workspace.model (1).js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // api/workspaces/workspace.model.js
  2. import mongoose from "mongoose";
  3. import localDatabase from "../../common/localDatabase.js";
  4. const schema = new localDatabase.Schema(
  5. {
  6. name: {
  7. type: String,
  8. required: true,
  9. trim: true
  10. },
  11. description: {
  12. type: String,
  13. default: ""
  14. },
  15. filePath: {
  16. type: String,
  17. default: null
  18. },
  19. fileType: {
  20. type: String,
  21. default: null
  22. },
  23. fileSize: {
  24. type: Number,
  25. default: 0
  26. },
  27. metadata: {
  28. type: Object,
  29. default: {}
  30. },
  31. isPublic: {
  32. type: Boolean,
  33. default: false
  34. },
  35. accountId: {
  36. type: mongoose.Schema.Types.ObjectId,
  37. ref: "Account",
  38. required: true
  39. },
  40. userId: {
  41. type: mongoose.Schema.Types.ObjectId,
  42. ref: "User",
  43. required: true
  44. },
  45. teams: [{
  46. _id: { type: mongoose.Schema.Types.ObjectId, ref: "Team" },
  47. code: { type: String },
  48. name: { type: String }
  49. }],
  50. lastAccessed: {
  51. type: Date,
  52. default: null
  53. }
  54. },
  55. { timestamps: true, toJSON: { virtuals: true } }
  56. );
  57. schema.virtual("id").get(function () {
  58. return this._id;
  59. });
  60. const Workspace = localDatabase.model("Workspace", schema, "workspace");
  61. export default Workspace;