Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions RestfullAPI/middleware/validateYear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function validateYear(req, res, next) {
const { year } = req.body;

if (!year || isNaN(year)) {
return res.status(400).json({ message: "Year must be a valid number" });
}

const currentYear = new Date().getFullYear();

if (year < 1500 || year > currentYear) {
return res.status(400).json({
message: `Year must be between 1500 and ${currentYear}`
});
}

next();
}

module.exports = validateYear;
Loading