recipe.js 1.2 KB

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