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.
- package/.github/workflows/npm-publish.yml +33 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +7 -5
- package/dist/src/models/Announcement.d.ts +7 -8
- package/dist/src/models/Announcement.js +30 -10
- package/dist/src/models/AppEvent.d.ts +1 -3
- package/dist/src/models/AppEvent.js +1 -1
- package/dist/src/models/Audience.d.ts +2 -3
- package/dist/src/models/Audience.js +6 -1
- package/dist/src/models/{Experiments.d.ts → BqPreCompiledData.d.ts} +12 -32
- package/dist/src/models/{ClientExperiment.js → BqPreCompiledData.js} +26 -46
- package/dist/src/models/CVRReport.d.ts +2 -3
- package/dist/src/models/CVRReport.js +14 -1
- package/dist/src/models/Client.d.ts +2 -4
- package/dist/src/models/Client.js +32 -52
- package/dist/src/models/ClientAdditionalRevenue.d.ts +2 -4
- package/dist/src/models/ClientAdditionalRevenue.js +4 -3
- package/dist/src/models/ClientLearning.d.ts +2 -4
- package/dist/src/models/ClientLearning.js +11 -7
- package/dist/src/models/ClientLinks.d.ts +2 -4
- package/dist/src/models/ClientLinks.js +16 -7
- package/dist/src/models/ClientNextSteps.d.ts +2 -4
- package/dist/src/models/ClientNextSteps.js +4 -3
- package/dist/src/models/ClientNote.d.ts +2 -4
- package/dist/src/models/ClientNote.js +4 -3
- package/dist/src/models/ClientReportsTemp.d.ts +2 -4
- package/dist/src/models/ClientReportsTemp.js +21 -3
- package/dist/src/models/ClientRetention.d.ts +2 -3
- package/dist/src/models/ClientRetention.js +19 -1
- package/dist/src/models/ClientScript.d.ts +2 -4
- package/dist/src/models/ClientScript.js +25 -9
- package/dist/src/models/ClientStrategy.d.ts +2 -4
- package/dist/src/models/ClientStrategy.js +4 -3
- package/dist/src/models/ClientSurvay.d.ts +2 -7
- package/dist/src/models/ClientSurvay.js +6 -1
- package/dist/src/models/Environment.d.ts +3 -3
- package/dist/src/models/Environment.js +27 -3
- package/dist/src/models/Faqs.d.ts +2 -3
- package/dist/src/models/Faqs.js +6 -1
- package/dist/src/models/Feedback.d.ts +2 -4
- package/dist/src/models/Feedback.js +4 -3
- package/dist/src/models/Goal.d.ts +3 -4
- package/dist/src/models/Goal.js +34 -12
- package/dist/src/models/Hypothesis.d.ts +3 -3
- package/dist/src/models/Hypothesis.js +50 -10
- package/dist/src/models/HypothesisSheet.d.ts +2 -4
- package/dist/src/models/HypothesisSheet.js +27 -3
- package/dist/src/models/LandingPages.d.ts +4 -3
- package/dist/src/models/LandingPages.js +30 -1
- package/dist/src/models/NewIdeas.d.ts +2 -4
- package/dist/src/models/NewIdeas.js +4 -3
- package/dist/src/models/Notification.d.ts +2 -3
- package/dist/src/models/Notification.js +30 -2
- package/dist/src/models/{ClientExperiment.d.ts → Organization.d.ts} +18 -31
- package/dist/src/models/{Experiments.js → Organization.js} +36 -54
- package/dist/src/models/Page.d.ts +4 -4
- package/dist/src/models/Page.js +57 -5
- package/dist/src/models/PageElement.d.ts +4 -3
- package/dist/src/models/PageElement.js +60 -8
- package/dist/src/models/PageTestType.d.ts +3 -3
- package/dist/src/models/PageTestType.js +42 -6
- package/dist/src/models/Portfolio.d.ts +2 -3
- package/dist/src/models/Portfolio.js +6 -1
- package/dist/src/models/PrecalculationFilters.d.ts +34 -0
- package/dist/src/models/PrecalculationFilters.js +78 -0
- package/dist/src/models/QueryLog.d.ts +2 -4
- package/dist/src/models/QueryLog.js +4 -3
- package/dist/src/models/ReadNotification.d.ts +2 -3
- package/dist/src/models/ReadNotification.js +30 -2
- package/dist/src/models/Report.d.ts +3 -4
- package/dist/src/models/Report.js +33 -49
- package/dist/src/models/Role.d.ts +4 -3
- package/dist/src/models/Role.js +51 -8
- package/dist/src/models/SavedSegment.d.ts +2 -3
- package/dist/src/models/SavedSegment.js +6 -1
- package/dist/src/models/Segment.d.ts +2 -3
- package/dist/src/models/Segment.js +6 -1
- package/dist/src/models/SegmentCombination.d.ts +2 -3
- package/dist/src/models/SegmentCombination.js +6 -1
- package/dist/src/models/Snippet.d.ts +3 -4
- package/dist/src/models/Snippet.js +29 -4
- package/dist/src/models/StageInCustomerJourney.d.ts +4 -4
- package/dist/src/models/StageInCustomerJourney.js +56 -4
- package/dist/src/models/Tag.d.ts +2 -3
- package/dist/src/models/Tag.js +30 -2
- package/dist/src/models/Temp.d.ts +2 -3
- package/dist/src/models/Temp.js +30 -2
- package/dist/src/models/Test.d.ts +17 -18
- package/dist/src/models/Test.js +83 -186
- package/dist/src/models/TestSequentialValue.d.ts +2 -3
- package/dist/src/models/TestSequentialValue.js +6 -1
- package/dist/src/models/Tier.d.ts +2 -3
- package/dist/src/models/Tier.js +30 -2
- package/dist/src/models/Trigger.d.ts +2 -3
- package/dist/src/models/Trigger.js +30 -2
- package/dist/src/models/User.d.ts +2 -3
- package/dist/src/models/User.js +10 -11
- package/index.ts +6 -4
- package/package.json +1 -1
- package/src/models/Announcement.ts +51 -28
- package/src/models/AppEvent.ts +1 -1
- package/src/models/Audience.ts +7 -1
- package/src/models/BqPreCompiledData.ts +62 -0
- package/src/models/CVRReport.ts +18 -1
- package/src/models/Client.ts +40 -60
- package/src/models/ClientAdditionalRevenue.ts +5 -4
- package/src/models/ClientLearning.ts +12 -8
- package/src/models/ClientLinks.ts +19 -8
- package/src/models/ClientNextSteps.ts +5 -4
- package/src/models/ClientNote.ts +5 -4
- package/src/models/ClientReportsTemp.ts +25 -4
- package/src/models/ClientRetention.ts +28 -2
- package/src/models/ClientScript.ts +27 -10
- package/src/models/ClientStrategy.ts +5 -4
- package/src/models/ClientSurvay.ts +7 -1
- package/src/models/Environment.ts +32 -4
- package/src/models/Faqs.ts +7 -1
- package/src/models/Feedback.ts +5 -4
- package/src/models/Goal.ts +37 -13
- package/src/models/Hypothesis.ts +30 -9
- package/src/models/HypothesisSheet.ts +4 -3
- package/src/models/LandingPages.ts +35 -1
- package/src/models/NewIdeas.ts +5 -4
- package/src/models/Notification.ts +7 -1
- package/src/models/Organization.ts +86 -0
- package/src/models/Page.ts +63 -6
- package/src/models/PageElement.ts +39 -8
- package/src/models/PageTestType.ts +22 -5
- package/src/models/Portfolio.ts +7 -1
- package/src/models/PrecalculationFilters.ts +68 -0
- package/src/models/QueryLog.ts +5 -4
- package/src/models/ReadNotification.ts +7 -1
- package/src/models/Report.ts +55 -67
- package/src/models/Role.ts +32 -7
- package/src/models/SavedSegment.ts +7 -1
- package/src/models/Segment.ts +7 -1
- package/src/models/SegmentCombination.ts +7 -1
- package/src/models/Snippet.ts +33 -5
- package/src/models/StageInCustomerJourney.ts +34 -6
- package/src/models/Tag.ts +7 -1
- package/src/models/Temp.ts +7 -1
- package/src/models/Test.ts +156 -244
- package/src/models/TestSequentialValue.ts +7 -1
- package/src/models/Tier.ts +7 -1
- package/src/models/Trigger.ts +7 -1
- package/src/models/User.ts +12 -11
- package/src/models/ClientExperiment.ts +0 -113
- package/src/models/Experiments.ts +0 -118
package/src/models/Audience.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface IAudience extends Document {
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
4
5
|
name: string;
|
|
5
6
|
rules_js?: string;
|
|
6
7
|
client?: mongoose.Schema.Types.ObjectId;
|
|
@@ -8,6 +9,11 @@ export interface IAudience extends Document {
|
|
|
8
9
|
|
|
9
10
|
const AudienceSchema = new Schema<IAudience>(
|
|
10
11
|
{
|
|
12
|
+
organizationId: {
|
|
13
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
14
|
+
ref: "organization",
|
|
15
|
+
default: null,
|
|
16
|
+
},
|
|
11
17
|
name: {
|
|
12
18
|
type: String,
|
|
13
19
|
required: true,
|
|
@@ -25,6 +31,6 @@ const AudienceSchema = new Schema<IAudience>(
|
|
|
25
31
|
}
|
|
26
32
|
);
|
|
27
33
|
|
|
28
|
-
const Audience = model<IAudience>("audience", AudienceSchema);
|
|
34
|
+
const Audience = mongoose.models.audience || model<IAudience>("audience", AudienceSchema);
|
|
29
35
|
|
|
30
36
|
export default Audience;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
|
|
3
|
+
export interface IBqPreCompiledData extends Document {
|
|
4
|
+
title: string;
|
|
5
|
+
organizationId: mongoose.Schema.Types.ObjectId;
|
|
6
|
+
client: mongoose.Schema.Types.ObjectId;
|
|
7
|
+
test: mongoose.Schema.Types.ObjectId;
|
|
8
|
+
from: Date;
|
|
9
|
+
to: Date;
|
|
10
|
+
filters: any;
|
|
11
|
+
otherFilters: any;
|
|
12
|
+
cloudurl: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const BqPreCompiledDataSchema = new Schema<IBqPreCompiledData>({
|
|
16
|
+
title: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: null,
|
|
19
|
+
},
|
|
20
|
+
organizationId: {
|
|
21
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
22
|
+
ref: "organization",
|
|
23
|
+
default: null,
|
|
24
|
+
},
|
|
25
|
+
client: {
|
|
26
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
27
|
+
ref: "client",
|
|
28
|
+
default: null,
|
|
29
|
+
},
|
|
30
|
+
test: {
|
|
31
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
32
|
+
ref: "test",
|
|
33
|
+
default: null,
|
|
34
|
+
},
|
|
35
|
+
from: {
|
|
36
|
+
type: Date,
|
|
37
|
+
default: null,
|
|
38
|
+
},
|
|
39
|
+
filters: {
|
|
40
|
+
type: Object,
|
|
41
|
+
default: null,
|
|
42
|
+
},
|
|
43
|
+
to: {
|
|
44
|
+
type: Date,
|
|
45
|
+
default: null,
|
|
46
|
+
},
|
|
47
|
+
otherFilters: {
|
|
48
|
+
type: Object,
|
|
49
|
+
default: null,
|
|
50
|
+
},
|
|
51
|
+
cloudurl: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: null,
|
|
54
|
+
},
|
|
55
|
+
}, {
|
|
56
|
+
timestamps: true
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
BqPreCompiledDataSchema.index({ organizationId: 1, client: 1 });
|
|
60
|
+
const BqPreCompiledData = mongoose.models.bqprecompileddata || model<IBqPreCompiledData>("bqprecompileddata", BqPreCompiledDataSchema);
|
|
61
|
+
|
|
62
|
+
export default BqPreCompiledData;
|
package/src/models/CVRReport.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface ICVRReport extends Document {
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
4
5
|
reportLink?: string;
|
|
5
6
|
client?: mongoose.Schema.Types.ObjectId;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
const CVRReportSchema = new Schema<ICVRReport>(
|
|
9
10
|
{
|
|
11
|
+
organizationId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: "organization",
|
|
14
|
+
default: null,
|
|
15
|
+
},
|
|
10
16
|
reportLink: {
|
|
11
17
|
type: String,
|
|
12
18
|
default: null,
|
|
19
|
+
trim: true,
|
|
13
20
|
},
|
|
14
21
|
client: {
|
|
15
22
|
type: mongoose.Schema.Types.ObjectId,
|
|
16
23
|
ref: "client",
|
|
24
|
+
index: true,
|
|
17
25
|
},
|
|
18
26
|
},
|
|
19
27
|
{
|
|
@@ -21,5 +29,14 @@ const CVRReportSchema = new Schema<ICVRReport>(
|
|
|
21
29
|
}
|
|
22
30
|
);
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
// Compound index for client and reportLink
|
|
33
|
+
CVRReportSchema.index({ client: 1 });
|
|
34
|
+
|
|
35
|
+
// Sparse index for reportLink
|
|
36
|
+
CVRReportSchema.index({ reportLink: 1 }, { sparse: true });
|
|
37
|
+
|
|
38
|
+
// TTL index for automatic cleanup of old reports (1 year)
|
|
39
|
+
CVRReportSchema.index({ createdAt: 1 }, { expireAfterSeconds: 31536000 });
|
|
40
|
+
|
|
41
|
+
const CVRReport = mongoose.models.cvrreport || model<ICVRReport>("cvrreport", CVRReportSchema);
|
|
25
42
|
export default CVRReport;
|
package/src/models/Client.ts
CHANGED
|
@@ -12,11 +12,11 @@ export interface IProperty extends Document {
|
|
|
12
12
|
const PropertySchema: Schema = new Schema<IProperty>({
|
|
13
13
|
propertyname: { type: String, required: true },
|
|
14
14
|
viewId: { type: String, required: true },
|
|
15
|
-
platform: { type: String,
|
|
15
|
+
platform: { type: String, default: "GA4" }
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export interface IClient extends Document {
|
|
19
|
-
|
|
19
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
20
20
|
name: string;
|
|
21
21
|
slug?: string;
|
|
22
22
|
viewId?: string;
|
|
@@ -37,72 +37,52 @@ export interface IClient extends Document {
|
|
|
37
37
|
|
|
38
38
|
const ClientSchema: Schema = new Schema<IClient>(
|
|
39
39
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
default: null,
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
type: String,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
viewId: {
|
|
50
|
-
type: String,
|
|
51
|
-
},
|
|
52
|
-
portfolioClient: {
|
|
53
|
-
type: Boolean,
|
|
54
|
-
default: false,
|
|
40
|
+
organizationId: { type: mongoose.Schema.Types.ObjectId,
|
|
41
|
+
ref: "organization",
|
|
42
|
+
default: null },
|
|
43
|
+
name: { type: String, required: true },
|
|
44
|
+
slug: {
|
|
45
|
+
type: String,
|
|
46
|
+
slug: ["name"],
|
|
47
|
+
slugPaddingSize: 4,
|
|
48
|
+
unique: true
|
|
55
49
|
},
|
|
50
|
+
viewId: { type: String },
|
|
51
|
+
portfolioClient: { type: Boolean, default: false },
|
|
56
52
|
gaproperties: [PropertySchema],
|
|
57
|
-
tier: {
|
|
58
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
59
|
-
ref: "tier",
|
|
60
|
-
default: null
|
|
61
|
-
},
|
|
62
|
-
active: {
|
|
63
|
-
type: Boolean,
|
|
64
|
-
default: true,
|
|
65
|
-
},
|
|
66
|
-
currency: {
|
|
67
|
-
type: String,
|
|
68
|
-
default: "USD",
|
|
69
|
-
},
|
|
70
|
-
logo: {
|
|
71
|
-
type: String,
|
|
72
|
-
default: "",
|
|
73
|
-
},
|
|
74
|
-
createdBy: {
|
|
75
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
76
|
-
ref: "user",
|
|
77
|
-
default: null,
|
|
78
|
-
},
|
|
79
|
-
onboardDate: {
|
|
80
|
-
type: Date,
|
|
81
|
-
default: new Date(),
|
|
82
|
-
},
|
|
83
|
-
bqClientId: {
|
|
84
|
-
type: String,
|
|
85
|
-
default: null,
|
|
86
|
-
},
|
|
87
|
-
defaultDataSet: {
|
|
88
|
-
type: String,
|
|
89
|
-
},
|
|
90
|
-
NDAStatus: {
|
|
91
|
-
type: Boolean,
|
|
92
|
-
default: false,
|
|
93
|
-
},
|
|
94
|
-
retainerValue: {
|
|
95
|
-
type: Number,
|
|
53
|
+
tier: {
|
|
54
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
55
|
+
ref: "tier",
|
|
56
|
+
default: null
|
|
96
57
|
},
|
|
97
|
-
|
|
98
|
-
|
|
58
|
+
active: { type: Boolean, default: true },
|
|
59
|
+
currency: { type: String, default: "USD" },
|
|
60
|
+
logo: { type: String, default: "" },
|
|
61
|
+
createdBy: {
|
|
62
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
63
|
+
ref: "user",
|
|
64
|
+
default: null
|
|
99
65
|
},
|
|
66
|
+
onboardDate: { type: Date, default: Date.now },
|
|
67
|
+
bqClientId: { type: String, default: null },
|
|
68
|
+
defaultDataSet: { type: String },
|
|
69
|
+
NDAStatus: { type: Boolean, default: false },
|
|
70
|
+
retainerValue: { type: Number },
|
|
71
|
+
useIntraDayTable: { type: Boolean }
|
|
100
72
|
},
|
|
101
|
-
{
|
|
73
|
+
{
|
|
74
|
+
timestamps: true
|
|
75
|
+
}
|
|
102
76
|
);
|
|
103
77
|
|
|
78
|
+
// Add compound indexes for better query performance
|
|
104
79
|
ClientSchema.index({ active: 1 });
|
|
80
|
+
ClientSchema.index({ organizationId: 1, active: 1 });
|
|
81
|
+
ClientSchema.index({ name: 1 }, { collation: { locale: 'en', strength: 2 } }); // Case-insensitive search
|
|
82
|
+
ClientSchema.index({ tier: 1, active: 1 }); // For tier-based queries
|
|
83
|
+
ClientSchema.index({ onboardDate: 1 }); // For date-based queries
|
|
84
|
+
ClientSchema.index({ portfolioClient: 1, active: 1 }); // For portfolio client queries
|
|
105
85
|
|
|
106
|
-
const Client = model<IClient>("client", ClientSchema);
|
|
86
|
+
const Client = mongoose.models.client || model<IClient>("client", ClientSchema);
|
|
107
87
|
|
|
108
88
|
export default Client;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface IClientAdditionalRevenue extends Document {
|
|
4
|
-
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
5
|
client?: mongoose.Schema.Types.ObjectId;
|
|
6
6
|
additionalRevenueForTests: IAdditionalRevenue;
|
|
7
7
|
createdBy?: mongoose.Schema.Types.ObjectId;
|
|
@@ -36,8 +36,9 @@ const AdditionalRevenueSchema = new Schema<IAdditionalRevenue>({
|
|
|
36
36
|
|
|
37
37
|
const ClientAdditionalRevenueSchema = new Schema<IClientAdditionalRevenue>(
|
|
38
38
|
{
|
|
39
|
-
|
|
40
|
-
type:
|
|
39
|
+
organizationId: {
|
|
40
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
41
|
+
ref: "organization",
|
|
41
42
|
default: null,
|
|
42
43
|
},
|
|
43
44
|
client: {
|
|
@@ -60,7 +61,7 @@ ClientAdditionalRevenueSchema.index({
|
|
|
60
61
|
client: 1,
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
const ClientAdditionalRevenue = model<IClientAdditionalRevenue>(
|
|
64
|
+
const ClientAdditionalRevenue = mongoose.models.clientadditionalrevenue || model<IClientAdditionalRevenue>(
|
|
64
65
|
"clientadditionalrevenue",
|
|
65
66
|
ClientAdditionalRevenueSchema
|
|
66
67
|
);
|
|
@@ -2,7 +2,7 @@ import mongoose, { Document, Schema, model } from "mongoose";
|
|
|
2
2
|
|
|
3
3
|
export interface IClientLearning extends Document {
|
|
4
4
|
name: string;
|
|
5
|
-
|
|
5
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
6
6
|
client?: mongoose.Schema.Types.ObjectId;
|
|
7
7
|
viewId?: string;
|
|
8
8
|
createdBy?: mongoose.Schema.Types.ObjectId;
|
|
@@ -13,9 +13,11 @@ const ClientLearningSchema = new Schema<IClientLearning>(
|
|
|
13
13
|
name: {
|
|
14
14
|
type: String,
|
|
15
15
|
required: true,
|
|
16
|
+
trim: true,
|
|
16
17
|
},
|
|
17
|
-
|
|
18
|
-
type:
|
|
18
|
+
organizationId: {
|
|
19
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
20
|
+
ref: "organization",
|
|
19
21
|
default: null,
|
|
20
22
|
},
|
|
21
23
|
client: {
|
|
@@ -35,12 +37,14 @@ const ClientLearningSchema = new Schema<IClientLearning>(
|
|
|
35
37
|
}
|
|
36
38
|
);
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
40
|
+
// Compound indexes for common query patterns
|
|
41
|
+
ClientLearningSchema.index({ client: 1 });
|
|
42
|
+
// Sparse indexes for optional fields
|
|
43
|
+
ClientLearningSchema.index({ organisationId: 1 }, { sparse: true });
|
|
44
|
+
// Case-insensitive index for name
|
|
45
|
+
ClientLearningSchema.index({ name: 1 }, { collation: { locale: 'en', strength: 2 } });
|
|
42
46
|
|
|
43
|
-
const ClientLearning = model<IClientLearning>(
|
|
47
|
+
const ClientLearning = mongoose.models.clientlearning || model<IClientLearning>(
|
|
44
48
|
"clientlearning",
|
|
45
49
|
ClientLearningSchema
|
|
46
50
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface IClientLinks extends Document {
|
|
4
|
-
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
5
|
title: string;
|
|
6
6
|
description?: string;
|
|
7
7
|
link?: string;
|
|
@@ -13,20 +13,24 @@ export interface IClientLinks extends Document {
|
|
|
13
13
|
|
|
14
14
|
const ClientLinksSchema = new Schema<IClientLinks>(
|
|
15
15
|
{
|
|
16
|
-
|
|
17
|
-
type:
|
|
16
|
+
organizationId: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
ref: "organization",
|
|
18
19
|
default: null,
|
|
19
20
|
},
|
|
20
21
|
title: {
|
|
21
22
|
type: String,
|
|
22
23
|
required: true,
|
|
24
|
+
trim: true,
|
|
23
25
|
},
|
|
24
26
|
description: {
|
|
25
27
|
type: String,
|
|
28
|
+
trim: true,
|
|
26
29
|
},
|
|
27
30
|
link: {
|
|
28
31
|
type: String,
|
|
29
32
|
required: true,
|
|
33
|
+
trim: true,
|
|
30
34
|
},
|
|
31
35
|
client: {
|
|
32
36
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -49,10 +53,17 @@ const ClientLinksSchema = new Schema<IClientLinks>(
|
|
|
49
53
|
}
|
|
50
54
|
);
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
+
// Compound indexes for common query patterns
|
|
57
|
+
ClientLinksSchema.index({ client: 1 });
|
|
58
|
+
ClientLinksSchema.index({ client: 1, private: 1 });
|
|
59
|
+
ClientLinksSchema.index({ client: 1, createdAt: -1 });
|
|
60
|
+
|
|
61
|
+
// Sparse indexes for optional fields
|
|
62
|
+
ClientLinksSchema.index({ viewId: 1 }, { sparse: true });
|
|
63
|
+
ClientLinksSchema.index({ organisationId: 1 }, { sparse: true });
|
|
64
|
+
|
|
65
|
+
// Case-insensitive indexes
|
|
66
|
+
ClientLinksSchema.index({ title: 1 }, { collation: { locale: 'en', strength: 2 } });
|
|
56
67
|
|
|
57
|
-
const ClientLinks = model<IClientLinks>("clientlink", ClientLinksSchema);
|
|
68
|
+
const ClientLinks = mongoose.models.clientlink || model<IClientLinks>("clientlink", ClientLinksSchema);
|
|
58
69
|
export default ClientLinks;
|
|
@@ -2,7 +2,7 @@ import mongoose, { Document, Schema, model } from "mongoose";
|
|
|
2
2
|
|
|
3
3
|
export interface IClientNextSteps extends Document {
|
|
4
4
|
name: string;
|
|
5
|
-
|
|
5
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
6
6
|
client?: mongoose.Schema.Types.ObjectId;
|
|
7
7
|
viewId?: string;
|
|
8
8
|
createdBy?: mongoose.Schema.Types.ObjectId;
|
|
@@ -14,8 +14,9 @@ const ClientNextStepsSchema = new Schema<IClientNextSteps>(
|
|
|
14
14
|
type: String,
|
|
15
15
|
required: true,
|
|
16
16
|
},
|
|
17
|
-
|
|
18
|
-
type:
|
|
17
|
+
organizationId: {
|
|
18
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
19
|
+
ref: "organization",
|
|
19
20
|
default: null,
|
|
20
21
|
},
|
|
21
22
|
client: {
|
|
@@ -40,7 +41,7 @@ ClientNextStepsSchema.index({
|
|
|
40
41
|
viewId: 1,
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
const ClientNextStep = model<IClientNextSteps>(
|
|
44
|
+
const ClientNextStep = mongoose.models.clientnextstep || model<IClientNextSteps>(
|
|
44
45
|
"clientnextstep",
|
|
45
46
|
ClientNextStepsSchema
|
|
46
47
|
);
|
package/src/models/ClientNote.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface IClientNote extends Document {
|
|
4
|
-
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
5
|
client?: mongoose.Schema.Types.ObjectId;
|
|
6
6
|
viewId?: string;
|
|
7
7
|
pageType?: mongoose.Schema.Types.ObjectId;
|
|
@@ -14,8 +14,9 @@ export interface IClientNote extends Document {
|
|
|
14
14
|
|
|
15
15
|
const ClientNoteSchema = new Schema<IClientNote>(
|
|
16
16
|
{
|
|
17
|
-
|
|
18
|
-
type:
|
|
17
|
+
organizationId: {
|
|
18
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
19
|
+
ref: "organization",
|
|
19
20
|
default: null,
|
|
20
21
|
},
|
|
21
22
|
client: {
|
|
@@ -57,5 +58,5 @@ ClientNoteSchema.index({
|
|
|
57
58
|
viewId: 1,
|
|
58
59
|
});
|
|
59
60
|
|
|
60
|
-
const ClientNote = model<IClientNote>("clientnote", ClientNoteSchema);
|
|
61
|
+
const ClientNote = mongoose.models.clientnote || model<IClientNote>("clientnote", ClientNoteSchema);
|
|
61
62
|
export default ClientNote;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface IClientReportsTemp extends Document {
|
|
4
|
-
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
5
|
client?: mongoose.Schema.Types.ObjectId;
|
|
6
6
|
viewId?: string;
|
|
7
7
|
test?: mongoose.Schema.Types.ObjectId;
|
|
@@ -15,8 +15,9 @@ export interface IClientReportsTemp extends Document {
|
|
|
15
15
|
|
|
16
16
|
const ClientReportsTempSchema = new Schema<IClientReportsTemp>(
|
|
17
17
|
{
|
|
18
|
-
|
|
19
|
-
type:
|
|
18
|
+
organizationId: {
|
|
19
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
20
|
+
ref: "organization",
|
|
20
21
|
default: null,
|
|
21
22
|
},
|
|
22
23
|
client: {
|
|
@@ -32,12 +33,15 @@ const ClientReportsTempSchema = new Schema<IClientReportsTemp>(
|
|
|
32
33
|
},
|
|
33
34
|
filters: {
|
|
34
35
|
type: String,
|
|
36
|
+
trim: true,
|
|
35
37
|
},
|
|
36
38
|
metricsFilters: {
|
|
37
39
|
type: String,
|
|
40
|
+
trim: true,
|
|
38
41
|
},
|
|
39
42
|
date: {
|
|
40
43
|
type: Date,
|
|
44
|
+
index: true,
|
|
41
45
|
},
|
|
42
46
|
report: {
|
|
43
47
|
type: mongoose.Schema.Types.Mixed,
|
|
@@ -45,6 +49,7 @@ const ClientReportsTempSchema = new Schema<IClientReportsTemp>(
|
|
|
45
49
|
deactivated: {
|
|
46
50
|
type: Boolean,
|
|
47
51
|
default: false,
|
|
52
|
+
index: true,
|
|
48
53
|
},
|
|
49
54
|
createdBy: {
|
|
50
55
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -56,7 +61,23 @@ const ClientReportsTempSchema = new Schema<IClientReportsTemp>(
|
|
|
56
61
|
}
|
|
57
62
|
);
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
// Compound indexes for common query patterns
|
|
65
|
+
ClientReportsTempSchema.index({ client: 1 });
|
|
66
|
+
ClientReportsTempSchema.index({ client: 1, test: 1 });
|
|
67
|
+
ClientReportsTempSchema.index({ client: 1, deactivated: 1 });
|
|
68
|
+
ClientReportsTempSchema.index({ client: 1, date: -1 });
|
|
69
|
+
ClientReportsTempSchema.index({ createdBy: 1, date: -1 });
|
|
70
|
+
ClientReportsTempSchema.index({ organisationId: 1, client: 1 });
|
|
71
|
+
|
|
72
|
+
// Sparse indexes for optional fields
|
|
73
|
+
ClientReportsTempSchema.index({ viewId: 1 }, { sparse: true });
|
|
74
|
+
ClientReportsTempSchema.index({ organisationId: 1 }, { sparse: true });
|
|
75
|
+
ClientReportsTempSchema.index({ test: 1 }, { sparse: true });
|
|
76
|
+
|
|
77
|
+
// TTL index for automatic cleanup of old reports
|
|
78
|
+
ClientReportsTempSchema.index({ date: 1 }, { expireAfterSeconds: 86400 }); // 24 hours
|
|
79
|
+
|
|
80
|
+
const ClientReportsTemp = mongoose.models.clientreportstemp || model<IClientReportsTemp>(
|
|
60
81
|
"clientreportstemp",
|
|
61
82
|
ClientReportsTempSchema
|
|
62
83
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
2
|
|
|
3
3
|
export interface IClientRetention extends Document {
|
|
4
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
4
5
|
client?: mongoose.Schema.Types.ObjectId;
|
|
5
6
|
viewId?: string;
|
|
6
7
|
year: Number;
|
|
@@ -16,10 +17,16 @@ export interface IClientRetention extends Document {
|
|
|
16
17
|
|
|
17
18
|
const ClientRetentionSchema = new Schema<IClientRetention>(
|
|
18
19
|
{
|
|
20
|
+
organizationId: {
|
|
21
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
22
|
+
ref: "organization",
|
|
23
|
+
default: null,
|
|
24
|
+
},
|
|
19
25
|
client: {
|
|
20
26
|
type: mongoose.Schema.Types.ObjectId,
|
|
21
27
|
ref: "client",
|
|
22
28
|
required: true,
|
|
29
|
+
index: true,
|
|
23
30
|
},
|
|
24
31
|
viewId: {
|
|
25
32
|
type: String,
|
|
@@ -29,6 +36,7 @@ const ClientRetentionSchema = new Schema<IClientRetention>(
|
|
|
29
36
|
type: Number,
|
|
30
37
|
required: true,
|
|
31
38
|
default: new Date().getFullYear(),
|
|
39
|
+
index: true,
|
|
32
40
|
},
|
|
33
41
|
retentions: {
|
|
34
42
|
type: [
|
|
@@ -59,7 +67,7 @@ const ClientRetentionSchema = new Schema<IClientRetention>(
|
|
|
59
67
|
retainerValue: {
|
|
60
68
|
type: Number,
|
|
61
69
|
required: true,
|
|
62
|
-
default:0,
|
|
70
|
+
default: 0,
|
|
63
71
|
},
|
|
64
72
|
otherPayments: {
|
|
65
73
|
type: Number,
|
|
@@ -75,7 +83,25 @@ const ClientRetentionSchema = new Schema<IClientRetention>(
|
|
|
75
83
|
}
|
|
76
84
|
);
|
|
77
85
|
|
|
78
|
-
|
|
86
|
+
// Compound indexes for common query patterns
|
|
87
|
+
ClientRetentionSchema.index({ client: 1, year: 1 });
|
|
88
|
+
ClientRetentionSchema.index({ client: 1, viewId: 1 });
|
|
89
|
+
ClientRetentionSchema.index({ year: 1, "retentions.month": 1 });
|
|
90
|
+
ClientRetentionSchema.index({ client: 1, "retentions.active": 1 });
|
|
91
|
+
|
|
92
|
+
// Sparse indexes for optional fields
|
|
93
|
+
ClientRetentionSchema.index({ viewId: 1 }, { sparse: true });
|
|
94
|
+
|
|
95
|
+
// Partial index for active retentions
|
|
96
|
+
ClientRetentionSchema.index(
|
|
97
|
+
{ "retentions.active": 1 },
|
|
98
|
+
{ partialFilterExpression: { "retentions.active": true } }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Index for sorting by retainer value
|
|
102
|
+
ClientRetentionSchema.index({ "retentions.retainerValue": -1 });
|
|
103
|
+
|
|
104
|
+
const ClientRetention = mongoose.models.clientretention || model<IClientRetention>(
|
|
79
105
|
"ClientRetention",
|
|
80
106
|
ClientRetentionSchema
|
|
81
107
|
);
|