mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 06:04:05 +00:00
editorconfig
This commit is contained in:
@@ -7,40 +7,40 @@ const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* Refer: https://stackoverflow.com/questions/58848625/access-messages-in-express-validator
|
||||
*
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
*
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
*/
|
||||
const validate = (req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (errors.isEmpty()) {
|
||||
return next();
|
||||
}
|
||||
const errors = validationResult(req);
|
||||
if (errors.isEmpty()) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const extractedErrors = [];
|
||||
errors.array().forEach(err => {
|
||||
if (err.type === "alternative") {
|
||||
err.nestedErrors.forEach(nestedErr => {
|
||||
extractedErrors.push({
|
||||
[nestedErr.path]: nestedErr.msg
|
||||
});
|
||||
});
|
||||
} else if (err.type === "field") {
|
||||
extractedErrors.push({
|
||||
[err.path]: err.msg
|
||||
});
|
||||
}
|
||||
});
|
||||
const extractedErrors = [];
|
||||
errors.array().forEach(err => {
|
||||
if (err.type === "alternative") {
|
||||
err.nestedErrors.forEach(nestedErr => {
|
||||
extractedErrors.push({
|
||||
[nestedErr.path]: nestedErr.msg
|
||||
});
|
||||
});
|
||||
} else if (err.type === "field") {
|
||||
extractedErrors.push({
|
||||
[err.path]: err.msg
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
res.status(400).json({
|
||||
message: getNestedValuesString(extractedErrors),
|
||||
errors: extractedErrors
|
||||
});
|
||||
logger.warn("invalid request", { extractedErrors });
|
||||
return;
|
||||
res.status(400).json({
|
||||
message: getNestedValuesString(extractedErrors),
|
||||
errors: extractedErrors
|
||||
});
|
||||
logger.warn("invalid request", { extractedErrors });
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validate
|
||||
validate
|
||||
};
|
||||
|
||||
@@ -3,29 +3,29 @@ const { body, header, param, query } = require("express-validator");
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
*/
|
||||
const createLinkValidator = async (req, res, next) => {
|
||||
await body("from")
|
||||
.notEmpty()
|
||||
.withMessage("from not defined in body")
|
||||
.isURL()
|
||||
.withMessage("from must be a valid link")
|
||||
.run(req);
|
||||
await body("to")
|
||||
.notEmpty()
|
||||
.withMessage("to not defined in body")
|
||||
.isURL()
|
||||
.withMessage("to must be a valid link")
|
||||
.run(req);
|
||||
next();
|
||||
await body("from")
|
||||
.notEmpty()
|
||||
.withMessage("from not defined in body")
|
||||
.isURL()
|
||||
.withMessage("from must be a valid link")
|
||||
.run(req);
|
||||
await body("to")
|
||||
.notEmpty()
|
||||
.withMessage("to not defined in body")
|
||||
.isURL()
|
||||
.withMessage("to must be a valid link")
|
||||
.run(req);
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createLinkValidator,
|
||||
removeLinkValidator: createLinkValidator,
|
||||
populateSingleLinkValidator: createLinkValidator,
|
||||
pruneSingleLinkValidator: createLinkValidator,
|
||||
createLinkValidator,
|
||||
removeLinkValidator: createLinkValidator,
|
||||
populateSingleLinkValidator: createLinkValidator,
|
||||
pruneSingleLinkValidator: createLinkValidator,
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@ const { body, header, param, query } = require("express-validator");
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
* @param {typedefs.Req} req
|
||||
* @param {typedefs.Res} res
|
||||
* @param {typedefs.Next} next
|
||||
*/
|
||||
const getPlaylistDetailsValidator = async (req, res, next) => {
|
||||
await query("playlist_link")
|
||||
.notEmpty()
|
||||
.withMessage("playlist_link not defined in query")
|
||||
.isURL()
|
||||
.withMessage("playlist_link must be a valid link")
|
||||
.run(req);
|
||||
next();
|
||||
await query("playlist_link")
|
||||
.notEmpty()
|
||||
.withMessage("playlist_link not defined in query")
|
||||
.isURL()
|
||||
.withMessage("playlist_link must be a valid link")
|
||||
.run(req);
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPlaylistDetailsValidator
|
||||
getPlaylistDetailsValidator
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user