Skip to content

Instantly share code, notes, and snippets.

@onlurking
Last active January 11, 2024 19:04
Show Gist options
  • Save onlurking/16e26be11f4e23502d7ae7c82e73bffd to your computer and use it in GitHub Desktop.
Save onlurking/16e26be11f4e23502d7ae7c82e73bffd to your computer and use it in GitHub Desktop.
const isValidSongContent = (req, res, next) => {
const rules = [
{
name: "songTitle",
validation: (value) => value.trim().length > 0,
error: "Title content must be at least one character long.",
},
{
name: "songArtist",
validation: (value) => value.trim().length > 0,
error: "Artist content must be at least one character long.",
},
{
name: "trackId",
validation: (value) => value.trim().length > 0,
error: "trackId content must be at least one character long.",
},
];
rules.forEach(({ name, validation, error }) => {
if (!validation(req.body[name])) {
res.status(400).json({ error });
return;
}
});
next();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment