merchant.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const isSanitary = require("../controllers/helper.js").isSanitary;
  2. const mongoose = require("mongoose");
  3. let emailValid = (value)=>{
  4. return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value);
  5. }
  6. const MerchantSchema = new mongoose.Schema({
  7. name: {
  8. type: String,
  9. required: [true, "MERCHANT NAME IS REQUIRED"],
  10. validate: {
  11. validator: isSanitary,
  12. message: "NAME CONTAINS ILLEGAL CHARACTERS"
  13. }
  14. },
  15. email: {
  16. type: String,
  17. required: [true, "EMAIL IS REQUIRED"],
  18. validate: {
  19. validator: emailValid,
  20. message: "INVALID EMAIL ADDRESS"
  21. },
  22. index: true
  23. },
  24. password: String,
  25. pos: {
  26. type: String,
  27. required: true
  28. },
  29. posId: String,
  30. posAccessToken: String,
  31. lastUpdatedTime: {
  32. type: String,
  33. default: Date.now()
  34. },
  35. createdAt: {
  36. type: Date,
  37. default: Date.now
  38. },
  39. status: [],
  40. squareLocation: String,
  41. inventory: [{
  42. ingredient: {
  43. type: mongoose.Schema.Types.ObjectId,
  44. ref: "Ingredient",
  45. required: [true, "MUST PROVIDE THE INGREDIENT"]
  46. },
  47. quantity: {
  48. type: Number,
  49. required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
  50. },
  51. defaultUnit: {
  52. type: String,
  53. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  54. }
  55. }],
  56. recipes: [{
  57. type: mongoose.Schema.Types.ObjectId,
  58. ref: "Recipe"
  59. }],
  60. session: {
  61. sessionId: {
  62. type: String,
  63. index: true
  64. },
  65. expiration: Date
  66. }
  67. });
  68. module.exports = mongoose.model("Merchant", MerchantSchema);