Minor fixes, comments

This commit is contained in:
Kaushik 2022-11-07 17:36:33 +05:30
parent 7e59afe469
commit 1973247ae4
9 changed files with 46 additions and 15 deletions

View File

@ -1 +1,5 @@
# Induction app back-end # Back-end server template
- Run npm i to install all dependencies first
- Env config: .env, .env.development, .env.staging, .env.production
- npm run staging_prep and npm run staging to deploy on Render after configuring a new web service on Render dashboard

View File

@ -2,14 +2,17 @@ const typedefs = require("../typedefs");
const logger = require("../utils/logger")(module); const logger = require("../utils/logger")(module);
/** /**
* @param {typedefs.Req} req * Business logic to go in these controller functions.
* @param {typedefs.Res} res * Everything should be contained inside try-catch blocks
*
* @param {typedefs.Req} req Express request object
* @param {typedefs.Res} res Express response object
*/ */
const __controller_func = async (req, res) => { const __controller_func = async (req, res) => {
try { try {
} catch (error) { } catch (error) {
logger.error("Error", { error }); logger.error("__controller_func", { error });
return res.status(500).send({ message: "Server Error. Try again." }); return res.status(500).send({ message: "Server Error. Try again." });
} }
} }

View File

@ -1,13 +1,18 @@
const router = require("express").Router(); const router = require("express").Router();
const { validate } = require("../validators"); const { validate } = require("../validators");
const { __controller_func } = require("./controller");
router.get( router.get(
// URL,
// middleware,
// validators,
// validate,
// __controller_func
); );
router.post( router.post(
//similar
); );
module.exports = router; module.exports = router;

View File

@ -3,6 +3,12 @@ const { body, header, param, query } = require("express-validator");
const typedefs = require("../typedefs"); const typedefs = require("../typedefs");
/** /**
* Validator middleware function
*
* Use the necessary part of the request, such as params for URL parameters, or query for query parameters.
*
* Refer https://github.com/validatorjs/validator.js for a full list of the validators and sanitizers available.
*
* @param {typedefs.Req} req * @param {typedefs.Req} req
* @param {typedefs.Res} res * @param {typedefs.Res} res
* @param {typedefs.Next} next * @param {typedefs.Next} next

View File

@ -14,8 +14,10 @@ app.use(cors());
app.use(helmet()); app.use(helmet());
app.disable("x-powered-by"); app.disable("x-powered-by");
// Put routes here
app.use((_req, res) => { app.use((_req, res) => {
return res.status(200).send("Induction app back-end."); return res.status(200).send("Back-end for");
}); });
const port = process.env.PORT || 5000; const port = process.env.PORT || 5000;

View File

@ -1,7 +1,7 @@
{ {
"name": "induction-api-2023", "name": "backend-template",
"version": "1.0.0", "version": "1.1.0",
"description": "", "description": "Template for back-end server using Express, Node, and Sequelize.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "cross-env NODE_ENV=development nodemon --exitcrash index.js", "dev": "cross-env NODE_ENV=development nodemon --exitcrash index.js",
@ -11,14 +11,14 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitlab.com/ctf-tech-2023/induction-api-2023.git" "url": "git+https://gitlab.com/ctf-tech-2023/backend-template.git"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"bugs": { "bugs": {
"url": "https://gitlab.com/ctf-tech-2023/induction-api-2023/issues" "url": "https://gitlab.com/ctf-tech-2023/backend-template/issues"
}, },
"homepage": "https://gitlab.com/ctf-tech-2023/induction-api-2023#readme", "homepage": "https://gitlab.com/ctf-tech-2023/backend-template#readme",
"dependencies": { "dependencies": {
"cors": "^2.8.5", "cors": "^2.8.5",
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",

View File

@ -1,3 +1,5 @@
// Type definitions to enable better auto-complete features.
/** /**
* @typedef {import("module")} Module * @typedef {import("module")} Module
* *

View File

@ -1,4 +1,11 @@
function getNestedValuesString(obj) { /**
* String joins all the values of a JSON object, including nested keys
*
* @param {any} obj JSON object
* @param {string} delimiter Delimiter of final string
* @returns
*/
const getNestedValuesString = (obj, delimiter) => {
let values = []; let values = [];
for (key in obj) { for (key in obj) {
if (typeof obj[key] !== "object") { if (typeof obj[key] !== "object") {
@ -8,7 +15,7 @@ function getNestedValuesString(obj) {
} }
} }
return values.join(); return delimiter ? values.join(delimiter) : values.join();
} }
module.exports = { module.exports = {

View File

@ -1,3 +1,5 @@
// Whole thing is winston logger stuff, if you want to learn read the docs
const path = require("path"); const path = require("path");
const { createLogger, transports, config, format } = require("winston"); const { createLogger, transports, config, format } = require("winston");