merchant.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. inventory: [{
  27. ingredient: {
  28. type: mongoose.Schema.Types.ObjectId,
  29. ref: "Ingredient",
  30. required: [true, "MUST PROVIDE THE INGREDIENT"]
  31. },
  32. quantity: {
  33. type: Number,
  34. required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
  35. },
  36. defaultUnit: {
  37. type: String,
  38. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  39. }
  40. }],
  41. recipes: [{
  42. type: mongoose.Schema.Types.ObjectId,
  43. ref: "Recipe"
  44. }],
  45. removed: {
  46. type: Boolean,
  47. default: false
  48. }
  49. });
  50. module.exports = mongoose.model("Merchant", MerchantSchema);