merchant.js 1.2 KB

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