merchant.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const isSanitary = require("../controllers/helper.js").isSanitary;
  2. const mongoose = require("mongoose");
  3. const MerchantSchema = new mongoose.Schema({
  4. name: {
  5. type: String,
  6. required: [true, "MERCHANT NAME IS REQUIRED"],
  7. validate: {
  8. validator: isSanitary,
  9. message: "NAME CONTAINS ILLEGAL CHARACTERS"
  10. }
  11. },
  12. createdAt: {
  13. type: Date,
  14. default: new Date()
  15. },
  16. inventory: [{
  17. ingredient: {
  18. type: mongoose.Schema.Types.ObjectId,
  19. ref: "Ingredient",
  20. required: [true, "MUST PROVIDE THE INGREDIENT"]
  21. },
  22. quantity: {
  23. type: Number,
  24. required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
  25. },
  26. defaultUnit: {
  27. type: String,
  28. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  29. }
  30. }],
  31. recipes: [{
  32. type: mongoose.Schema.Types.ObjectId,
  33. ref: "Recipe"
  34. }],
  35. });
  36. module.exports = mongoose.model("Merchant", MerchantSchema);