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