@cool-digital-solutions/interferir-models 1.1.32 → 1.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,16 +13,7 @@ const teamSchema = new mongoose_1.Schema({
13
13
  logo: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Image', default: null },
14
14
  plan: { type: String, enum: Object.values(team_type_1.Plan), required: true },
15
15
  maxSize: { type: Number },
16
- users: [
17
- {
18
- user: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User' },
19
- role: { type: String, enum: Object.values(team_type_1.UserTeamRole) },
20
- createdBy: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', default: null },
21
- updatedBy: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', default: null },
22
- updatedDate: Number,
23
- createdDate: Number,
24
- },
25
- ],
16
+ users: [{ user: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User' }, role: { type: String, enum: Object.values(team_type_1.UserTeamRole) }, addedDate: Number }],
26
17
  createdBy: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', default: null },
27
18
  updatedBy: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', default: null },
28
19
  updatedDate: Number,
@@ -36,13 +27,9 @@ teamSchema.pre('save', function (next) {
36
27
  this.createdBy = user._id;
37
28
  if (!notUpdatedBy)
38
29
  this.updatedBy = user._id;
39
- for (const user of this.users) {
40
- user.createdBy = user._id;
41
- if (!notUpdatedBy)
42
- user.updatedBy = user._id;
43
- user.createdDate = this.createdDate;
44
- user.updatedDate = this.updatedDate;
45
- }
30
+ }
31
+ for (const user of this.users) {
32
+ user.addedDate = Date.now();
46
33
  }
47
34
  next();
48
35
  });
@@ -51,13 +38,11 @@ teamSchema.pre('findOneAndUpdate', function (next) {
51
38
  const notUpdatedBy = express_http_context_1.default.get('notUpdatedBy');
52
39
  if (user && !notUpdatedBy)
53
40
  this._update.updatedBy = user._id;
54
- if (user) {
41
+ if (this.users.length)
55
42
  for (const user of this.users) {
56
- if (!notUpdatedBy)
57
- user.updatedBy = user._id;
58
- user.updatedDate = this.updatedDate;
43
+ if (!user.addedDate)
44
+ user.addedDate = Date.now();
59
45
  }
60
- }
61
46
  next();
62
47
  });
63
48
  exports.default = teamSchema;
@@ -37,6 +37,7 @@ export declare enum UserTeamRole {
37
37
  interface User extends BaseSchema {
38
38
  user: Types.ObjectId | IUser;
39
39
  role: UserTeamRole;
40
+ addedDate: number;
40
41
  }
41
42
  export interface ITeam extends BaseSchema {
42
43
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cool-digital-solutions/interferir-models",
3
- "version": "1.1.32",
3
+ "version": "1.1.34",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist/**/*"