merchant.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const isSanitary = require("../validator.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. locationId: String,
  22. createdAt: {
  23. type: Date,
  24. default: new Date()
  25. },
  26. address: Object,
  27. inventory: [{
  28. ingredient: {
  29. type: mongoose.Schema.Types.ObjectId,
  30. ref: "Ingredient",
  31. required: [true, "MUST PROVIDE THE INGREDIENT"]
  32. },
  33. quantity: {
  34. type: Number,
  35. required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
  36. },
  37. defaultUnit: {
  38. type: String,
  39. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  40. }
  41. }],
  42. recipes: [{
  43. type: mongoose.Schema.Types.ObjectId,
  44. ref: "Recipe"
  45. }],
  46. removed: {
  47. type: Boolean,
  48. default: false
  49. }
  50. });
  51. module.exports = mongoose.model("Merchant", MerchantSchema);