merchant.js 1.5 KB

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