recipe.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. category: {
  25. type: String,
  26. default: ""
  27. },
  28. hidden: {
  29. type: Boolean,
  30. default: false
  31. },
  32. ingredients: [{
  33. ingredient: {
  34. type: mongoose.Schema.Types.ObjectId,
  35. ref: "Ingredient",
  36. required: [true, "INGREDIENT IS REQUIRED"]
  37. },
  38. quantity: {
  39. type: Number,
  40. min: [0, "QUANTITY OF INGREDIENTS CANNOT BE A NEGATIVE NUMBER"],
  41. required: [true, "MUST PROVED A QUANTITY FOR ALL INGREDIENTS"]
  42. }
  43. }]
  44. });
  45. module.exports = mongoose.model("Recipe", RecipeSchema);