backedn converted to ts
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
const mongoose = require('mongoose');
|
||||
import mongoose from "mongoose";
|
||||
// middleware to check for a valid object id
|
||||
const checkObjectId = (idToCheck) => (req, res, next) => {
|
||||
import type { Request, Response, NextFunction } from "express";
|
||||
const checkObjectId = (idToCheck: string) => (req: Request, res: Response, next: NextFunction) => {
|
||||
if (!mongoose.Types.ObjectId.isValid(req.params[idToCheck]))
|
||||
return res.status(400).json({ msg: 'Invalid ID' });
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = checkObjectId;
|
||||
export default checkObjectId
|
||||
|
||||
Reference in New Issue
Block a user