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);
/**
* @param {typedefs.Req} req
* @param {typedefs.Res} res
* Business logic to go in these controller functions.
* 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) => {
try {
} catch (error) {
logger.error("Error", { error });
logger.error("__controller_func", { error });
return res.status(500).send({ message: "Server Error. Try again." });
}
}

View File

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

View File

@ -3,6 +3,12 @@ const { body, header, param, query } = require("express-validator");
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.Res} res
* @param {typedefs.Next} next

View File

@ -14,8 +14,10 @@ app.use(cors());
app.use(helmet());
app.disable("x-powered-by");
// Put routes here
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;

View File

@ -1,7 +1,7 @@
{
"name": "induction-api-2023",
"version": "1.0.0",
"description": "",
"name": "backend-template",
"version": "1.1.0",
"description": "Template for back-end server using Express, Node, and Sequelize.",
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_ENV=development nodemon --exitcrash index.js",
@ -11,14 +11,14 @@
},
"repository": {
"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": "",
"license": "ISC",
"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": {
"cors": "^2.8.5",
"cross-fetch": "^3.1.5",

View File

@ -1,3 +1,5 @@
// Type definitions to enable better auto-complete features.
/**
* @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 = [];
for (key in obj) {
if (typeof obj[key] !== "object") {
@ -8,7 +15,7 @@ function getNestedValuesString(obj) {
}
}
return values.join();
return delimiter ? values.join(delimiter) : values.join();
}
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 { createLogger, transports, config, format } = require("winston");