merchant.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const isSanitary = require("../controllers/helper.js").isSanitary;
  2. const mongoose = require("mongoose");
  3. let emailValid = (value)=>{
  4. /^\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. },
  23. password: {
  24. type: String,
  25. required: [true, "MUST PROVIDE A PASSWORD"],
  26. },
  27. pos: {
  28. type: String,
  29. required: true
  30. },
  31. posId: String,
  32. posAccessToken: String,
  33. lastUpdatedTime: {
  34. type: String,
  35. default: Date.now()
  36. },
  37. createdAt: {
  38. type: Date,
  39. default: Date.now
  40. },
  41. status: [],
  42. squareLocation: String,
  43. inventory: [{
  44. ingredient: {
  45. type: mongoose.Schema.Types.ObjectId,
  46. ref: "Ingredient",
  47. required: [true, "MUST PROVIDE THE INGREDIENT"]
  48. },
  49. quantity: {
  50. type: Number,
  51. required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
  52. },
  53. defaultUnit: {
  54. type: String,
  55. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  56. }
  57. }],
  58. recipes: [{
  59. type: mongoose.Schema.Types.ObjectId,
  60. ref: "Recipe"
  61. }],
  62. session: {
  63. sessionId: String,
  64. expiration: Date
  65. },
  66. verifyId: String
  67. });
  68. module.exports = mongoose.model("Merchant", MerchantSchema);