recipe.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const isSanitary = require("../validator.js").isSanitary;
  2. const mongoose = require("mongoose");
  3. const RecipeSchema = new mongoose.Schema({
  4. posId: String,
  5. merchant: {
  6. type: mongoose.Schema.Types.ObjectId,
  7. ref: "Merchant",
  8. required: [true, "MERCHANT IS REQUIRED"]
  9. },
  10. name: {
  11. type: String,
  12. minlength: [2, "RECIPE NAME MUST CONTAIN AT LEAST 2 CHARACTERS"],
  13. validate: {
  14. validator: isSanitary,
  15. message: "RECIPE NAME CONTAINS ILLEGAL CHARACTERS"
  16. },
  17. required: true
  18. },
  19. price: {
  20. type: Number,
  21. min: [0, "PRICE OF RECIPE CANNOT BE A NEGATIVE NUMBER"],
  22. required: [true, "RECIPE PRICE IS REQUIRED"]
  23. },
  24. ingredients: [{
  25. ingredient: {
  26. type: mongoose.Schema.Types.ObjectId,
  27. ref: "Ingredient",
  28. required: [true, "INGREDIENT IS REQUIRED"]
  29. },
  30. quantity: {
  31. type: Number,
  32. min: [0, "QUANTITY OF INGREDIENTS CANNOT BE A NEGATIVE NUMBER"],
  33. required: [true, "MUST PROVED A QUANTITY FOR ALL INGREDIENTS"]
  34. }
  35. }]
  36. });
  37. module.exports = mongoose.model("Recipe", RecipeSchema);