Before inserting a document into my DB collection, I need to ensure that all the data in req.query
matches the structure of my IGroupDocument
in the controller.
What is the recommended approach for achieving this?
IGroupDocument:
import { Document, Model } from "mongoose";
export interface IGroup {
firstName: string;
lastName: string;
age?: number;
email: string,
dateOfEntry?: Date;
}
export interface IGroupDocument extends IGroup, Document {}
Controller:
function create(req: Request, res: Response) {
// Validate req.query: check for existence of firstName, lastName, and email as strings, then create a new document using req.query and call it newGroup.
GroupModel.create(newGroup)
res.send(`${req.query.name} created`)
}