owner.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const mongoose = require("mongoose");
  2. let emailValid = require("../validator.js").emailValid;
  3. let isSanitary = require("../validator.js").isSanitary;
  4. const OwnerSchema = new mongoose.Schema({
  5. email: {
  6. type: String,
  7. required: [true, "EMAIL IS REQUIRED"],
  8. validate: {
  9. validator: emailValid,
  10. message: "INVALID EMAIL ADDRESS"
  11. },
  12. index: true
  13. },
  14. name: {
  15. type: String,
  16. required: [true, "MUST PROVIDE AN OWNER NAME"],
  17. validate: {
  18. validator: isSanitary,
  19. message: "OWNER NAME CONTAINS ILLEGAL CHARACTERS"
  20. }
  21. },
  22. password: {
  23. type: String,
  24. required: true
  25. },
  26. square: {
  27. id: String,
  28. accessToken: String,
  29. expires: Date,
  30. refreshToken: String,
  31. },
  32. createdAt: {
  33. type: Date,
  34. default: new Date()
  35. },
  36. status: [],
  37. session: {
  38. sessionId: {
  39. type: String,
  40. index: true
  41. },
  42. expiration: Date
  43. },
  44. merchants: [{
  45. type: mongoose.Schema.Types.ObjectId,
  46. ref: "Merchant"
  47. }]
  48. });
  49. module.exports = mongoose.model("Owner", OwnerSchema);