codebase-models 2.0.5 → 2.0.7

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.
Files changed (72) hide show
  1. package/dist/index.d.ts +3 -1
  2. package/dist/index.js +6 -1
  3. package/dist/src/constant.d.ts +7 -0
  4. package/dist/src/constant.js +17 -0
  5. package/dist/src/models/Announcement.d.ts +1 -0
  6. package/dist/src/models/Announcement.js +31 -0
  7. package/dist/src/models/Audience.d.ts +1 -0
  8. package/dist/src/models/Audience.js +31 -0
  9. package/dist/src/models/BqPreCompiledData.d.ts +1 -0
  10. package/dist/src/models/BqPreCompiledData.js +31 -0
  11. package/dist/src/models/Client.d.ts +1 -0
  12. package/dist/src/models/Client.js +31 -0
  13. package/dist/src/models/ClientAdditionalRevenue.d.ts +3 -1
  14. package/dist/src/models/ClientAdditionalRevenue.js +48 -0
  15. package/dist/src/models/ClientLearning.d.ts +1 -0
  16. package/dist/src/models/ClientLearning.js +31 -0
  17. package/dist/src/models/ClientLinks.d.ts +1 -0
  18. package/dist/src/models/ClientLinks.js +31 -0
  19. package/dist/src/models/ClientNextSteps.d.ts +1 -0
  20. package/dist/src/models/ClientNextSteps.js +30 -0
  21. package/dist/src/models/ClientNote.d.ts +1 -0
  22. package/dist/src/models/ClientNote.js +31 -0
  23. package/dist/src/models/ClientScript.d.ts +12 -11
  24. package/dist/src/models/ClientScript.js +54 -9
  25. package/dist/src/models/ClientStrategy.d.ts +1 -0
  26. package/dist/src/models/ClientStrategy.js +31 -0
  27. package/dist/src/models/CustomQuery.d.ts +1 -0
  28. package/dist/src/models/CustomQuery.js +30 -1
  29. package/dist/src/models/Environment.d.ts +3 -0
  30. package/dist/src/models/Environment.js +38 -0
  31. package/dist/src/models/Goal.d.ts +1 -0
  32. package/dist/src/models/Goal.js +31 -2
  33. package/dist/src/models/Page.d.ts +2 -0
  34. package/dist/src/models/Page.js +48 -0
  35. package/dist/src/models/PageElement.js +0 -1
  36. package/dist/src/models/PageTestType.js +0 -2
  37. package/dist/src/models/Report.d.ts +1 -0
  38. package/dist/src/models/Report.js +30 -0
  39. package/dist/src/models/Role.js +0 -3
  40. package/dist/src/models/Snippet.js +0 -4
  41. package/dist/src/models/StageInCustomerJourney.d.ts +1 -0
  42. package/dist/src/models/StageInCustomerJourney.js +31 -4
  43. package/dist/src/models/Test.d.ts +3 -0
  44. package/dist/src/models/Test.js +47 -2
  45. package/dist/src/models/TestTimeline.d.ts +39 -0
  46. package/dist/src/models/TestTimeline.js +79 -0
  47. package/index.ts +4 -1
  48. package/package.json +3 -2
  49. package/src/constant.ts +17 -0
  50. package/src/models/Announcement.ts +22 -0
  51. package/src/models/Audience.ts +23 -0
  52. package/src/models/BqPreCompiledData.ts +22 -0
  53. package/src/models/Client.ts +22 -0
  54. package/src/models/ClientAdditionalRevenue.ts +42 -1
  55. package/src/models/ClientLearning.ts +22 -0
  56. package/src/models/ClientLinks.ts +23 -2
  57. package/src/models/ClientNextSteps.ts +20 -0
  58. package/src/models/ClientNote.ts +22 -1
  59. package/src/models/ClientScript.ts +56 -21
  60. package/src/models/ClientStrategy.ts +24 -0
  61. package/src/models/CustomQuery.ts +22 -2
  62. package/src/models/Environment.ts +33 -1
  63. package/src/models/Goal.ts +22 -3
  64. package/src/models/Page.ts +43 -0
  65. package/src/models/PageElement.ts +0 -1
  66. package/src/models/PageTestType.ts +0 -2
  67. package/src/models/Report.ts +22 -0
  68. package/src/models/Role.ts +1 -3
  69. package/src/models/Snippet.ts +1 -4
  70. package/src/models/StageInCustomerJourney.ts +22 -4
  71. package/src/models/Test.ts +42 -4
  72. package/src/models/TestTimeline.ts +61 -0
@@ -1,6 +1,7 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
-
2
+ import { generateRandomIID } from "../constant";
3
3
  export interface IClientLinks extends Document {
4
+ iid: string;
4
5
  organizationId?: mongoose.Schema.Types.ObjectId;
5
6
  title: string;
6
7
  description?: string;
@@ -13,6 +14,10 @@ export interface IClientLinks extends Document {
13
14
 
14
15
  const ClientLinksSchema = new Schema<IClientLinks>(
15
16
  {
17
+ iid: {
18
+ type: String,
19
+ trim: true,
20
+ },
16
21
  organizationId: {
17
22
  type: mongoose.Schema.Types.ObjectId,
18
23
  ref: "organization",
@@ -51,8 +56,24 @@ const ClientLinksSchema = new Schema<IClientLinks>(
51
56
  {
52
57
  timestamps: true,
53
58
  }
54
- );
59
+ );
60
+
61
+ ClientLinksSchema.pre('save', async function(next) {
62
+ if (!this.iid) {
63
+ let unique = false;
64
+ while (!unique) {
65
+ const id = generateRandomIID();
66
+ const existing = await mongoose.models.clientlink.findOne({ iid: id });
67
+ if (!existing) {
68
+ this.iid = id;
69
+ unique = true;
70
+ }
71
+ }
72
+ }
73
+ next();
74
+ });
55
75
 
76
+ ClientLinksSchema.index({ iid: 1 }, { unique: true });
56
77
  // Compound indexes for common query patterns
57
78
  ClientLinksSchema.index({ client: 1 });
58
79
  ClientLinksSchema.index({ client: 1, private: 1 });
@@ -1,6 +1,8 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
2
3
 
3
4
  export interface IClientNextSteps extends Document {
5
+ iid: string;
4
6
  name: string;
5
7
  organizationId?: mongoose.Schema.Types.ObjectId;
6
8
  client?: mongoose.Schema.Types.ObjectId;
@@ -10,6 +12,10 @@ export interface IClientNextSteps extends Document {
10
12
 
11
13
  const ClientNextStepsSchema = new Schema<IClientNextSteps>(
12
14
  {
15
+ iid: {
16
+ type: String,
17
+ trim: true,
18
+ },
13
19
  name: {
14
20
  type: String,
15
21
  required: true,
@@ -36,6 +42,20 @@ const ClientNextStepsSchema = new Schema<IClientNextSteps>(
36
42
  }
37
43
  );
38
44
 
45
+ ClientNextStepsSchema.pre('save', async function(next) {
46
+ if (!this.iid) {
47
+ let unique = false;
48
+ while (!unique) {
49
+ const id = generateRandomIID();
50
+ const existing = await mongoose.models.clientnextstep.findOne({ iid: id });
51
+ if (!existing) {
52
+ this.iid = id;
53
+ unique = true;
54
+ }
55
+ }
56
+ }
57
+ next();
58
+ });
39
59
  ClientNextStepsSchema.index({
40
60
  client: 1,
41
61
  viewId: 1,
@@ -1,6 +1,8 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
2
3
 
3
4
  export interface IClientNote extends Document {
5
+ iid: string;
4
6
  organizationId?: mongoose.Schema.Types.ObjectId;
5
7
  client?: mongoose.Schema.Types.ObjectId;
6
8
  viewId?: string;
@@ -14,6 +16,10 @@ export interface IClientNote extends Document {
14
16
 
15
17
  const ClientNoteSchema = new Schema<IClientNote>(
16
18
  {
19
+ iid: {
20
+ type: String,
21
+ trim: true,
22
+ },
17
23
  organizationId: {
18
24
  type: mongoose.Schema.Types.ObjectId,
19
25
  ref: "organization",
@@ -51,9 +57,24 @@ const ClientNoteSchema = new Schema<IClientNote>(
51
57
  {
52
58
  timestamps: true,
53
59
  }
54
- );
60
+ );
55
61
 
62
+ ClientNoteSchema.pre('save', async function(next) {
63
+ if (!this.iid) {
64
+ let unique = false;
65
+ while (!unique) {
66
+ const id = generateRandomIID();
67
+ const existing = await mongoose.models.clientnote.findOne({ iid: id });
68
+ if (!existing) {
69
+ this.iid = id;
70
+ unique = true;
71
+ }
72
+ }
73
+ }
74
+ next();
75
+ });
56
76
  ClientNoteSchema.index({
77
+ iid: 1,
57
78
  client: 1,
58
79
  viewId: 1,
59
80
  });
@@ -1,26 +1,24 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
-
3
- export interface IClientScriptSchema extends Document {
4
- scriptUrl: string;
5
- viewId: string;
6
- }
2
+ import { generateRandomIID } from "../constant";
7
3
 
8
4
  export interface IClientScript extends Document {
5
+ iid: string;
9
6
  organizationId?: mongoose.Schema.Types.ObjectId;
10
7
  client?: mongoose.Schema.Types.ObjectId;
8
+ adhere_dnt: Boolean;
9
+ allow_in_iframes: Boolean;
11
10
  viewId?: string;
12
11
  clientScriptURL: string;
13
12
  jquery_include: string;
14
13
  debug: Boolean;
15
14
  restrict_debug: Boolean;
16
- adhere_dnt: Boolean;
17
15
  max_cookie_lifetime: Number;
18
16
  activation_mode: string;
19
17
  use_antiflicker: Boolean;
20
18
  snippet_revision: Number;
19
+ snippet_version: Number;
21
20
  rules: string;
22
21
  rules_tracking: string;
23
- tracker_url: string;
24
22
  asset_url: string;
25
23
  metadata_key_exp_1: mongoose.Schema.Types.Mixed;
26
24
  metadata_key_exp_2: mongoose.Schema.Types.Mixed;
@@ -28,19 +26,26 @@ export interface IClientScript extends Document {
28
26
  metadata_key_var_1: mongoose.Schema.Types.Mixed;
29
27
  metadata_key_var_2: mongoose.Schema.Types.Mixed;
30
28
  metadata_key_var_3: mongoose.Schema.Types.Mixed;
31
- cookie_domain: string;
32
- snippet_version: Number;
29
+ logDomain: string;
33
30
  storage: string;
34
31
  run_only_on_reinit: Boolean;
35
- allow_in_iframes: Boolean;
36
32
  visual_editor_version: Number;
37
- jscode: string;
38
- csscode: string;
33
+ js: string;
34
+ css: string;
35
+ helper_js: string;
39
36
  is_spa: Boolean;
37
+ isPreview: Boolean;
38
+ goalsEnabled: Boolean;
39
+ optedOut: Boolean;
40
+ liveEventListenersSet: Boolean;
40
41
  }
41
42
 
42
43
  const ClientScriptSchema = new Schema<IClientScript>(
43
44
  {
45
+ iid: {
46
+ type: String,
47
+ trim: true,
48
+ },
44
49
  organizationId: {
45
50
  type: mongoose.Schema.Types.ObjectId,
46
51
  ref: "organization",
@@ -52,7 +57,6 @@ const ClientScriptSchema = new Schema<IClientScript>(
52
57
  },
53
58
  viewId: {
54
59
  type: String,
55
- index: true,
56
60
  },
57
61
  clientScriptURL: {
58
62
  type: String,
@@ -100,10 +104,6 @@ const ClientScriptSchema = new Schema<IClientScript>(
100
104
  default: "return true;",
101
105
  trim: true,
102
106
  },
103
- tracker_url: {
104
- type: String,
105
- trim: true,
106
- },
107
107
  asset_url: {
108
108
  type: String,
109
109
  trim: true,
@@ -126,7 +126,7 @@ const ClientScriptSchema = new Schema<IClientScript>(
126
126
  metadata_key_var_3: {
127
127
  type: mongoose.Schema.Types.Mixed,
128
128
  },
129
- cookie_domain: {
129
+ logDomain: {
130
130
  type: String,
131
131
  trim: true,
132
132
  },
@@ -149,11 +149,15 @@ const ClientScriptSchema = new Schema<IClientScript>(
149
149
  visual_editor_version: {
150
150
  type: Number,
151
151
  },
152
- jscode: {
152
+ js: {
153
+ type: String,
154
+ trim: true,
155
+ },
156
+ css: {
153
157
  type: String,
154
158
  trim: true,
155
159
  },
156
- csscode: {
160
+ helper_js: {
157
161
  type: String,
158
162
  trim: true,
159
163
  },
@@ -161,17 +165,48 @@ const ClientScriptSchema = new Schema<IClientScript>(
161
165
  type: Boolean,
162
166
  default: false,
163
167
  },
168
+ isPreview: {
169
+ type: Boolean,
170
+ default: false,
171
+ },
172
+ goalsEnabled: {
173
+ type: Boolean,
174
+ default: false,
175
+ },
176
+ optedOut: {
177
+ type: Boolean,
178
+ default: false,
179
+ },
180
+ liveEventListenersSet: {
181
+ type: Boolean,
182
+ default: false,
183
+ },
164
184
  },
165
185
  {
166
186
  timestamps: true,
167
187
  }
168
188
  );
169
189
 
190
+ ClientScriptSchema.pre('save', async function(next) {
191
+ if (!this.iid) {
192
+ let unique = false;
193
+ while (!unique) {
194
+ const id = generateRandomIID();
195
+ const existing = await mongoose.models.clientscript.findOne({ iid: id });
196
+ if (!existing) {
197
+ this.iid = id;
198
+ unique = true;
199
+ }
200
+ }
201
+ }
202
+ next();
203
+ });
204
+
205
+ ClientScriptSchema.index({ iid: 1 }, { unique: true });
170
206
  // Compound indexes for common query patterns
171
207
  ClientScriptSchema.index({ client: 1 });
172
208
  // Sparse indexes for optional fields
173
209
  ClientScriptSchema.index({ organisationId: 1 }, { sparse: true });
174
- ClientScriptSchema.index({ tracker_url: 1 }, { sparse: true });
175
210
  ClientScriptSchema.index({ asset_url: 1 }, { sparse: true });
176
211
 
177
212
 
@@ -1,6 +1,8 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
2
3
 
3
4
  export interface IClientStrategy extends Document {
5
+ iid: string;
4
6
  year: mongoose.Schema.Types.Mixed;
5
7
  month: mongoose.Schema.Types.Mixed;
6
8
  startDate?: Date;
@@ -15,6 +17,10 @@ export interface IClientStrategy extends Document {
15
17
 
16
18
  const ClientStrategySchema = new Schema<IClientStrategy>(
17
19
  {
20
+ iid: {
21
+ type: String,
22
+ trim: true,
23
+ },
18
24
  year: {
19
25
  type: mongoose.Schema.Types.Mixed,
20
26
  required: true,
@@ -55,8 +61,26 @@ const ClientStrategySchema = new Schema<IClientStrategy>(
55
61
  {
56
62
  timestamps: true,
57
63
  }
64
+
58
65
  );
59
66
 
67
+ ClientStrategySchema.pre('save', async function(next) {
68
+ if (!this.iid) {
69
+ let unique = false;
70
+ while (!unique) {
71
+ const id = generateRandomIID();
72
+ const existing = await mongoose.models.clientstrategy.findOne({ iid: id });
73
+ if (!existing) {
74
+ this.iid = id;
75
+ unique = true;
76
+ }
77
+ }
78
+ }
79
+ next();
80
+ });
81
+
82
+ ClientStrategySchema.index({ iid: 1 }, { unique: true });
83
+
60
84
  ClientStrategySchema.index({
61
85
  year: 1,
62
86
  month: 1,
@@ -1,6 +1,8 @@
1
1
  import mongoose, { Schema, model, Document } from 'mongoose';
2
+ import { generateRandomIID } from '../constant';
2
3
 
3
4
  interface ICustomQuery extends Document {
5
+ iid: string;
4
6
  organizationId?: mongoose.Schema.Types.ObjectId;
5
7
  title: string;
6
8
  module: string;
@@ -11,6 +13,10 @@ interface ICustomQuery extends Document {
11
13
 
12
14
  const CustomQuerySchema = new Schema<ICustomQuery>(
13
15
  {
16
+ iid: {
17
+ type: String,
18
+ trim: true,
19
+ },
14
20
  organizationId: { type: mongoose.Schema.Types.ObjectId, ref: "organization", default: null },
15
21
  title: { type: String, required: true },
16
22
  module: { type: String, required: true },
@@ -21,8 +27,22 @@ const CustomQuerySchema = new Schema<ICustomQuery>(
21
27
  {
22
28
  timestamps: true, // Automatically adds createdAt and updatedAt fields
23
29
  }
24
- );
25
- CustomQuerySchema.index({ module: 1, client: 1 }, { unique: true });
30
+ );
31
+ CustomQuerySchema.pre('save', async function(next) {
32
+ if (!this.iid) {
33
+ let unique = false;
34
+ while (!unique) {
35
+ const id = generateRandomIID();
36
+ const existing = await mongoose.models.customquery.findOne({ iid: id });
37
+ if (!existing) {
38
+ this.iid = id;
39
+ unique = true;
40
+ }
41
+ }
42
+ }
43
+ next();
44
+ });
45
+
26
46
 
27
47
  const CustomQuery = model<ICustomQuery>('CustomQuery', CustomQuerySchema);
28
48
 
@@ -1,20 +1,29 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
2
3
 
3
4
  export interface IEnvironment extends Document {
5
+ iid: string;
4
6
  name: string;
5
7
  rules_js?: string;
6
8
  client?: mongoose.Schema.Types.ObjectId;
7
9
  organizationId?: mongoose.Schema.Types.ObjectId;
8
10
  isActive?: boolean;
11
+ default?: boolean;
12
+ qa?: boolean;
9
13
  }
10
14
 
11
15
  const EnvironmentSchema = new Schema<IEnvironment>({
16
+ iid: {
17
+ type: String,
18
+ trim: true,
19
+ },
12
20
  name: {
13
21
  type: String,
14
22
  required: true,
15
23
  default: 'Default',
16
24
  trim: true,
17
25
  },
26
+
18
27
  client: {
19
28
  type: mongoose.Schema.Types.ObjectId,
20
29
  ref: "client",
@@ -24,6 +33,10 @@ const EnvironmentSchema = new Schema<IEnvironment>({
24
33
  type: mongoose.Schema.Types.ObjectId,
25
34
  ref: "organization",
26
35
  },
36
+ default: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
27
40
  rules_js: {
28
41
  type: String,
29
42
  default: "return true",
@@ -32,11 +45,30 @@ const EnvironmentSchema = new Schema<IEnvironment>({
32
45
  isActive: {
33
46
  type: Boolean,
34
47
  default: true,
35
- }
48
+ },
49
+ qa: {
50
+ type: Boolean,
51
+ default: false,
52
+ }
36
53
  }, {
37
54
  timestamps: true
38
55
  });
39
56
 
57
+ EnvironmentSchema.pre('save', async function(next) {
58
+ if (!this.iid) {
59
+ let unique = false;
60
+ while (!unique) {
61
+ const id = generateRandomIID();
62
+ const existing = await mongoose.models.environment.findOne({ iid: id });
63
+ if (!existing) {
64
+ this.iid = id;
65
+ unique = true;
66
+ }
67
+ }
68
+ }
69
+ next();
70
+ });
71
+
40
72
  // Compound indexes for common query patterns
41
73
  EnvironmentSchema.index({ client: 1, name: 1 }, { unique: true });
42
74
  EnvironmentSchema.index({ client: 1, isActive: 1 });
@@ -1,8 +1,10 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
2
  import slug from "mongoose-slug-updater"
3
+ import { generateRandomIID } from "../constant";
3
4
  mongoose.plugin(slug)
4
5
 
5
6
  export interface IGoal extends Document {
7
+ iid: string;
6
8
  name: string;
7
9
  details?: string;
8
10
  slug?: string;
@@ -19,11 +21,14 @@ export interface IGoal extends Document {
19
21
  }
20
22
 
21
23
  const GoalSchema = new Schema<IGoal>({
24
+ iid: {
25
+ type: String,
26
+ trim: true,
27
+ },
22
28
  name: {
23
29
  type: String,
24
30
  required: true,
25
31
  trim: true,
26
- index: true,
27
32
  },
28
33
  details: {
29
34
  type: String,
@@ -75,12 +80,26 @@ const GoalSchema = new Schema<IGoal>({
75
80
  timestamps: true
76
81
  });
77
82
 
78
- // Compound indexes for common query patterns
83
+ GoalSchema.pre('save', async function(next) {
84
+ if (!this.iid) {
85
+ let unique = false;
86
+ while (!unique) {
87
+ const id = generateRandomIID();
88
+ const existing = await mongoose.models.goal.findOne({ iid: id });
89
+ if (!existing) {
90
+ this.iid = id;
91
+ unique = true;
92
+ }
93
+ }
94
+ }
95
+ next();
96
+ });
97
+
79
98
  GoalSchema.index({ client: 1});
80
99
  GoalSchema.index({ client: 1, isActive: 1 });
81
100
  GoalSchema.index({ organizationId: 1, client: 1 });
82
101
  GoalSchema.index({ client: 1, name: 1 }, { unique: true });
83
-
102
+ GoalSchema.index({ iid: 1 }, { unique: true });
84
103
  const Goal = mongoose.models.goal || model<IGoal>("goal", GoalSchema);
85
104
 
86
105
  export default Goal;
@@ -1,14 +1,20 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
2
  import slug from "mongoose-slug-updater"
3
+ import { generateRandomIID } from "../constant";
3
4
  mongoose.plugin(slug)
4
5
 
6
+ // Helper function
7
+
8
+
5
9
  export interface IUrltargetings extends Document {
10
+ iid: string;
6
11
  type: string;
7
12
  url: string;
8
13
  url_type: string;
9
14
  }
10
15
 
11
16
  export interface IPage extends Document {
17
+ iid: string;
12
18
  name: string;
13
19
  client?: mongoose.Schema.Types.ObjectId;
14
20
  organizationId?: mongoose.Schema.Types.ObjectId;
@@ -23,6 +29,10 @@ export interface IPage extends Document {
23
29
  }
24
30
 
25
31
  const UrltargetingsSchema = new Schema<IUrltargetings>({
32
+ iid: {
33
+ type: String,
34
+ unique: true,
35
+ },
26
36
  type: {
27
37
  type: String,
28
38
  required: true,
@@ -41,6 +51,10 @@ const UrltargetingsSchema = new Schema<IUrltargetings>({
41
51
  });
42
52
 
43
53
  const PageSchema = new Schema<IPage>({
54
+ iid: {
55
+ type: String,
56
+ unique: true,
57
+ },
44
58
  name: {
45
59
  type: String,
46
60
  required: true,
@@ -98,6 +112,35 @@ const PageSchema = new Schema<IPage>({
98
112
  timestamps: true
99
113
  });
100
114
 
115
+ PageSchema.pre('save', async function(next) {
116
+ if (!this.iid) {
117
+ let unique = false;
118
+ while (!unique) {
119
+ const id = generateRandomIID();
120
+ const existing = await mongoose.models.page.findOne({ iid: id });
121
+ if (!existing) {
122
+ this.iid = id;
123
+ unique = true;
124
+ }
125
+ }
126
+ }
127
+ for (const urltargeting of this.urltargetings) {
128
+ if (!urltargeting.iid) {
129
+ let uniqueVar = false;
130
+ while (!uniqueVar) {
131
+ const id = generateRandomIID();
132
+ const existingVar = await mongoose.models.page.findOne({ "urltargetings.iid": id });
133
+ if (!existingVar) {
134
+ urltargeting.iid = id;
135
+ uniqueVar = true;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ next();
141
+ });
142
+
143
+ PageSchema.index({ iid: 1 }, { unique: true });
101
144
  // Compound indexes for common query patterns
102
145
  PageSchema.index({ client: 1, name: 1 }, { unique: true });
103
146
  PageSchema.index({ client: 1, isActive: 1 });
@@ -28,7 +28,6 @@ const PageElementSchema = new Schema<IPageElement>({
28
28
  organizationId: {
29
29
  type: mongoose.Schema.Types.ObjectId,
30
30
  ref: "organization",
31
- index: true,
32
31
  default: null,
33
32
  },
34
33
  client: {
@@ -20,7 +20,6 @@ const PageTestTypeSchema = new Schema<IPageTestType>({
20
20
  required: true,
21
21
  unique: true,
22
22
  trim: true,
23
- index: true,
24
23
  },
25
24
  details: {
26
25
  type: String,
@@ -34,7 +33,6 @@ const PageTestTypeSchema = new Schema<IPageTestType>({
34
33
  isActive: {
35
34
  type: Boolean,
36
35
  default: true,
37
- index: true,
38
36
  }
39
37
  }, {
40
38
  timestamps: true
@@ -1,6 +1,8 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import { generateRandomIID } from "../constant";
2
3
 
3
4
  export interface IReports extends Document {
5
+ iid: string;
4
6
  name: string;
5
7
  segmentName?: string;
6
8
  reportLink?: string;
@@ -23,6 +25,10 @@ export interface IReports extends Document {
23
25
 
24
26
  const ReportsSchema = new Schema<IReports>(
25
27
  {
28
+ iid: {
29
+ type: String,
30
+ trim: true,
31
+ },
26
32
  organizationId: {
27
33
  type: mongoose.Schema.Types.ObjectId,
28
34
  ref: "organization",
@@ -64,6 +70,22 @@ const ReportsSchema = new Schema<IReports>(
64
70
  }
65
71
  );
66
72
 
73
+ ReportsSchema.pre('save', async function(next) {
74
+ if (!this.iid) {
75
+ let unique = false;
76
+ while (!unique) {
77
+ const id = generateRandomIID();
78
+ const existing = await mongoose.models.report.findOne({ iid: id });
79
+ if (!existing) {
80
+ this.iid = id;
81
+ unique = true;
82
+ }
83
+ }
84
+ }
85
+ next();
86
+ });
87
+
88
+
67
89
  // Add compound indexes for better query performance
68
90
  ReportsSchema.index({ client: 1, conclusion: 1 });
69
91
  ReportsSchema.index({ test: 1, to: -1 }); // For sorting reports by date
@@ -16,7 +16,6 @@ const RoleSchema = new Schema<IRole>({
16
16
  required: true,
17
17
  enum: ["USER", "ADMIN", "EDITOR", "COLLABORATOR", "CLIENT"],
18
18
  trim: true,
19
- index: true,
20
19
  uppercase: true,
21
20
  },
22
21
  description: {
@@ -26,13 +25,12 @@ const RoleSchema = new Schema<IRole>({
26
25
  organizationId: {
27
26
  type: mongoose.Schema.Types.ObjectId,
28
27
  ref: "organization",
29
- index: true,
30
28
  default: null,
31
29
  },
32
30
  isActive: {
33
31
  type: Boolean,
34
32
  default: true,
35
- index: true,
33
+
36
34
  }
37
35
  }, {
38
36
  timestamps: true
@@ -22,20 +22,18 @@ const SnippetSchema = new Schema<ISnippet>(
22
22
  type: mongoose.Schema.Types.ObjectId,
23
23
  ref: "organization",
24
24
  default: null,
25
- index: true,
25
+
26
26
  },
27
27
  name: {
28
28
  type: String,
29
29
  required: true,
30
30
  unique: true,
31
31
  trim: true,
32
- index: true,
33
32
  },
34
33
  pageelement: {
35
34
  type: [mongoose.Schema.Types.ObjectId],
36
35
  ref: "pageelement",
37
36
  default: [],
38
- index: true,
39
37
  },
40
38
  client: {
41
39
  type: mongoose.Schema.Types.ObjectId,
@@ -73,7 +71,6 @@ const SnippetSchema = new Schema<ISnippet>(
73
71
  test: {
74
72
  type: mongoose.Schema.Types.ObjectId,
75
73
  ref: "test",
76
- index: true,
77
74
  },
78
75
  status: {
79
76
  type: String,