merchant.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. square: {
  30. id: String,
  31. accessToken: String,
  32. expires: Date,
  33. refreshToken: String,
  34. location: String
  35. },
  36. posId: String,
  37. posAccessToken: String,
  38. lastUpdatedTime: {
  39. type: String,
  40. default: Date.now()
  41. },
  42. createdAt: {
  43. type: Date,
  44. default: Date.now
  45. },
  46. status: [],
  47. squareLocation: String,
  48. inventory: [{
  49. ingredient: {
  50. type: mongoose.Schema.Types.ObjectId,
  51. ref: "Ingredient",
  52. required: [true, "MUST PROVIDE THE INGREDIENT"]
  53. },
  54. quantity: {
  55. type: Number,
  56. required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
  57. },
  58. defaultUnit: {
  59. type: String,
  60. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  61. }
  62. }],
  63. recipes: [{
  64. type: mongoose.Schema.Types.ObjectId,
  65. ref: "Recipe"
  66. }],
  67. session: {
  68. sessionId: {
  69. type: String,
  70. index: true
  71. },
  72. expiration: Date
  73. }
  74. });
  75. module.exports = mongoose.model("Merchant", MerchantSchema);