merchant.js 1.4 KB

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