merchant.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }],
  48. recipes: [{
  49. type: mongoose.Schema.Types.ObjectId,
  50. ref: "Recipe"
  51. }],
  52. removed: {
  53. type: Boolean,
  54. default: false
  55. }
  56. });
  57. module.exports = mongoose.model("Merchant", MerchantSchema);