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
@@ -0,0 +1,86 @@
1
+ import mongoose, { Document, Schema, model } from "mongoose";
2
+
3
+ export interface IOrganization extends Document {
4
+ name: string;
5
+ description: string;
6
+ adminEmail: string;
7
+ adminContact: string;
8
+ createdBy: mongoose.Schema.Types.ObjectId;
9
+ address: string;
10
+ city: string;
11
+ state: string;
12
+ zip: string;
13
+ country: string;
14
+ phone: string;
15
+ logo: string;
16
+ website: string;
17
+ createdAt: Date;
18
+ updatedAt: Date;
19
+ isActive: boolean;
20
+ }
21
+ const OrganizationSchema = new Schema<IOrganization>({
22
+ name: {
23
+ type: String,
24
+ required: true,
25
+ unique: true,
26
+ },
27
+ description: {
28
+ type: String,
29
+ required: true,
30
+ },
31
+ adminEmail: {
32
+ type: String,
33
+ required: true,
34
+ },
35
+ adminContact: {
36
+ type: String,
37
+ required: true,
38
+ },
39
+ createdBy: {
40
+ type: mongoose.Schema.Types.ObjectId,
41
+ ref: "user",
42
+ },
43
+ address: {
44
+ type: String,
45
+ required: true,
46
+ },
47
+ city: {
48
+ type: String,
49
+ required: true,
50
+ },
51
+ state: {
52
+ type: String,
53
+ required: true,
54
+ },
55
+ zip: {
56
+ type: String,
57
+ required: true,
58
+ },
59
+ country: {
60
+ type: String,
61
+ required: true,
62
+ },
63
+ phone: {
64
+ type: String,
65
+ required: true,
66
+ },
67
+ logo: {
68
+ type: String,
69
+ required: true,
70
+ },
71
+ website: {
72
+ type: String,
73
+ required: true,
74
+ },
75
+ isActive: {
76
+ type: Boolean,
77
+ default: true,
78
+ },
79
+ }, {
80
+ timestamps: true
81
+ });
82
+ const Organization = mongoose.models.organization || model<IOrganization>("organization", OrganizationSchema);
83
+
84
+ OrganizationSchema.index({ name: 1, isActive: 1 });
85
+
86
+ export default Organization;
@@ -1,6 +1,7 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
2
  import slug from "mongoose-slug-updater"
3
3
  mongoose.plugin(slug)
4
+
4
5
  export interface IUrltargetings extends Document {
5
6
  type: string;
6
7
  url: string;
@@ -10,24 +11,32 @@ export interface IUrltargetings extends Document {
10
11
  export interface IPage extends Document {
11
12
  name: string;
12
13
  client?: mongoose.Schema.Types.ObjectId;
14
+ organizationId?: mongoose.Schema.Types.ObjectId;
13
15
  trigger: string;
14
16
  trigger_js: string;
15
17
  api_name: string;
16
18
  poll_on_rules: Boolean;
17
19
  deactivation_mode: string;
18
20
  rules_js: string;
19
- urltargetings: IUrltargetings;
21
+ urltargetings: IUrltargetings[];
22
+ isActive?: boolean;
20
23
  }
21
24
 
22
25
  const UrltargetingsSchema = new Schema<IUrltargetings>({
23
26
  type: {
24
27
  type: String,
28
+ required: true,
29
+ trim: true,
25
30
  },
26
31
  url: {
27
32
  type: String,
33
+ required: true,
34
+ trim: true,
28
35
  },
29
36
  url_type: {
30
37
  type: String,
38
+ required: true,
39
+ trim: true,
31
40
  },
32
41
  });
33
42
 
@@ -35,35 +44,83 @@ const PageSchema = new Schema<IPage>({
35
44
  name: {
36
45
  type: String,
37
46
  required: true,
47
+ trim: true,
48
+ index: true,
38
49
  },
39
50
  trigger: {
40
51
  type: String,
41
- default: "direct"
52
+ default: "direct",
53
+ trim: true,
54
+ index: true,
55
+ },
56
+ organizationId: {
57
+ type: mongoose.Schema.Types.ObjectId,
58
+ ref: "organization",
59
+ default: null,
60
+ index: true,
42
61
  },
43
62
  client: {
44
63
  type: mongoose.Schema.Types.ObjectId,
45
64
  ref: "client",
65
+ required: true,
66
+ index: true,
46
67
  },
47
68
  trigger_js: {
48
69
  type: String,
49
- default: ""
70
+ default: "",
71
+ trim: true,
72
+ },
73
+ api_name: {
74
+ type: String,
75
+ slug: ["name"],
76
+ slugPaddingSize: 4,
77
+ unique: true,
78
+ trim: true,
50
79
  },
51
- api_name: { type: String, slug: ["name"], slugPaddingSize: 4, unique: true },
52
80
  poll_on_rules: {
53
81
  type: Boolean,
54
82
  default: false,
83
+ index: true,
55
84
  },
56
85
  deactivation_mode: {
57
86
  type: String,
58
87
  default: "reset",
88
+ trim: true,
59
89
  },
60
90
  rules_js: {
61
91
  type: String,
62
- default:"return true"
92
+ default: "return true",
93
+ trim: true,
63
94
  },
64
95
  urltargetings: [UrltargetingsSchema],
96
+ isActive: {
97
+ type: Boolean,
98
+ default: true,
99
+ index: true,
100
+ }
101
+ }, {
102
+ timestamps: true
65
103
  });
66
104
 
67
- const Page = model<IPage>("page", PageSchema);
105
+ // Compound indexes for common query patterns
106
+ PageSchema.index({ client: 1, name: 1 }, { unique: true });
107
+ PageSchema.index({ client: 1, isActive: 1 });
108
+ PageSchema.index({ organizationId: 1, client: 1 });
109
+ PageSchema.index({ organizationId: 1, name: 1 });
110
+
111
+ // Text index for full-text search
112
+ // PageSchema.index({
113
+ // name: 'text',
114
+ // trigger_js: 'text',
115
+ // rules_js: 'text'
116
+ // }, {
117
+ // weights: {
118
+ // name: 10,
119
+ // trigger_js: 5,
120
+ // rules_js: 5
121
+ // }
122
+ // });
123
+
124
+ const Page = mongoose.models.page || model<IPage>("page", PageSchema);
68
125
 
69
126
  export default Page;
@@ -1,8 +1,13 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
+ import slug from "mongoose-slug-updater"
3
+ mongoose.plugin(slug)
2
4
 
3
5
  export interface IPageElement extends Document {
4
6
  name: string;
5
7
  slug?: string;
8
+ organizationId?: mongoose.Schema.Types.ObjectId;
9
+ client?: mongoose.Schema.Types.ObjectId;
10
+ isActive?: boolean;
6
11
  createdAt?: Date;
7
12
  updatedAt?: Date;
8
13
  }
@@ -11,20 +16,46 @@ const PageElementSchema = new Schema<IPageElement>({
11
16
  name: {
12
17
  type: String,
13
18
  required: true,
19
+ trim: true,
20
+ index: true,
14
21
  },
15
22
  slug: {
16
- type: String,
23
+ type: String,
24
+ slug: ["name"],
25
+ slugPaddingSize: 4,
26
+ unique: true,
27
+ trim: true,
17
28
  },
18
- createdAt: {
19
- type: Date,
20
- default: new Date(),
29
+ organizationId: {
30
+ type: mongoose.Schema.Types.ObjectId,
31
+ ref: "organization",
32
+ index: true,
33
+ default: null,
21
34
  },
22
- updatedAt: {
23
- type: Date,
24
- default: new Date(),
35
+ client: {
36
+ type: mongoose.Schema.Types.ObjectId,
37
+ ref: "client",
38
+ required: true,
39
+ index: true,
25
40
  },
41
+ isActive: {
42
+ type: Boolean,
43
+ default: true,
44
+ index: true,
45
+ }
46
+ }, {
47
+ timestamps: true
26
48
  });
27
49
 
28
- const PageElement = model<IPageElement>("pageelement", PageElementSchema);
50
+ // Compound indexes for common query patterns
51
+ PageElementSchema.index({ client: 1, name: 1 }, { unique: true });
52
+ PageElementSchema.index({ client: 1, isActive: 1 });
53
+ PageElementSchema.index({ organizationId: 1, client: 1 });
54
+ PageElementSchema.index({ organizationId: 1, name: 1 });
55
+
56
+ // Text index for full-text search
57
+ PageElementSchema.index({ name: 'text' });
58
+
59
+ const PageElement = mongoose.models.pageelement || model<IPageElement>("pageelement", PageElementSchema);
29
60
 
30
61
  export default PageElement;
@@ -3,30 +3,47 @@ import mongoose, { Document, Schema, model } from "mongoose";
3
3
  export interface IPageTestType extends Document {
4
4
  name: string;
5
5
  details?: string;
6
+ isActive?: boolean;
6
7
  createdAt?: Date;
7
8
  updatedAt?: Date;
9
+ organizationId?: mongoose.Schema.Types.ObjectId;
8
10
  }
9
11
 
10
12
  const PageTestTypeSchema = new Schema<IPageTestType>({
13
+ organizationId: {
14
+ type: mongoose.Schema.Types.ObjectId,
15
+ ref: "organization",
16
+ default: null,
17
+ },
11
18
  name: {
12
19
  type: String,
13
20
  required: true,
14
21
  unique: true,
22
+ trim: true,
23
+ index: true,
15
24
  },
16
25
  details: {
17
26
  type: String,
18
27
  default: "",
28
+ trim: true,
19
29
  },
20
30
  createdAt: {
21
31
  type: Date,
22
32
  default: new Date(),
23
33
  },
24
- updatedAt: {
25
- type: Date,
26
- default: new Date(),
27
- },
34
+ isActive: {
35
+ type: Boolean,
36
+ default: true,
37
+ index: true,
38
+ }
39
+ }, {
40
+ timestamps: true
28
41
  });
29
42
 
30
- const PageTestType = model<IPageTestType>("pagetesttype", PageTestTypeSchema);
43
+ // Compound indexes for common query patterns
44
+ PageTestTypeSchema.index({ name: 1, isActive: 1 });
45
+
46
+
47
+ const PageTestType = mongoose.models.pagetesttype || model<IPageTestType>("pagetesttype", PageTestTypeSchema);
31
48
 
32
49
  export default PageTestType;
@@ -3,6 +3,7 @@ import mongoose, { Document, Schema, model } from "mongoose";
3
3
  export interface IPortfolio extends Document {
4
4
  portfoliokey: mongoose.Schema.Types.Mixed;
5
5
  portfolioData?: mongoose.Schema.Types.Mixed;
6
+ organizationId?: mongoose.Schema.Types.ObjectId;
6
7
  }
7
8
 
8
9
  const PortfolioSchema = new Schema<IPortfolio>(
@@ -15,12 +16,17 @@ const PortfolioSchema = new Schema<IPortfolio>(
15
16
  type: mongoose.Schema.Types.Mixed,
16
17
  default: null,
17
18
  },
19
+ organizationId: {
20
+ type: mongoose.Schema.Types.ObjectId,
21
+ ref: "organization",
22
+ default: null,
23
+ },
18
24
  },
19
25
  {
20
26
  timestamps: true,
21
27
  }
22
28
  );
23
29
 
24
- const Portfolio = model<IPortfolio>("portfolio", PortfolioSchema);
30
+ const Portfolio = mongoose.models.portfolio || model<IPortfolio>("portfolio", PortfolioSchema);
25
31
 
26
32
  export default Portfolio;
@@ -0,0 +1,68 @@
1
+ import mongoose, { Document, Schema, model } from "mongoose";
2
+
3
+ export interface IPrecalculationFilters extends Document {
4
+ title: string;
5
+ organizationId: mongoose.Schema.Types.ObjectId;
6
+ client: mongoose.Schema.Types.ObjectId;
7
+ filters: any;
8
+ otherFilters: any;
9
+ }
10
+
11
+ const PrecalculationFiltersSchema = new Schema<IPrecalculationFilters>({
12
+ title: {
13
+ type: String,
14
+ trim: true,
15
+ },
16
+ organizationId: {
17
+ type: mongoose.Schema.Types.ObjectId,
18
+ ref: "organization",
19
+ },
20
+ client: {
21
+ type: mongoose.Schema.Types.ObjectId,
22
+ ref: "client",
23
+ },
24
+ filters: {
25
+ type: Object,
26
+ required: true,
27
+ },
28
+ otherFilters: {
29
+ type: Object,
30
+ required: true,
31
+ },
32
+ }, {
33
+ timestamps: true
34
+ });
35
+
36
+ // Pre-save middleware to generate title from filters
37
+ // PrecalculationFiltersSchema.pre('save', function(next) {
38
+ // if (!this.title) {
39
+ // // Generate title from filters object
40
+ // const filterValues = Object.values(this.filters);
41
+ // const otherFilterValues = Object.values(this.otherFilters);
42
+
43
+ // // Combine all values and create a title
44
+ // const allValues = [...filterValues, ...otherFilterValues]
45
+ // .filter(value => value !== null && value !== undefined)
46
+ // .map(value => {
47
+ // if (typeof value === 'object') {
48
+ // return Object.values(value).join(' ');
49
+ // }
50
+ // return value.toString();
51
+ // })
52
+ // .join(' ');
53
+
54
+ // // Truncate if too long and add ellipsis
55
+ // this.title = allValues.length > 50
56
+ // ? allValues.substring(0, 47) + '...'
57
+ // : allValues;
58
+ // }
59
+ // next();
60
+ // });
61
+
62
+ PrecalculationFiltersSchema.index({ organizationId: 1, test: 1 });
63
+ PrecalculationFiltersSchema.index({ organizationId: 1, client: 1 });
64
+
65
+ // Check if model is already registered
66
+ const PrecalculationFilters = mongoose.models.precalculationfilter || model<IPrecalculationFilters>("precalculationfilter", PrecalculationFiltersSchema);
67
+
68
+ export default PrecalculationFilters;
@@ -1,7 +1,7 @@
1
1
  import mongoose, { Document, Schema, model } from "mongoose";
2
2
 
3
3
  export interface IQueryLog extends Document {
4
- organisationId?: string;
4
+ organizationId?: mongoose.Schema.Types.ObjectId;
5
5
  query: string;
6
6
  timeTaken: number;
7
7
  user?: mongoose.Schema.Types.ObjectId;
@@ -9,8 +9,9 @@ export interface IQueryLog extends Document {
9
9
 
10
10
  const QueryLogSchema = new Schema<IQueryLog>(
11
11
  {
12
- organisationId: {
13
- type: String,
12
+ organizationId: {
13
+ type: mongoose.Schema.Types.ObjectId,
14
+ ref: "organization",
14
15
  default: null,
15
16
  },
16
17
  query: {
@@ -29,6 +30,6 @@ const QueryLogSchema = new Schema<IQueryLog>(
29
30
  }
30
31
  );
31
32
 
32
- const QueryLog = model<IQueryLog>("querylog", QueryLogSchema);
33
+ const QueryLog = mongoose.models.querylog || model<IQueryLog>("querylog", QueryLogSchema);
33
34
 
34
35
  export default QueryLog;
@@ -4,10 +4,16 @@ export interface IReadNotification extends Document {
4
4
  notification?: mongoose.Schema.Types.ObjectId;
5
5
  user?: mongoose.Schema.Types.ObjectId;
6
6
  read?: boolean;
7
+ organizationId?: mongoose.Schema.Types.ObjectId;
7
8
  }
8
9
 
9
10
  const ReadNotificationSchema = new Schema<IReadNotification>(
10
11
  {
12
+ organizationId: {
13
+ type: mongoose.Schema.Types.ObjectId,
14
+ ref: "organization",
15
+ default: null,
16
+ },
11
17
  notification: {
12
18
  type: Schema.Types.ObjectId,
13
19
  ref: "notification",
@@ -26,7 +32,7 @@ const ReadNotificationSchema = new Schema<IReadNotification>(
26
32
  }
27
33
  );
28
34
 
29
- const ReadNotification = model<IReadNotification>(
35
+ const ReadNotification = mongoose.models.readnotification || model<IReadNotification>(
30
36
  "readnotification",
31
37
  ReadNotificationSchema
32
38
  );
@@ -15,78 +15,66 @@ export interface IReports extends Document {
15
15
  from?: Date;
16
16
  to?: Date;
17
17
  createdBy?: mongoose.Schema.Types.ObjectId;
18
- excludedFromCalculations?: Boolean;
18
+ excludedFromCalculations?: boolean;
19
19
  createdAt?: Date;
20
20
  updatedAt?: Date;
21
+ organizationId?: mongoose.Schema.Types.ObjectId;
21
22
  }
22
23
 
23
- const ReportsSchema = new Schema<IReports>({
24
- name: {
25
- type: String,
26
- required: true,
27
- },
28
- segmentName: {
29
- type: String,
30
- },
31
- reportLink: {
32
- type: String,
33
- },
34
- conclusion: {
35
- type: String,
36
- },
37
- variant: {
38
- type: String,
39
- },
40
- client: {
41
- type: mongoose.Schema.Types.ObjectId,
42
- ref: "client",
43
- },
44
- viewId: {
45
- type: String,
46
- },
47
- test: {
48
- type: mongoose.Schema.Types.ObjectId,
49
- ref: "test",
50
- },
51
- gaTestId: {
52
- type: String,
53
- },
54
- reportDetails: {
55
- type: mongoose.Schema.Types.Mixed,
56
- },
57
- learnings: {
58
- type: mongoose.Schema.Types.Mixed,
59
- default: [],
60
- },
61
- from: {
62
- type: Date,
63
- },
64
- to: {
65
- type: Date,
66
- },
67
- createdBy: {
68
- type: mongoose.Schema.Types.ObjectId,
69
- ref: "user",
70
- },
71
- excludedFromCalculations: {
72
- type: Boolean,
73
- default: false
74
- },
75
- createdAt: {
76
- type: Date,
77
- default: new Date(),
78
- },
79
- updatedAt: {
80
- type: Date,
81
- default: new Date(),
82
- },
83
- });
24
+ const ReportsSchema = new Schema<IReports>(
25
+ {
26
+ organizationId: {
27
+ type: mongoose.Schema.Types.ObjectId,
28
+ ref: "organization",
29
+ default: null,
30
+ },
31
+ name: { type: String, required: true },
32
+ segmentName: { type: String },
33
+ reportLink: { type: String },
34
+ conclusion: { type: String },
35
+ variant: { type: String },
36
+ client: {
37
+ type: mongoose.Schema.Types.ObjectId,
38
+ ref: "client"
39
+ },
40
+ viewId: { type: String },
41
+ test: {
42
+ type: mongoose.Schema.Types.ObjectId,
43
+ ref: "test"
44
+ },
45
+ gaTestId: { type: String },
46
+ reportDetails: { type: mongoose.Schema.Types.Mixed },
47
+ learnings: {
48
+ type: mongoose.Schema.Types.Mixed,
49
+ default: []
50
+ },
51
+ from: { type: Date },
52
+ to: { type: Date },
53
+ createdBy: {
54
+ type: mongoose.Schema.Types.ObjectId,
55
+ ref: "user"
56
+ },
57
+ excludedFromCalculations: {
58
+ type: Boolean,
59
+ default: false
60
+ }
61
+ },
62
+ {
63
+ timestamps: true
64
+ }
65
+ );
84
66
 
85
- ReportsSchema.index({
86
- client: 1,
87
- conclusion: 1,
88
- });
67
+ // Add compound indexes for better query performance
68
+ ReportsSchema.index({ client: 1, conclusion: 1 });
69
+ ReportsSchema.index({ test: 1, to: -1 }); // For sorting reports by date
70
+ ReportsSchema.index({ client: 1, test: 1 }); // For client-specific test reports
71
+ ReportsSchema.index({ from: 1, to: 1 }); // For date range queries
72
+ ReportsSchema.index({ client: 1, "reportDetails.implementedStatus": 1 }); // For implemented status queries
73
+ ReportsSchema.index({ client: 1, "reportDetails.conclusionFactorStatusAll": 1 }); // For conclusion factor queries
74
+ ReportsSchema.index({ client: 1, gaTestId: 1 }); // For GA test ID lookups
75
+ ReportsSchema.index({ createdBy: 1, to: -1 }); // For user's reports
76
+ ReportsSchema.index({ client: 1, excludedFromCalculations: 1 }); // For calculation exclusions
89
77
 
90
- const Report = model<IReports>("report", ReportsSchema);
78
+ const Report = mongoose.models.report || model<IReports>("report", ReportsSchema);
91
79
 
92
80
  export default Report;
@@ -2,6 +2,9 @@ import mongoose, { Document, Schema, model } from "mongoose";
2
2
 
3
3
  export interface IRole extends Document {
4
4
  name: string;
5
+ description?: string;
6
+ organizationId?: mongoose.Schema.Types.ObjectId;
7
+ isActive?: boolean;
5
8
  createdAt?: Date;
6
9
  updatedAt?: Date;
7
10
  }
@@ -12,17 +15,39 @@ const RoleSchema = new Schema<IRole>({
12
15
  unique: true,
13
16
  required: true,
14
17
  enum: ["USER", "ADMIN", "EDITOR", "COLLABORATOR", "CLIENT"],
18
+ trim: true,
19
+ index: true,
20
+ uppercase: true,
15
21
  },
16
- createdAt: {
17
- type: Date,
18
- default: new Date(),
22
+ description: {
23
+ type: String,
24
+ trim: true,
19
25
  },
20
- updatedAt: {
21
- type: Date,
22
- default: new Date(),
26
+ organizationId: {
27
+ type: mongoose.Schema.Types.ObjectId,
28
+ ref: "organization",
29
+ index: true,
30
+ default: null,
23
31
  },
32
+ isActive: {
33
+ type: Boolean,
34
+ default: true,
35
+ index: true,
36
+ }
37
+ }, {
38
+ timestamps: true
39
+ });
40
+
41
+ // Compound indexes for common query patterns
42
+ RoleSchema.index({ name: 1, isActive: 1 });
43
+ RoleSchema.index({ organizationId: 1, name: 1 });
44
+
45
+ // Add text index for search
46
+ RoleSchema.index({
47
+ name: 'text',
48
+ description: 'text'
24
49
  });
25
50
 
26
- const Role = model<IRole>("role", RoleSchema);
51
+ const Role = mongoose.models.role || model<IRole>("role", RoleSchema);
27
52
 
28
53
  export default Role;