merchant.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const mongoose = require("mongoose");
  2. const MerchantSchema = new mongoose.Schema({
  3. name: {
  4. type: String,
  5. required: true
  6. },
  7. posId: {
  8. type: String,
  9. required: true
  10. },
  11. lastUpdatedTime: {
  12. type: String,
  13. default: Date.now()
  14. },
  15. inventory: [{
  16. ingredient: {
  17. type: mongoose.Schema.Types.ObjectId,
  18. ref: "Ingredient",
  19. required: true
  20. },
  21. quantity: {
  22. type: Number,
  23. required: true,
  24. min: [0, "Quantity cannot be less than 0"]
  25. }
  26. }],
  27. recipes: [{
  28. posId: {
  29. type: String,
  30. required: true
  31. },
  32. name: {
  33. type: String,
  34. required: true,
  35. },
  36. ingredients: [{
  37. ingredient: {
  38. type: mongoose.Schema.Types.ObjectId,
  39. ref: "Ingredient",
  40. required: [true, "Must provide ingredient"]
  41. },
  42. quantity: {
  43. type: Number,
  44. min: [0, "Cannot have a negative quantity"],
  45. required: [true, "Must provide a quantity"]
  46. }
  47. }]
  48. }]
  49. });
  50. module.exports = mongoose.model("Merchant", MerchantSchema);