merchant.js 1.5 KB

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