merchant.js 1.8 KB

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