modarb-be / src /common /models /meal.model.ts
Hozifa Elgharbawy
Add meal-related models, validations and serializers
7676a27
raw
history blame
914 Bytes
import mongoose from "mongoose";
const { Schema } = mongoose;
import { MealType } from "@common/enums/meal-type.enum";
export interface IMeal {
name: string;
created_at: Date;
ingredients: [string];
calories: number;
carbs: number;
proteins: number;
fats: number;
type: MealType;
}
const mealSchema = new Schema({
name: { type: String, required: true, unique: true, dropDups: true },
created_at: { type: Date, default: Date.now() },
type: {
type: String,
enum: MealType,
required: true,
},
ingredients: [{ type: mongoose.Types.ObjectId, ref: "ingredients" }],
calories: { type: Number, required: true },
carbs: { type: Number, required: true },
proteins: { type: Number, required: true },
fats: { type: Number, required: true },
});
export type MealDocument = IMeal & mongoose.Document;
export const Meal = mongoose.model<MealDocument>(
"meals",
mealSchema
);