merchant.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. square: {
  26. id: String,
  27. accessToken: String,
  28. expires: Date,
  29. refreshToken: String,
  30. location: String
  31. },
  32. createdAt: {
  33. type: Date,
  34. default: new Date()
  35. },
  36. status: [],
  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. defaultUnit: {
  48. type: String,
  49. required: [true, "INGREDIENT UNIT IS REQUIRED"]
  50. }
  51. }],
  52. recipes: [{
  53. type: mongoose.Schema.Types.ObjectId,
  54. ref: "Recipe"
  55. }],
  56. session: {
  57. sessionId: {
  58. type: String,
  59. index: true
  60. },
  61. expiration: Date
  62. }
  63. });
  64. module.exports = mongoose.model("Merchant", MerchantSchema);