recipe.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. validate: {
  28. validator: isSanitary,
  29. message: "RECIPE CATEGORY CONTAINS ILLEGAL CHARACTERS"
  30. }
  31. },
  32. hidden: {
  33. type: Boolean,
  34. default: false
  35. },
  36. ingredients: [{
  37. ingredient: {
  38. type: mongoose.Schema.Types.ObjectId,
  39. ref: "Ingredient",
  40. required: [true, "INGREDIENT IS REQUIRED"]
  41. },
  42. quantity: {
  43. type: Number,
  44. min: [0, "QUANTITY OF INGREDIENTS CANNOT BE A NEGATIVE NUMBER"],
  45. required: [true, "MUST PROVED A QUANTITY FOR ALL INGREDIENTS"]
  46. },
  47. unit: String
  48. }]
  49. });
  50. module.exports = mongoose.model("Recipe", RecipeSchema);