codebase-models 1.0.7 → 2.0.1

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 (148) hide show
  1. package/.github/workflows/npm-publish.yml +33 -0
  2. package/dist/index.d.ts +4 -3
  3. package/dist/index.js +7 -5
  4. package/dist/src/models/Announcement.d.ts +7 -8
  5. package/dist/src/models/Announcement.js +30 -10
  6. package/dist/src/models/AppEvent.d.ts +1 -3
  7. package/dist/src/models/AppEvent.js +1 -1
  8. package/dist/src/models/Audience.d.ts +2 -3
  9. package/dist/src/models/Audience.js +6 -1
  10. package/dist/src/models/{Experiments.d.ts → BqPreCompiledData.d.ts} +12 -32
  11. package/dist/src/models/{ClientExperiment.js → BqPreCompiledData.js} +26 -46
  12. package/dist/src/models/CVRReport.d.ts +2 -3
  13. package/dist/src/models/CVRReport.js +14 -1
  14. package/dist/src/models/Client.d.ts +2 -4
  15. package/dist/src/models/Client.js +32 -52
  16. package/dist/src/models/ClientAdditionalRevenue.d.ts +2 -4
  17. package/dist/src/models/ClientAdditionalRevenue.js +4 -3
  18. package/dist/src/models/ClientLearning.d.ts +2 -4
  19. package/dist/src/models/ClientLearning.js +11 -7
  20. package/dist/src/models/ClientLinks.d.ts +2 -4
  21. package/dist/src/models/ClientLinks.js +16 -7
  22. package/dist/src/models/ClientNextSteps.d.ts +2 -4
  23. package/dist/src/models/ClientNextSteps.js +4 -3
  24. package/dist/src/models/ClientNote.d.ts +2 -4
  25. package/dist/src/models/ClientNote.js +4 -3
  26. package/dist/src/models/ClientReportsTemp.d.ts +2 -4
  27. package/dist/src/models/ClientReportsTemp.js +21 -3
  28. package/dist/src/models/ClientRetention.d.ts +2 -3
  29. package/dist/src/models/ClientRetention.js +19 -1
  30. package/dist/src/models/ClientScript.d.ts +2 -4
  31. package/dist/src/models/ClientScript.js +25 -9
  32. package/dist/src/models/ClientStrategy.d.ts +2 -4
  33. package/dist/src/models/ClientStrategy.js +4 -3
  34. package/dist/src/models/ClientSurvay.d.ts +2 -7
  35. package/dist/src/models/ClientSurvay.js +6 -1
  36. package/dist/src/models/Environment.d.ts +3 -3
  37. package/dist/src/models/Environment.js +27 -3
  38. package/dist/src/models/Faqs.d.ts +2 -3
  39. package/dist/src/models/Faqs.js +6 -1
  40. package/dist/src/models/Feedback.d.ts +2 -4
  41. package/dist/src/models/Feedback.js +4 -3
  42. package/dist/src/models/Goal.d.ts +3 -4
  43. package/dist/src/models/Goal.js +34 -12
  44. package/dist/src/models/Hypothesis.d.ts +3 -3
  45. package/dist/src/models/Hypothesis.js +50 -10
  46. package/dist/src/models/HypothesisSheet.d.ts +2 -4
  47. package/dist/src/models/HypothesisSheet.js +27 -3
  48. package/dist/src/models/LandingPages.d.ts +4 -3
  49. package/dist/src/models/LandingPages.js +30 -1
  50. package/dist/src/models/NewIdeas.d.ts +2 -4
  51. package/dist/src/models/NewIdeas.js +4 -3
  52. package/dist/src/models/Notification.d.ts +2 -3
  53. package/dist/src/models/Notification.js +30 -2
  54. package/dist/src/models/{ClientExperiment.d.ts → Organization.d.ts} +18 -31
  55. package/dist/src/models/{Experiments.js → Organization.js} +36 -54
  56. package/dist/src/models/Page.d.ts +4 -4
  57. package/dist/src/models/Page.js +57 -5
  58. package/dist/src/models/PageElement.d.ts +4 -3
  59. package/dist/src/models/PageElement.js +60 -8
  60. package/dist/src/models/PageTestType.d.ts +3 -3
  61. package/dist/src/models/PageTestType.js +42 -6
  62. package/dist/src/models/Portfolio.d.ts +2 -3
  63. package/dist/src/models/Portfolio.js +6 -1
  64. package/dist/src/models/PrecalculationFilters.d.ts +34 -0
  65. package/dist/src/models/PrecalculationFilters.js +78 -0
  66. package/dist/src/models/QueryLog.d.ts +2 -4
  67. package/dist/src/models/QueryLog.js +4 -3
  68. package/dist/src/models/ReadNotification.d.ts +2 -3
  69. package/dist/src/models/ReadNotification.js +30 -2
  70. package/dist/src/models/Report.d.ts +3 -4
  71. package/dist/src/models/Report.js +33 -49
  72. package/dist/src/models/Role.d.ts +4 -3
  73. package/dist/src/models/Role.js +51 -8
  74. package/dist/src/models/SavedSegment.d.ts +2 -3
  75. package/dist/src/models/SavedSegment.js +6 -1
  76. package/dist/src/models/Segment.d.ts +2 -3
  77. package/dist/src/models/Segment.js +6 -1
  78. package/dist/src/models/SegmentCombination.d.ts +2 -3
  79. package/dist/src/models/SegmentCombination.js +6 -1
  80. package/dist/src/models/Snippet.d.ts +3 -4
  81. package/dist/src/models/Snippet.js +29 -4
  82. package/dist/src/models/StageInCustomerJourney.d.ts +4 -4
  83. package/dist/src/models/StageInCustomerJourney.js +56 -4
  84. package/dist/src/models/Tag.d.ts +2 -3
  85. package/dist/src/models/Tag.js +30 -2
  86. package/dist/src/models/Temp.d.ts +2 -3
  87. package/dist/src/models/Temp.js +30 -2
  88. package/dist/src/models/Test.d.ts +17 -18
  89. package/dist/src/models/Test.js +83 -186
  90. package/dist/src/models/TestSequentialValue.d.ts +2 -3
  91. package/dist/src/models/TestSequentialValue.js +6 -1
  92. package/dist/src/models/Tier.d.ts +2 -3
  93. package/dist/src/models/Tier.js +30 -2
  94. package/dist/src/models/Trigger.d.ts +2 -3
  95. package/dist/src/models/Trigger.js +30 -2
  96. package/dist/src/models/User.d.ts +2 -3
  97. package/dist/src/models/User.js +10 -11
  98. package/index.ts +6 -4
  99. package/package.json +1 -1
  100. package/src/models/Announcement.ts +51 -28
  101. package/src/models/AppEvent.ts +1 -1
  102. package/src/models/Audience.ts +7 -1
  103. package/src/models/BqPreCompiledData.ts +62 -0
  104. package/src/models/CVRReport.ts +18 -1
  105. package/src/models/Client.ts +40 -60
  106. package/src/models/ClientAdditionalRevenue.ts +5 -4
  107. package/src/models/ClientLearning.ts +12 -8
  108. package/src/models/ClientLinks.ts +19 -8
  109. package/src/models/ClientNextSteps.ts +5 -4
  110. package/src/models/ClientNote.ts +5 -4
  111. package/src/models/ClientReportsTemp.ts +25 -4
  112. package/src/models/ClientRetention.ts +28 -2
  113. package/src/models/ClientScript.ts +27 -10
  114. package/src/models/ClientStrategy.ts +5 -4
  115. package/src/models/ClientSurvay.ts +7 -1
  116. package/src/models/Environment.ts +32 -4
  117. package/src/models/Faqs.ts +7 -1
  118. package/src/models/Feedback.ts +5 -4
  119. package/src/models/Goal.ts +37 -13
  120. package/src/models/Hypothesis.ts +30 -9
  121. package/src/models/HypothesisSheet.ts +4 -3
  122. package/src/models/LandingPages.ts +35 -1
  123. package/src/models/NewIdeas.ts +5 -4
  124. package/src/models/Notification.ts +7 -1
  125. package/src/models/Organization.ts +86 -0
  126. package/src/models/Page.ts +63 -6
  127. package/src/models/PageElement.ts +39 -8
  128. package/src/models/PageTestType.ts +22 -5
  129. package/src/models/Portfolio.ts +7 -1
  130. package/src/models/PrecalculationFilters.ts +68 -0
  131. package/src/models/QueryLog.ts +5 -4
  132. package/src/models/ReadNotification.ts +7 -1
  133. package/src/models/Report.ts +55 -67
  134. package/src/models/Role.ts +32 -7
  135. package/src/models/SavedSegment.ts +7 -1
  136. package/src/models/Segment.ts +7 -1
  137. package/src/models/SegmentCombination.ts +7 -1
  138. package/src/models/Snippet.ts +33 -5
  139. package/src/models/StageInCustomerJourney.ts +34 -6
  140. package/src/models/Tag.ts +7 -1
  141. package/src/models/Temp.ts +7 -1
  142. package/src/models/Test.ts +156 -244
  143. package/src/models/TestSequentialValue.ts +7 -1
  144. package/src/models/Tier.ts +7 -1
  145. package/src/models/Trigger.ts +7 -1
  146. package/src/models/User.ts +12 -11
  147. package/src/models/ClientExperiment.ts +0 -113
  148. package/src/models/Experiments.ts +0 -118
@@ -6,7 +6,7 @@ export interface IClientScriptSchema extends Document {
6
6
  }
7
7
 
8
8
  export interface IClientScript extends Document {
9
- organisationId?: string;
9
+ organizationId?: mongoose.Schema.Types.ObjectId;
10
10
  client?: mongoose.Schema.Types.ObjectId;
11
11
  viewId?: string;
12
12
  clientScriptURL: string;
@@ -41,23 +41,28 @@ export interface IClientScript extends Document {
41
41
 
42
42
  const ClientScriptSchema = new Schema<IClientScript>(
43
43
  {
44
- organisationId: {
45
- type: String,
44
+ organizationId: {
45
+ type: mongoose.Schema.Types.ObjectId,
46
+ ref: "organization",
46
47
  default: null,
47
48
  },
48
49
  client: {
49
50
  type: mongoose.Schema.Types.ObjectId,
50
51
  ref: "client",
52
+ index: true,
51
53
  },
52
54
  viewId: {
53
55
  type: String,
56
+ index: true,
54
57
  },
55
58
  clientScriptURL: {
56
59
  type: String,
60
+ trim: true,
57
61
  },
58
62
  jquery_include: {
59
63
  type: String,
60
64
  default: "false",
65
+ trim: true,
61
66
  },
62
67
  debug: {
63
68
  type: Boolean,
@@ -76,6 +81,7 @@ const ClientScriptSchema = new Schema<IClientScript>(
76
81
  },
77
82
  activation_mode: {
78
83
  type: String,
84
+ trim: true,
79
85
  },
80
86
  use_antiflicker: {
81
87
  type: Boolean,
@@ -87,17 +93,21 @@ const ClientScriptSchema = new Schema<IClientScript>(
87
93
  },
88
94
  rules: {
89
95
  type: String,
90
- default: "return true;"
96
+ default: "return true;",
97
+ trim: true,
91
98
  },
92
99
  rules_tracking: {
93
100
  type: String,
94
- default: "return true;"
101
+ default: "return true;",
102
+ trim: true,
95
103
  },
96
104
  tracker_url: {
97
105
  type: String,
106
+ trim: true,
98
107
  },
99
108
  asset_url: {
100
109
  type: String,
110
+ trim: true,
101
111
  },
102
112
  metadata_key_exp_1: {
103
113
  type: mongoose.Schema.Types.Mixed,
@@ -119,6 +129,7 @@ const ClientScriptSchema = new Schema<IClientScript>(
119
129
  },
120
130
  cookie_domain: {
121
131
  type: String,
132
+ trim: true,
122
133
  },
123
134
  snippet_version: {
124
135
  type: Number,
@@ -126,6 +137,7 @@ const ClientScriptSchema = new Schema<IClientScript>(
126
137
  storage: {
127
138
  type: String,
128
139
  default: "default",
140
+ trim: true,
129
141
  },
130
142
  run_only_on_reinit: {
131
143
  type: Boolean,
@@ -140,9 +152,11 @@ const ClientScriptSchema = new Schema<IClientScript>(
140
152
  },
141
153
  jscode: {
142
154
  type: String,
155
+ trim: true,
143
156
  },
144
157
  csscode: {
145
158
  type: String,
159
+ trim: true,
146
160
  },
147
161
  is_spa: {
148
162
  type: Boolean,
@@ -154,11 +168,14 @@ const ClientScriptSchema = new Schema<IClientScript>(
154
168
  }
155
169
  );
156
170
 
157
- ClientScriptSchema.index({
158
- client: 1,
159
- viewId: 1,
160
- });
171
+ // Compound indexes for common query patterns
172
+ ClientScriptSchema.index({ client: 1 });
173
+ // Sparse indexes for optional fields
174
+ ClientScriptSchema.index({ organisationId: 1 }, { sparse: true });
175
+ ClientScriptSchema.index({ tracker_url: 1 }, { sparse: true });
176
+ ClientScriptSchema.index({ asset_url: 1 }, { sparse: true });
177
+
161
178
 
162
- const ClientScript = model<IClientScript>("clientscript", ClientScriptSchema);
179
+ const ClientScript = mongoose.models.clientscript || model<IClientScript>("clientscript", ClientScriptSchema);
163
180
 
164
181
  export default ClientScript;
@@ -6,7 +6,7 @@ export interface IClientStrategy extends Document {
6
6
  startDate?: Date;
7
7
  endDate?: Date;
8
8
  strategies?: mongoose.Schema.Types.Mixed;
9
- organisationId?: string;
9
+ organizationId?: mongoose.Schema.Types.ObjectId;
10
10
  client?: mongoose.Schema.Types.ObjectId;
11
11
  learningsoftime?: mongoose.Schema.Types.Mixed;
12
12
  viewId?: string;
@@ -32,8 +32,9 @@ const ClientStrategySchema = new Schema<IClientStrategy>(
32
32
  strategies: {
33
33
  type: mongoose.Schema.Types.Mixed,
34
34
  },
35
- organisationId: {
36
- type: String,
35
+ organizationId: {
36
+ type: mongoose.Schema.Types.ObjectId,
37
+ ref: "organization",
37
38
  default: null,
38
39
  },
39
40
  client: {
@@ -63,7 +64,7 @@ ClientStrategySchema.index({
63
64
  viewId: 1,
64
65
  });
65
66
 
66
- const ClientStrategy = model<IClientStrategy>(
67
+ const ClientStrategy = mongoose.models.clientstrategy || model<IClientStrategy>(
67
68
  "clientstrategy",
68
69
  ClientStrategySchema
69
70
  );
@@ -3,6 +3,7 @@ import mongoose, { Document, Schema, model } from "mongoose";
3
3
  export interface IClientSurvay extends Document {
4
4
  responses: IResponce;
5
5
  user?: mongoose.Schema.Types.ObjectId;
6
+ organizationId?: mongoose.Schema.Types.ObjectId;
6
7
  }
7
8
 
8
9
  export interface IResponce extends Document {
@@ -26,11 +27,16 @@ const ClientSurveySchema = new Schema<IClientSurvay>(
26
27
  type: mongoose.Schema.Types.ObjectId,
27
28
  ref: "user",
28
29
  },
30
+ organizationId: {
31
+ type: mongoose.Schema.Types.ObjectId,
32
+ ref: "organization",
33
+ default: null,
34
+ },
29
35
  },
30
36
  {
31
37
  timestamps: true,
32
38
  }
33
39
  );
34
40
 
35
- const ClientSurvey = model("clientsurvey", ClientSurveySchema);
41
+ const ClientSurvey = mongoose.models.clientsurvey || model("clientsurvey", ClientSurveySchema);
36
42
  export default ClientSurvey;
@@ -4,26 +4,54 @@ export interface IEnvironment extends Document {
4
4
  name: string;
5
5
  rules_js?: string;
6
6
  client?: mongoose.Schema.Types.ObjectId;
7
+ organizationId?: mongoose.Schema.Types.ObjectId;
8
+ isActive?: boolean;
7
9
  }
8
10
 
9
11
  const EnvironmentSchema = new Schema<IEnvironment>({
10
12
  name: {
11
13
  type: String,
12
14
  required: true,
13
- default: 'Default'
15
+ default: 'Default',
16
+ trim: true,
17
+ index: true,
14
18
  },
15
19
  client: {
16
20
  type: mongoose.Schema.Types.ObjectId,
17
21
  ref: "client",
22
+ required: true,
23
+ index: true,
24
+ },
25
+ organizationId: {
26
+ type: mongoose.Schema.Types.ObjectId,
27
+ ref: "organization",
28
+ index: true,
18
29
  },
19
30
  rules_js: {
20
31
  type: String,
21
- default: "return true"
32
+ default: "return true",
33
+ trim: true,
22
34
  },
23
- },{
35
+ isActive: {
36
+ type: Boolean,
37
+ default: true,
38
+ index: true,
39
+ }
40
+ }, {
24
41
  timestamps: true
25
42
  });
26
43
 
27
- const Environment = model<IEnvironment>("environment", EnvironmentSchema);
44
+ // Compound indexes for common query patterns
45
+ EnvironmentSchema.index({ client: 1, name: 1 }, { unique: true });
46
+ EnvironmentSchema.index({ client: 1, isActive: 1 });
47
+ EnvironmentSchema.index({ organizationId: 1, client: 1 });
48
+ EnvironmentSchema.index({ organizationId: 1, name: 1 }, {
49
+ sparse: true,
50
+ });
51
+
52
+ // Text index for full-text search
53
+ EnvironmentSchema.index({ name: 'text' });
54
+
55
+ const Environment = mongoose.models.environment || model<IEnvironment>("environment", EnvironmentSchema);
28
56
 
29
57
  export default Environment;
@@ -6,6 +6,7 @@ export interface IFaqs extends Document {
6
6
  keywords?: mongoose.Schema.Types.Array;
7
7
  createdAt?: Date;
8
8
  updatedAt?: Date;
9
+ organizationId?: mongoose.Schema.Types.ObjectId;
9
10
  }
10
11
 
11
12
  const FaqSchema = new Schema<IFaqs>({
@@ -26,7 +27,12 @@ const FaqSchema = new Schema<IFaqs>({
26
27
  type: Date,
27
28
  default: new Date(),
28
29
  },
30
+ organizationId: {
31
+ type: mongoose.Schema.Types.ObjectId,
32
+ ref: "organization",
33
+ default: null,
34
+ },
29
35
  });
30
36
 
31
- const Faq = model<IFaqs>("faq", FaqSchema);
37
+ const Faq = mongoose.models.faq || model<IFaqs>("faq", FaqSchema);
32
38
  export default Faq;
@@ -5,7 +5,7 @@ export interface IFeedback extends Document {
5
5
  details?: string;
6
6
  client?: mongoose.Schema.Types.ObjectId;
7
7
  thread?: mongoose.Schema.Types.Mixed;
8
- organisationId?: string;
8
+ organizationId?: mongoose.Schema.Types.ObjectId;
9
9
  createdAt?: Date;
10
10
  updatedAt?: Date;
11
11
  }
@@ -27,8 +27,9 @@ const FeedbackSchema = new Schema<IFeedback>({
27
27
  type: mongoose.Schema.Types.Mixed,
28
28
  default: [],
29
29
  },
30
- organisationId: {
31
- type: String,
30
+ organizationId: {
31
+ type: mongoose.Schema.Types.ObjectId,
32
+ ref: "organization",
32
33
  default: null,
33
34
  },
34
35
  createdAt: {
@@ -41,6 +42,6 @@ const FeedbackSchema = new Schema<IFeedback>({
41
42
  },
42
43
  });
43
44
 
44
- const Feedback = model<IFeedback>("feedback", FeedbackSchema);
45
+ const Feedback = mongoose.models.feedback || model<IFeedback>("feedback", FeedbackSchema);
45
46
 
46
47
  export default Feedback;
@@ -6,13 +6,14 @@ export interface IGoal extends Document {
6
6
  name: string;
7
7
  details?: string;
8
8
  slug?: string;
9
- organisationId?: string;
9
+ organizationId?: mongoose.Schema.Types.ObjectId;
10
10
  client?: mongoose.Schema.Types.ObjectId;
11
11
  type: string;
12
12
  counting_method: string;
13
13
  css_selector: string;
14
14
  api_name: string;
15
15
  rules_js: string;
16
+ isActive?: boolean;
16
17
  createdAt?: Date;
17
18
  updatedAt?: Date;
18
19
  }
@@ -21,45 +22,68 @@ const GoalSchema = new Schema<IGoal>({
21
22
  name: {
22
23
  type: String,
23
24
  required: true,
25
+ trim: true,
26
+ index: true,
24
27
  },
25
28
  details: {
26
29
  type: String,
27
30
  default: "",
31
+ trim: true,
28
32
  },
29
33
  slug: {
30
34
  type: String,
35
+ unique: true,
36
+ sparse: true,
31
37
  },
32
- organisationId: {
33
- type: String,
38
+ organizationId: {
39
+ type: mongoose.Schema.Types.ObjectId,
40
+ ref: "organization",
34
41
  default: null,
42
+ index: true,
35
43
  },
36
44
  client: {
37
45
  type: mongoose.Schema.Types.ObjectId,
38
46
  ref: "client",
47
+ index: true,
39
48
  },
40
49
  type: {
41
50
  type: String,
51
+ trim: true,
42
52
  },
43
53
  counting_method: {
44
54
  type: String,
55
+ trim: true,
45
56
  },
46
57
  css_selector: {
47
58
  type: String,
59
+ trim: true,
60
+ },
61
+ api_name: {
62
+ type: String,
63
+ slug: ["name"],
64
+ slugPaddingSize: 4,
65
+ unique: true,
66
+ trim: true,
48
67
  },
49
- api_name: { type: String, slug: ["name"], slugPaddingSize: 4, unique: true },
50
68
  rules_js: {
51
69
  type: String,
70
+ trim: true,
52
71
  },
53
- createdAt: {
54
- type: Date,
55
- default: new Date(),
56
- },
57
- updatedAt: {
58
- type: Date,
59
- default: new Date(),
60
- },
72
+ isActive: {
73
+ type: Boolean,
74
+ default: true,
75
+ index: true,
76
+ }
77
+ }, {
78
+ timestamps: true
61
79
  });
62
80
 
63
- const Goal = model<IGoal>("goal", GoalSchema);
81
+ // Compound indexes for common query patterns
82
+ GoalSchema.index({ client: 1});
83
+ GoalSchema.index({ client: 1, isActive: 1 });
84
+ GoalSchema.index({ organizationId: 1, client: 1 });
85
+ GoalSchema.index({ client: 1, name: 1 }, { unique: true });
86
+
87
+ const Goal = mongoose.models.goal || model<IGoal>("goal", GoalSchema);
64
88
 
65
89
  export default Goal;
@@ -1,50 +1,71 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
2
 
3
3
  export interface IHypothesis extends Document {
4
+ organizationId?: mongoose.Schema.Types.ObjectId;
4
5
  hypothesisNumber?: string;
5
6
  name: string;
6
7
  action: string;
7
8
  result: string;
8
9
  expectation: string;
9
10
  tagged?: string;
11
+ isActive?: boolean;
10
12
  createdAt?: Date;
11
13
  updatedAt?: Date;
12
14
  }
13
15
 
14
16
  const HypothesisSchema = new Schema<IHypothesis>({
17
+ organizationId: {
18
+ type: mongoose.Schema.Types.ObjectId,
19
+ ref: "organization",
20
+ default: null,
21
+ },
15
22
  hypothesisNumber: {
16
23
  type: String,
24
+ trim: true,
25
+ index: true,
17
26
  },
18
27
  name: {
19
28
  type: String,
20
29
  required: true,
30
+ trim: true,
31
+ index: true,
21
32
  },
22
33
  action: {
23
34
  type: String,
24
35
  required: true,
36
+ trim: true,
25
37
  },
26
38
  result: {
27
39
  type: String,
28
40
  required: true,
41
+ trim: true,
29
42
  },
30
43
  expectation: {
31
44
  type: String,
32
45
  required: true,
46
+ trim: true,
33
47
  },
34
48
  tagged: {
35
49
  type: String,
36
50
  default: "General Purpose",
51
+ trim: true,
52
+ index: true,
37
53
  },
38
- createdAt: {
39
- type: Date,
40
- default: new Date(),
41
- },
42
- updatedAt: {
43
- type: Date,
44
- default: new Date(),
45
- },
54
+ isActive: {
55
+ type: Boolean,
56
+ default: true,
57
+ index: true,
58
+ }
59
+ }, {
60
+ timestamps: true
46
61
  });
47
62
 
48
- const Hypothesis = model<IHypothesis>("hypos", HypothesisSchema);
63
+ // Compound indexes for common query patterns
64
+ HypothesisSchema.index({ hypothesisNumber: 1, isActive: 1 });
65
+ HypothesisSchema.index({ tagged: 1, isActive: 1 });
66
+ HypothesisSchema.index({ name: 1, isActive: 1 });
67
+
68
+
69
+ const Hypothesis = mongoose.models.hypothesis || model<IHypothesis>("hypothesis", HypothesisSchema);
49
70
 
50
71
  export default Hypothesis;
@@ -2,7 +2,7 @@ import mongoose, { Document, Schema, model } from "mongoose";
2
2
  import HypothesisSheetConstants from "../constant";
3
3
 
4
4
  export interface IHypothesisSheet extends Document {
5
- organizationId?: string;
5
+ organizationId?: mongoose.Schema.Types.ObjectId;
6
6
  client?: mongoose.Schema.Types.ObjectId;
7
7
  viewId?: string;
8
8
  pageelement?: mongoose.Schema.Types.ObjectId;
@@ -25,8 +25,9 @@ export interface IHypothesisSheet extends Document {
25
25
  const HypothesisSheetSchema = new Schema<IHypothesisSheet>(
26
26
  {
27
27
  organizationId: {
28
- type: String,
28
+ type: mongoose.Schema.Types.ObjectId,
29
29
  default: null,
30
+ ref: "organization",
30
31
  },
31
32
  client: {
32
33
  type: Schema.Types.ObjectId,
@@ -106,7 +107,7 @@ const HypothesisSheetSchema = new Schema<IHypothesisSheet>(
106
107
  }
107
108
  );
108
109
 
109
- const HypothesisSheet = model<IHypothesisSheet>(
110
+ const HypothesisSheet = mongoose.models.hypothesissheet || model<IHypothesisSheet>(
110
111
  "hypothesisSheet",
111
112
  HypothesisSheetSchema
112
113
  );
@@ -2,19 +2,29 @@ import mongoose, { Document, Schema, model } from "mongoose";
2
2
 
3
3
  export interface ILandingPagesData extends Document {
4
4
  conversionRate?: Number;
5
+ lastUpdated?: Date;
5
6
  }
6
7
 
7
8
  const LandingPageDataSchema = new Schema<ILandingPagesData>({
8
9
  conversionRate: {
9
10
  type: Number,
11
+ min: 0,
12
+ max: 100,
13
+ index: true,
10
14
  },
15
+ lastUpdated: {
16
+ type: Date,
17
+ default: Date.now,
18
+ }
11
19
  });
12
20
 
13
21
  export interface ILandingPages extends Document {
14
22
  title: string;
15
23
  client?: mongoose.Schema.Types.ObjectId;
24
+ organizationId?: mongoose.Schema.Types.ObjectId;
16
25
  screenshot?: string;
17
26
  dataPoints?: ILandingPagesData;
27
+ isActive?: boolean;
18
28
  }
19
29
 
20
30
  const LandingPagesSchema = new Schema<ILandingPages>(
@@ -22,25 +32,49 @@ const LandingPagesSchema = new Schema<ILandingPages>(
22
32
  title: {
23
33
  type: String,
24
34
  required: true,
35
+ trim: true,
36
+ index: true,
25
37
  },
26
38
  client: {
27
39
  type: mongoose.Schema.Types.ObjectId,
28
40
  ref: "client",
29
41
  required: true,
42
+ index: true,
43
+ },
44
+ organizationId: {
45
+ type: mongoose.Schema.Types.ObjectId,
46
+ ref: "organization",
47
+ index: true,
30
48
  },
31
49
  screenshot: {
32
50
  type: String,
33
51
  default: null,
52
+ trim: true,
34
53
  },
35
54
  dataPoints: {
36
55
  type: LandingPageDataSchema,
37
56
  default: {},
38
57
  },
58
+ isActive: {
59
+ type: Boolean,
60
+ default: true,
61
+ index: true,
62
+ }
39
63
  },
40
64
  {
41
65
  timestamps: true,
42
66
  }
43
67
  );
44
68
 
45
- const LandingPages = model<ILandingPages>("LandingPages", LandingPagesSchema);
69
+ // Compound indexes for common query patterns
70
+ LandingPagesSchema.index({ client: 1, title: 1 }, { unique: true });
71
+ LandingPagesSchema.index({ client: 1, isActive: 1 });
72
+ LandingPagesSchema.index({ organizationId: 1, client: 1 });
73
+ LandingPagesSchema.index({ organizationId: 1, title: 1 });
74
+ LandingPagesSchema.index({ client: 1, 'dataPoints.conversionRate': -1 });
75
+
76
+ // Text index for full-text search
77
+ LandingPagesSchema.index({ title: 'text' });
78
+
79
+ const LandingPages = mongoose.models.landingpages || model<ILandingPages>("landingpages", LandingPagesSchema);
46
80
  export default LandingPages;
@@ -1,7 +1,7 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
2
 
3
3
  export interface INewIdeas extends Document {
4
- organisationId?: string;
4
+ organizationId?: mongoose.Schema.Types.ObjectId;
5
5
  ideaName: string;
6
6
  client?: mongoose.Schema.Types.ObjectId;
7
7
  hypothesis?: mongoose.Schema.Types.ObjectId;
@@ -14,8 +14,9 @@ export interface INewIdeas extends Document {
14
14
 
15
15
  const NewIdeasSchema = new Schema<INewIdeas>(
16
16
  {
17
- organisationId: {
18
- type: String,
17
+ organizationId: {
18
+ type: mongoose.Schema.Types.ObjectId,
19
+ ref: "organization",
19
20
  default: null,
20
21
  },
21
22
  ideaName: {
@@ -59,5 +60,5 @@ NewIdeasSchema.index({
59
60
  viewId: 1,
60
61
  });
61
62
 
62
- const NewIdeas = model<INewIdeas>("Newideas", NewIdeasSchema);
63
+ const NewIdeas = mongoose.models.newideas || model<INewIdeas>("newideas", NewIdeasSchema);
63
64
  export default NewIdeas;
@@ -8,10 +8,16 @@ export interface INotification extends Document {
8
8
  archive?: boolean;
9
9
  module?: string;
10
10
  moduleData?: string;
11
+ organizationId?: mongoose.Schema.Types.ObjectId;
11
12
  }
12
13
 
13
14
  const NotificationSchema = new Schema<INotification>(
14
15
  {
16
+ organizationId: {
17
+ type: mongoose.Schema.Types.ObjectId,
18
+ ref: "organization",
19
+ default: null,
20
+ },
15
21
  title: {
16
22
  type: String,
17
23
  },
@@ -42,6 +48,6 @@ const NotificationSchema = new Schema<INotification>(
42
48
  }
43
49
  );
44
50
 
45
- const Notification = model<INotification>("notification", NotificationSchema);
51
+ const Notification = mongoose.models.notification || model<INotification>("notification", NotificationSchema);
46
52
 
47
53
  export default Notification;