user.model.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // ./api/users/user.model.js
  2. import mongoose from "mongoose";
  3. import localDatabase from "../../common/localDatabase.js";
  4. const schema = new localDatabase.Schema(
  5. {
  6. name: String,
  7. surname: String,
  8. email: String,
  9. language: String,
  10. password: String,
  11. role: String,
  12. active: {
  13. type: Boolean,
  14. default: false,
  15. },
  16. confirmationToken: String,
  17. passwordResetToken: String,
  18. passwordResetExpires: Date,
  19. sso: String,
  20. accountOwner: {
  21. type: Boolean,
  22. default: false,
  23. },
  24. accountId: {
  25. type: mongoose.Schema.Types.ObjectId,
  26. ref: "Account",
  27. },
  28. account: {
  29. type: mongoose.Schema.Types.ObjectId,
  30. ref: "Account",
  31. },
  32. teams: [
  33. {
  34. _id: { type: mongoose.Schema.Types.ObjectId, ref: "Team" },
  35. code: { type: String },
  36. name: { type: String },
  37. },
  38. ],
  39. },
  40. { timestamps: true, toJSON: { virtuals: true } }
  41. );
  42. schema.virtual("id").get(function () {
  43. return this._id;
  44. });
  45. const User = localDatabase.model("User", schema, "user");
  46. export default User;