codebase-models 3.0.2 → 3.0.4
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/dist/src/models/Client.d.ts +6 -0
- package/dist/src/models/Client.js +18 -11
- package/package.json +1 -1
- package/src/models/Client.ts +38 -23
|
@@ -28,6 +28,11 @@ export interface IProperty extends Document {
|
|
|
28
28
|
viewId: string;
|
|
29
29
|
platform?: string;
|
|
30
30
|
}
|
|
31
|
+
export interface IShopify extends Document {
|
|
32
|
+
shopDomain: string;
|
|
33
|
+
accessToken: string;
|
|
34
|
+
apiVersion?: string;
|
|
35
|
+
}
|
|
31
36
|
export interface IClient extends Document {
|
|
32
37
|
iid: string;
|
|
33
38
|
organization: mongoose.Schema.Types.ObjectId;
|
|
@@ -47,6 +52,7 @@ export interface IClient extends Document {
|
|
|
47
52
|
NDAStatus?: boolean;
|
|
48
53
|
retainerValue: number;
|
|
49
54
|
useIntraDayTable: boolean;
|
|
55
|
+
shopify?: IShopify;
|
|
50
56
|
}
|
|
51
57
|
declare const Client: mongoose.Model<any, {}, {}, {}, any, any>;
|
|
52
58
|
export default Client;
|
|
@@ -42,26 +42,32 @@ mongoose_1.default.plugin(mongoose_slug_updater_1.default);
|
|
|
42
42
|
const PropertySchema = new mongoose_1.Schema({
|
|
43
43
|
propertyname: { type: String, required: true },
|
|
44
44
|
viewId: { type: String, required: true },
|
|
45
|
-
platform: { type: String, default: "GA4" }
|
|
45
|
+
platform: { type: String, default: "GA4" },
|
|
46
|
+
});
|
|
47
|
+
const shopifySchema = new mongoose_1.Schema({
|
|
48
|
+
shopDomain: { type: String, required: true },
|
|
49
|
+
accessToken: { type: String, required: true },
|
|
50
|
+
apiVersion: { type: String, default: "2026-01" },
|
|
46
51
|
});
|
|
47
52
|
const ClientSchema = new mongoose_1.Schema({
|
|
48
53
|
iid: {
|
|
49
54
|
type: String,
|
|
50
55
|
trim: true,
|
|
51
56
|
unique: true,
|
|
52
|
-
default: () => (0, constant_1.generateRandomIID)()
|
|
57
|
+
default: () => (0, constant_1.generateRandomIID)(),
|
|
53
58
|
},
|
|
54
|
-
organization: {
|
|
59
|
+
organization: {
|
|
60
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
55
61
|
ref: "organization",
|
|
56
62
|
default: null,
|
|
57
|
-
required: true
|
|
63
|
+
required: true,
|
|
58
64
|
},
|
|
59
65
|
name: { type: String, required: true },
|
|
60
66
|
slug: {
|
|
61
67
|
type: String,
|
|
62
68
|
slug: ["name"],
|
|
63
69
|
slugPaddingSize: 4,
|
|
64
|
-
unique: true
|
|
70
|
+
unique: true,
|
|
65
71
|
},
|
|
66
72
|
viewId: { type: String },
|
|
67
73
|
portfolioClient: { type: Boolean, default: false },
|
|
@@ -69,7 +75,7 @@ const ClientSchema = new mongoose_1.Schema({
|
|
|
69
75
|
tier: {
|
|
70
76
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
71
77
|
ref: "tier",
|
|
72
|
-
default: null
|
|
78
|
+
default: null,
|
|
73
79
|
},
|
|
74
80
|
active: { type: Boolean, default: true },
|
|
75
81
|
currency: { type: String, default: "USD" },
|
|
@@ -77,18 +83,19 @@ const ClientSchema = new mongoose_1.Schema({
|
|
|
77
83
|
createdBy: {
|
|
78
84
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
79
85
|
ref: "user",
|
|
80
|
-
default: null
|
|
86
|
+
default: null,
|
|
81
87
|
},
|
|
82
88
|
onboardDate: { type: Date, default: Date.now },
|
|
83
89
|
bqClientId: { type: String, default: null },
|
|
84
90
|
defaultDataSet: { type: String },
|
|
85
91
|
NDAStatus: { type: Boolean, default: false },
|
|
86
92
|
retainerValue: { type: Number },
|
|
87
|
-
useIntraDayTable: { type: Boolean }
|
|
93
|
+
useIntraDayTable: { type: Boolean },
|
|
94
|
+
shopify: { type: shopifySchema, default: null },
|
|
88
95
|
}, {
|
|
89
|
-
timestamps: true
|
|
96
|
+
timestamps: true,
|
|
90
97
|
});
|
|
91
|
-
ClientSchema.pre(
|
|
98
|
+
ClientSchema.pre("save", function (next) {
|
|
92
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
100
|
if (!this.iid) {
|
|
94
101
|
let unique = false;
|
|
@@ -107,7 +114,7 @@ ClientSchema.pre('save', function (next) {
|
|
|
107
114
|
// Add compound indexes for better query performance
|
|
108
115
|
ClientSchema.index({ active: 1 });
|
|
109
116
|
ClientSchema.index({ organization: 1, active: 1 });
|
|
110
|
-
ClientSchema.index({ name: 1 }, { collation: { locale:
|
|
117
|
+
ClientSchema.index({ name: 1 }, { collation: { locale: "en", strength: 2 } }); // Case-insensitive search
|
|
111
118
|
ClientSchema.index({ tier: 1, active: 1 }); // For tier-based queries
|
|
112
119
|
ClientSchema.index({ onboardDate: 1 }); // For date-based queries
|
|
113
120
|
ClientSchema.index({ portfolioClient: 1, active: 1 }); // For portfolio client queries
|
package/package.json
CHANGED
package/src/models/Client.ts
CHANGED
|
@@ -13,7 +13,19 @@ export interface IProperty extends Document {
|
|
|
13
13
|
const PropertySchema: Schema = new Schema<IProperty>({
|
|
14
14
|
propertyname: { type: String, required: true },
|
|
15
15
|
viewId: { type: String, required: true },
|
|
16
|
-
platform: { type: String, default: "GA4" }
|
|
16
|
+
platform: { type: String, default: "GA4" },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export interface IShopify extends Document {
|
|
20
|
+
shopDomain: string;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
apiVersion?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const shopifySchema: Schema = new Schema<IShopify>({
|
|
26
|
+
shopDomain: { type: String, required: true },
|
|
27
|
+
accessToken: { type: String, required: true },
|
|
28
|
+
apiVersion: { type: String, default: "2026-01" },
|
|
17
29
|
});
|
|
18
30
|
|
|
19
31
|
export interface IClient extends Document {
|
|
@@ -35,6 +47,7 @@ export interface IClient extends Document {
|
|
|
35
47
|
NDAStatus?: boolean;
|
|
36
48
|
retainerValue: number;
|
|
37
49
|
useIntraDayTable: boolean;
|
|
50
|
+
shopify?: IShopify;
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
const ClientSchema: Schema = new Schema<IClient>(
|
|
@@ -43,49 +56,51 @@ const ClientSchema: Schema = new Schema<IClient>(
|
|
|
43
56
|
type: String,
|
|
44
57
|
trim: true,
|
|
45
58
|
unique: true,
|
|
46
|
-
default: () => generateRandomIID()
|
|
59
|
+
default: () => generateRandomIID(),
|
|
47
60
|
},
|
|
48
|
-
organization: {
|
|
61
|
+
organization: {
|
|
62
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
49
63
|
ref: "organization",
|
|
50
64
|
default: null,
|
|
51
|
-
required: true
|
|
65
|
+
required: true,
|
|
52
66
|
},
|
|
53
67
|
name: { type: String, required: true },
|
|
54
|
-
slug: {
|
|
55
|
-
type: String,
|
|
56
|
-
slug: ["name"],
|
|
57
|
-
slugPaddingSize: 4,
|
|
58
|
-
unique: true
|
|
68
|
+
slug: {
|
|
69
|
+
type: String,
|
|
70
|
+
slug: ["name"],
|
|
71
|
+
slugPaddingSize: 4,
|
|
72
|
+
unique: true,
|
|
59
73
|
},
|
|
60
74
|
viewId: { type: String },
|
|
61
75
|
portfolioClient: { type: Boolean, default: false },
|
|
62
76
|
gaproperties: [PropertySchema],
|
|
63
|
-
tier: {
|
|
64
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
65
|
-
ref: "tier",
|
|
66
|
-
default: null
|
|
77
|
+
tier: {
|
|
78
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
79
|
+
ref: "tier",
|
|
80
|
+
default: null,
|
|
67
81
|
},
|
|
68
82
|
active: { type: Boolean, default: true },
|
|
69
83
|
currency: { type: String, default: "USD" },
|
|
70
84
|
logo: { type: String, default: "" },
|
|
71
|
-
createdBy: {
|
|
72
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
73
|
-
ref: "user",
|
|
74
|
-
default: null
|
|
85
|
+
createdBy: {
|
|
86
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
87
|
+
ref: "user",
|
|
88
|
+
default: null,
|
|
75
89
|
},
|
|
76
90
|
onboardDate: { type: Date, default: Date.now },
|
|
77
91
|
bqClientId: { type: String, default: null },
|
|
78
92
|
defaultDataSet: { type: String },
|
|
79
93
|
NDAStatus: { type: Boolean, default: false },
|
|
80
94
|
retainerValue: { type: Number },
|
|
81
|
-
useIntraDayTable: { type: Boolean }
|
|
95
|
+
useIntraDayTable: { type: Boolean },
|
|
96
|
+
shopify: { type: shopifySchema, default: null },
|
|
82
97
|
},
|
|
83
|
-
{
|
|
84
|
-
timestamps: true
|
|
98
|
+
{
|
|
99
|
+
timestamps: true,
|
|
85
100
|
}
|
|
86
101
|
);
|
|
87
102
|
|
|
88
|
-
ClientSchema.pre(
|
|
103
|
+
ClientSchema.pre("save", async function (next) {
|
|
89
104
|
if (!this.iid) {
|
|
90
105
|
let unique = false;
|
|
91
106
|
while (!unique) {
|
|
@@ -96,14 +111,14 @@ ClientSchema.pre('save', async function(next) {
|
|
|
96
111
|
unique = true;
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
}
|
|
114
|
+
}
|
|
100
115
|
next();
|
|
101
116
|
});
|
|
102
117
|
|
|
103
118
|
// Add compound indexes for better query performance
|
|
104
119
|
ClientSchema.index({ active: 1 });
|
|
105
120
|
ClientSchema.index({ organization: 1, active: 1 });
|
|
106
|
-
ClientSchema.index({ name: 1 }, { collation: { locale:
|
|
121
|
+
ClientSchema.index({ name: 1 }, { collation: { locale: "en", strength: 2 } }); // Case-insensitive search
|
|
107
122
|
ClientSchema.index({ tier: 1, active: 1 }); // For tier-based queries
|
|
108
123
|
ClientSchema.index({ onboardDate: 1 }); // For date-based queries
|
|
109
124
|
ClientSchema.index({ portfolioClient: 1, active: 1 }); // For portfolio client queries
|