Last active
January 11, 2024 19:04
-
-
Save onlurking/16e26be11f4e23502d7ae7c82e73bffd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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