codebase-models 2.0.4 → 2.0.6
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/index.d.ts +4 -1
- package/dist/index.js +8 -1
- package/dist/src/constant.d.ts +7 -0
- package/dist/src/constant.js +17 -0
- package/dist/src/models/Announcement.d.ts +1 -0
- package/dist/src/models/Announcement.js +31 -0
- package/dist/src/models/Audience.d.ts +1 -0
- package/dist/src/models/Audience.js +31 -0
- package/dist/src/models/BqPreCompiledData.d.ts +1 -0
- package/dist/src/models/BqPreCompiledData.js +31 -0
- package/dist/src/models/Client.d.ts +1 -0
- package/dist/src/models/Client.js +31 -0
- package/dist/src/models/ClientAdditionalRevenue.d.ts +3 -1
- package/dist/src/models/ClientAdditionalRevenue.js +48 -0
- package/dist/src/models/ClientLearning.d.ts +1 -0
- package/dist/src/models/ClientLearning.js +31 -0
- package/dist/src/models/ClientLinks.d.ts +1 -0
- package/dist/src/models/ClientLinks.js +31 -0
- package/dist/src/models/ClientNextSteps.d.ts +1 -0
- package/dist/src/models/ClientNextSteps.js +30 -0
- package/dist/src/models/ClientNote.d.ts +1 -0
- package/dist/src/models/ClientNote.js +31 -0
- package/dist/src/models/ClientScript.d.ts +12 -11
- package/dist/src/models/ClientScript.js +54 -8
- package/dist/src/models/ClientStrategy.d.ts +1 -0
- package/dist/src/models/ClientStrategy.js +31 -0
- package/dist/src/models/CustomQuery.d.ts +38 -0
- package/dist/src/models/CustomQuery.js +68 -0
- package/dist/src/models/Environment.d.ts +2 -0
- package/dist/src/models/Environment.js +34 -0
- package/dist/src/models/Goal.d.ts +1 -0
- package/dist/src/models/Goal.js +31 -1
- package/dist/src/models/Page.d.ts +2 -0
- package/dist/src/models/Page.js +48 -0
- package/dist/src/models/Report.d.ts +1 -0
- package/dist/src/models/Report.js +30 -0
- package/dist/src/models/StageInCustomerJourney.d.ts +1 -0
- package/dist/src/models/StageInCustomerJourney.js +31 -0
- package/dist/src/models/Test.d.ts +2 -0
- package/dist/src/models/Test.js +46 -2
- package/dist/src/models/TestTimeline.d.ts +39 -0
- package/dist/src/models/TestTimeline.js +79 -0
- package/index.ts +6 -1
- package/package.json +3 -2
- package/src/constant.ts +17 -0
- package/src/models/Announcement.ts +22 -0
- package/src/models/Audience.ts +23 -0
- package/src/models/BqPreCompiledData.ts +22 -0
- package/src/models/Client.ts +22 -0
- package/src/models/ClientAdditionalRevenue.ts +42 -1
- package/src/models/ClientLearning.ts +22 -0
- package/src/models/ClientLinks.ts +23 -2
- package/src/models/ClientNextSteps.ts +20 -0
- package/src/models/ClientNote.ts +22 -1
- package/src/models/ClientScript.ts +56 -20
- package/src/models/ClientStrategy.ts +24 -0
- package/src/models/CustomQuery.ts +49 -0
- package/src/models/Environment.ts +27 -0
- package/src/models/Goal.ts +22 -2
- package/src/models/Page.ts +43 -0
- package/src/models/Report.ts +22 -0
- package/src/models/StageInCustomerJourney.ts +22 -0
- package/src/models/Test.ts +40 -3
- package/src/models/TestTimeline.ts +61 -0
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import mongoose, { Document } from "mongoose";
|
|
26
26
|
export interface IVariations extends Document {
|
|
27
|
+
iid: string;
|
|
27
28
|
name: string;
|
|
28
29
|
css_code: string;
|
|
29
30
|
baseline: boolean;
|
|
@@ -38,6 +39,7 @@ export interface IVariations extends Document {
|
|
|
38
39
|
}
|
|
39
40
|
export interface ITest extends Document {
|
|
40
41
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
42
|
+
iid: string;
|
|
41
43
|
status: string;
|
|
42
44
|
name: string;
|
|
43
45
|
traffic_allocation: number;
|
package/dist/src/models/Test.js
CHANGED
|
@@ -22,9 +22,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
35
|
const mongoose_1 = __importStar(require("mongoose"));
|
|
36
|
+
const constant_1 = require("../constant");
|
|
27
37
|
const VariationsSchema = new mongoose_1.Schema({
|
|
38
|
+
iid: { type: String, unique: true },
|
|
28
39
|
name: { type: String, required: true },
|
|
29
40
|
css_code: { type: String, default: "" },
|
|
30
41
|
baseline: { type: Boolean, default: false },
|
|
@@ -38,6 +49,7 @@ const VariationsSchema = new mongoose_1.Schema({
|
|
|
38
49
|
changesets: { type: String, default: "[]" }
|
|
39
50
|
});
|
|
40
51
|
const TestSchema = new mongoose_1.Schema({
|
|
52
|
+
iid: { type: String, unique: true },
|
|
41
53
|
organizationId: {
|
|
42
54
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
43
55
|
ref: "organization",
|
|
@@ -46,7 +58,7 @@ const TestSchema = new mongoose_1.Schema({
|
|
|
46
58
|
status: {
|
|
47
59
|
type: String,
|
|
48
60
|
default: "draft",
|
|
49
|
-
enum: ["live", "draft", "ended", "paused", "preview", "running"]
|
|
61
|
+
enum: ["live", "draft", "ended", "paused", "preview", "running", "discard"]
|
|
50
62
|
},
|
|
51
63
|
name: { type: String, required: true },
|
|
52
64
|
traffic_allocation: { type: Number, default: 100 },
|
|
@@ -113,7 +125,8 @@ const TestSchema = new mongoose_1.Schema({
|
|
|
113
125
|
},
|
|
114
126
|
stageincustomerjourney: {
|
|
115
127
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
116
|
-
ref: "stageincustomerjourney"
|
|
128
|
+
ref: "stageincustomerjourney",
|
|
129
|
+
default: null
|
|
117
130
|
},
|
|
118
131
|
// Test configuration
|
|
119
132
|
property: { type: mongoose_1.default.Schema.Types.Mixed, default: null },
|
|
@@ -143,6 +156,37 @@ const TestSchema = new mongoose_1.Schema({
|
|
|
143
156
|
}, {
|
|
144
157
|
timestamps: true
|
|
145
158
|
});
|
|
159
|
+
TestSchema.pre('save', function (next) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
if (!this.iid) {
|
|
162
|
+
let unique = false;
|
|
163
|
+
while (!unique) {
|
|
164
|
+
const id = (0, constant_1.generateRandomIID)();
|
|
165
|
+
const existing = yield mongoose_1.default.models.test.findOne({ iid: id });
|
|
166
|
+
if (!existing) {
|
|
167
|
+
this.iid = id;
|
|
168
|
+
unique = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// For each Variation inside Test
|
|
173
|
+
for (const variation of this.variations) {
|
|
174
|
+
if (!variation.iid) {
|
|
175
|
+
let uniqueVar = false;
|
|
176
|
+
while (!uniqueVar) {
|
|
177
|
+
const id = (0, constant_1.generateRandomIID)();
|
|
178
|
+
const existingVar = yield mongoose_1.default.models.test.findOne({ "variations.iid": id });
|
|
179
|
+
if (!existingVar) {
|
|
180
|
+
variation.iid = id;
|
|
181
|
+
uniqueVar = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
next();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
TestSchema.index({ iid: 1 }, { unique: true });
|
|
146
190
|
// Add compound indexes for better query performance
|
|
147
191
|
TestSchema.index({ client: 1, status: 1 });
|
|
148
192
|
TestSchema.index({ client: 1, status: 1, livedate: 1 });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
import mongoose, { Document } from "mongoose";
|
|
26
|
+
export interface ITestTimeline extends Document {
|
|
27
|
+
iid: string;
|
|
28
|
+
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
29
|
+
test: mongoose.Schema.Types.ObjectId;
|
|
30
|
+
event: string;
|
|
31
|
+
client: mongoose.Schema.Types.ObjectId;
|
|
32
|
+
user: mongoose.Schema.Types.ObjectId;
|
|
33
|
+
changes: {
|
|
34
|
+
type: mongoose.Schema.Types.Mixed;
|
|
35
|
+
default: {};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
declare const TestTimeline: mongoose.Model<any, {}, {}, {}, any, any>;
|
|
39
|
+
export default TestTimeline;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const mongoose_1 = __importStar(require("mongoose"));
|
|
36
|
+
const constant_1 = require("../constant");
|
|
37
|
+
const TestTimelineSchema = new mongoose_1.Schema({
|
|
38
|
+
iid: {
|
|
39
|
+
type: String,
|
|
40
|
+
unique: true,
|
|
41
|
+
},
|
|
42
|
+
event: {
|
|
43
|
+
type: String,
|
|
44
|
+
enum: ["test_created", "test_updated", "test_deleted"],
|
|
45
|
+
},
|
|
46
|
+
organizationId: {
|
|
47
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
48
|
+
ref: "organization",
|
|
49
|
+
default: null,
|
|
50
|
+
},
|
|
51
|
+
client: {
|
|
52
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
53
|
+
ref: "client",
|
|
54
|
+
},
|
|
55
|
+
test: {
|
|
56
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
57
|
+
ref: "test",
|
|
58
|
+
},
|
|
59
|
+
user: {
|
|
60
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
61
|
+
ref: "user",
|
|
62
|
+
},
|
|
63
|
+
changes: {
|
|
64
|
+
type: mongoose_1.default.Schema.Types.Mixed,
|
|
65
|
+
default: {},
|
|
66
|
+
},
|
|
67
|
+
}, {
|
|
68
|
+
timestamps: true,
|
|
69
|
+
});
|
|
70
|
+
TestTimelineSchema.pre("save", function (next) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
if (!this.iid) {
|
|
73
|
+
this.iid = (0, constant_1.generateRandomIID)();
|
|
74
|
+
}
|
|
75
|
+
next();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const TestTimeline = mongoose_1.default.models.testTimeline || (0, mongoose_1.model)("testTimeline", TestTimelineSchema);
|
|
79
|
+
exports.default = TestTimeline;
|
package/index.ts
CHANGED
|
@@ -47,7 +47,9 @@ import Audience from "./src/models/Audience";
|
|
|
47
47
|
import Environment from "./src/models/Environment";
|
|
48
48
|
import PrecalculationFilters from "./src/models/PrecalculationFilters";
|
|
49
49
|
import BqPreCompiledData from "./src/models/BqPreCompiledData";
|
|
50
|
-
|
|
50
|
+
import CustomQuery from "./src/models/CustomQuery";
|
|
51
|
+
import { generateRandomIID } from "./src/constant";
|
|
52
|
+
import TestTimeline from "./src/models/TestTimeline";
|
|
51
53
|
async function seedRoles() {
|
|
52
54
|
const checkRoles = await Role.countDocuments();
|
|
53
55
|
if (checkRoles < 5) {
|
|
@@ -96,6 +98,7 @@ export async function connect(
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
export {
|
|
101
|
+
generateRandomIID,
|
|
99
102
|
Client,
|
|
100
103
|
ClientReportsTemp,
|
|
101
104
|
QueryLog,
|
|
@@ -128,7 +131,9 @@ export {
|
|
|
128
131
|
Portfolio,
|
|
129
132
|
ReadNotification,
|
|
130
133
|
Role,
|
|
134
|
+
CustomQuery,
|
|
131
135
|
SavedSegment,
|
|
136
|
+
TestTimeline,
|
|
132
137
|
Segment,
|
|
133
138
|
SegmentCombination,
|
|
134
139
|
Snippet,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebase-models",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Common models for codebase",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"mongoose": "^8.2.3",
|
|
16
|
-
"mongoose-slug-updater": "^3.3.0"
|
|
16
|
+
"mongoose-slug-updater": "^3.3.0",
|
|
17
|
+
"uuid": "^11.1.0"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@types/mongoose": "^5.11.97",
|
package/src/constant.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
|
|
1
3
|
const HypothesisSheetConstants = {
|
|
2
4
|
NO: 0,
|
|
3
5
|
YES: 1,
|
|
@@ -11,4 +13,19 @@ const HypothesisSheetConstants = {
|
|
|
11
13
|
GOOD: 2,
|
|
12
14
|
};
|
|
13
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Generates a random unique identifier
|
|
18
|
+
* @returns A 12-character uppercase string (increased from 8 for better uniqueness)
|
|
19
|
+
* @throws Error if UUID generation fails
|
|
20
|
+
*/
|
|
21
|
+
const generateRandomIID = (): string => {
|
|
22
|
+
try {
|
|
23
|
+
// Take first 12 characters instead of 8 for better uniqueness
|
|
24
|
+
return uuidv4().replace(/-/g, '').substring(0, 12).toUpperCase();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(`Failed to generate random IID: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { generateRandomIID };
|
|
14
31
|
export default HypothesisSheetConstants;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IAnnouncement extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
title: string;
|
|
5
7
|
description?: string;
|
|
6
8
|
active?: boolean;
|
|
@@ -12,6 +14,10 @@ export interface IAnnouncement extends Document {
|
|
|
12
14
|
|
|
13
15
|
const AnnouncementSchema = new Schema<IAnnouncement>(
|
|
14
16
|
{
|
|
17
|
+
iid: {
|
|
18
|
+
type: String,
|
|
19
|
+
trim: true,
|
|
20
|
+
},
|
|
15
21
|
organizationId: {
|
|
16
22
|
type: mongoose.Schema.Types.ObjectId,
|
|
17
23
|
ref: "organization",
|
|
@@ -49,6 +55,22 @@ const AnnouncementSchema = new Schema<IAnnouncement>(
|
|
|
49
55
|
}
|
|
50
56
|
);
|
|
51
57
|
|
|
58
|
+
AnnouncementSchema.pre('save', async function(next) {
|
|
59
|
+
if (!this.iid) {
|
|
60
|
+
let unique = false;
|
|
61
|
+
while (!unique) {
|
|
62
|
+
const id = generateRandomIID();
|
|
63
|
+
const existing = await mongoose.models.announcement.findOne({ iid: id });
|
|
64
|
+
if (!existing) {
|
|
65
|
+
this.iid = id;
|
|
66
|
+
unique = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
next();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
AnnouncementSchema.index({ iid: 1 }, { unique: true });
|
|
52
74
|
// Add compound indexes for better query performance
|
|
53
75
|
AnnouncementSchema.index({ active: 1, createdAt: -1 }); // For active announcements sorted by date
|
|
54
76
|
AnnouncementSchema.index({ forRoles: 1, active: 1 }); // For role-based announcements
|
package/src/models/Audience.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IAudience extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
7
|
name: string;
|
|
6
8
|
rules_js?: string;
|
|
@@ -9,6 +11,10 @@ export interface IAudience extends Document {
|
|
|
9
11
|
|
|
10
12
|
const AudienceSchema = new Schema<IAudience>(
|
|
11
13
|
{
|
|
14
|
+
iid: {
|
|
15
|
+
type: String,
|
|
16
|
+
trim: true,
|
|
17
|
+
},
|
|
12
18
|
organizationId: {
|
|
13
19
|
type: mongoose.Schema.Types.ObjectId,
|
|
14
20
|
ref: "organization",
|
|
@@ -31,6 +37,23 @@ const AudienceSchema = new Schema<IAudience>(
|
|
|
31
37
|
}
|
|
32
38
|
);
|
|
33
39
|
|
|
40
|
+
AudienceSchema.pre('save', async function(next) {
|
|
41
|
+
if (!this.iid) {
|
|
42
|
+
let unique = false;
|
|
43
|
+
while (!unique) {
|
|
44
|
+
const id = generateRandomIID();
|
|
45
|
+
const existing = await mongoose.models.audience.findOne({ iid: id });
|
|
46
|
+
if (!existing) {
|
|
47
|
+
this.iid = id;
|
|
48
|
+
unique = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
next();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
AudienceSchema.index({ iid: 1 }, { unique: true });
|
|
56
|
+
|
|
34
57
|
const Audience = mongoose.models.audience || model<IAudience>("audience", AudienceSchema);
|
|
35
58
|
|
|
36
59
|
export default Audience;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IBqPreCompiledData extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
title: string;
|
|
5
7
|
organizationId: mongoose.Schema.Types.ObjectId;
|
|
6
8
|
client: mongoose.Schema.Types.ObjectId;
|
|
@@ -13,6 +15,10 @@ export interface IBqPreCompiledData extends Document {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const BqPreCompiledDataSchema = new Schema<IBqPreCompiledData>({
|
|
18
|
+
iid: {
|
|
19
|
+
type: String,
|
|
20
|
+
trim: true,
|
|
21
|
+
},
|
|
16
22
|
title: {
|
|
17
23
|
type: String,
|
|
18
24
|
default: null,
|
|
@@ -56,6 +62,22 @@ const BqPreCompiledDataSchema = new Schema<IBqPreCompiledData>({
|
|
|
56
62
|
timestamps: true
|
|
57
63
|
});
|
|
58
64
|
|
|
65
|
+
BqPreCompiledDataSchema.pre('save', async function(next) {
|
|
66
|
+
if (!this.iid) {
|
|
67
|
+
let unique = false;
|
|
68
|
+
while (!unique) {
|
|
69
|
+
const id = generateRandomIID();
|
|
70
|
+
const existing = await mongoose.models.bqprecompileddata.findOne({ iid: id });
|
|
71
|
+
if (!existing) {
|
|
72
|
+
this.iid = id;
|
|
73
|
+
unique = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
next();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
BqPreCompiledDataSchema.index({ iid: 1 }, { unique: true });
|
|
59
81
|
BqPreCompiledDataSchema.index({ organizationId: 1, client: 1 });
|
|
60
82
|
const BqPreCompiledData = mongoose.models.bqprecompileddata || model<IBqPreCompiledData>("bqprecompileddata", BqPreCompiledDataSchema);
|
|
61
83
|
|
package/src/models/Client.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import mongoose, { Schema, Document, model } from "mongoose";
|
|
2
2
|
import slug from "mongoose-slug-updater";
|
|
3
|
+
import { generateRandomIID } from "../constant";
|
|
3
4
|
|
|
4
5
|
mongoose.plugin(slug);
|
|
5
6
|
|
|
@@ -16,6 +17,7 @@ const PropertySchema: Schema = new Schema<IProperty>({
|
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
export interface IClient extends Document {
|
|
20
|
+
iid: string;
|
|
19
21
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
20
22
|
name: string;
|
|
21
23
|
slug?: string;
|
|
@@ -37,6 +39,10 @@ export interface IClient extends Document {
|
|
|
37
39
|
|
|
38
40
|
const ClientSchema: Schema = new Schema<IClient>(
|
|
39
41
|
{
|
|
42
|
+
iid: {
|
|
43
|
+
type: String,
|
|
44
|
+
trim: true,
|
|
45
|
+
},
|
|
40
46
|
organizationId: { type: mongoose.Schema.Types.ObjectId,
|
|
41
47
|
ref: "organization",
|
|
42
48
|
default: null },
|
|
@@ -75,6 +81,22 @@ const ClientSchema: Schema = new Schema<IClient>(
|
|
|
75
81
|
}
|
|
76
82
|
);
|
|
77
83
|
|
|
84
|
+
ClientSchema.pre('save', async function(next) {
|
|
85
|
+
if (!this.iid) {
|
|
86
|
+
let unique = false;
|
|
87
|
+
while (!unique) {
|
|
88
|
+
const id = generateRandomIID();
|
|
89
|
+
const existing = await mongoose.models.client.findOne({ iid: id });
|
|
90
|
+
if (!existing) {
|
|
91
|
+
this.iid = id;
|
|
92
|
+
unique = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
next();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
ClientSchema.index({ iid: 1 }, { unique: true });
|
|
78
100
|
// Add compound indexes for better query performance
|
|
79
101
|
ClientSchema.index({ active: 1 });
|
|
80
102
|
ClientSchema.index({ organizationId: 1, active: 1 });
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IClientAdditionalRevenue extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
7
|
client?: mongoose.Schema.Types.ObjectId;
|
|
6
|
-
additionalRevenueForTests: IAdditionalRevenue;
|
|
8
|
+
additionalRevenueForTests: IAdditionalRevenue[];
|
|
7
9
|
createdBy?: mongoose.Schema.Types.ObjectId;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export interface IAdditionalRevenue extends Document {
|
|
13
|
+
iid: string;
|
|
11
14
|
segmentName: string;
|
|
12
15
|
lastDate?: Date;
|
|
13
16
|
test?: mongoose.Schema.Types.ObjectId;
|
|
@@ -15,6 +18,10 @@ export interface IAdditionalRevenue extends Document {
|
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
const AdditionalRevenueSchema = new Schema<IAdditionalRevenue>({
|
|
21
|
+
iid: {
|
|
22
|
+
type: String,
|
|
23
|
+
trim: true,
|
|
24
|
+
},
|
|
18
25
|
// add_rev: {
|
|
19
26
|
// type: Number,
|
|
20
27
|
// },
|
|
@@ -34,8 +41,13 @@ const AdditionalRevenueSchema = new Schema<IAdditionalRevenue>({
|
|
|
34
41
|
},
|
|
35
42
|
});
|
|
36
43
|
|
|
44
|
+
|
|
37
45
|
const ClientAdditionalRevenueSchema = new Schema<IClientAdditionalRevenue>(
|
|
38
46
|
{
|
|
47
|
+
iid: {
|
|
48
|
+
type: String,
|
|
49
|
+
trim: true,
|
|
50
|
+
},
|
|
39
51
|
organizationId: {
|
|
40
52
|
type: mongoose.Schema.Types.ObjectId,
|
|
41
53
|
ref: "organization",
|
|
@@ -57,6 +69,35 @@ const ClientAdditionalRevenueSchema = new Schema<IClientAdditionalRevenue>(
|
|
|
57
69
|
}
|
|
58
70
|
);
|
|
59
71
|
|
|
72
|
+
ClientAdditionalRevenueSchema.pre('save', async function(next) {
|
|
73
|
+
if (!this.iid) {
|
|
74
|
+
let unique = false;
|
|
75
|
+
while (!unique) {
|
|
76
|
+
const id = generateRandomIID();
|
|
77
|
+
const existing = await mongoose.models.clientadditionalrevenue.findOne({ iid: id });
|
|
78
|
+
if (!existing) {
|
|
79
|
+
this.iid = id;
|
|
80
|
+
unique = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// For each Variation inside Test
|
|
85
|
+
for (const additionalRevenue of this.additionalRevenueForTests) {
|
|
86
|
+
if (!additionalRevenue.iid) {
|
|
87
|
+
let uniqueVar = false;
|
|
88
|
+
while (!uniqueVar) {
|
|
89
|
+
const id = generateRandomIID();
|
|
90
|
+
const existingVar = await mongoose.models.clientadditionalrevenue.findOne({ "additionalRevenueForTests.iid": id });
|
|
91
|
+
if (!existingVar) {
|
|
92
|
+
additionalRevenue.iid = id;
|
|
93
|
+
uniqueVar = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
next();
|
|
99
|
+
});
|
|
100
|
+
|
|
60
101
|
ClientAdditionalRevenueSchema.index({
|
|
61
102
|
client: 1,
|
|
62
103
|
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IClientLearning extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
name: string;
|
|
5
7
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
6
8
|
client?: mongoose.Schema.Types.ObjectId;
|
|
@@ -10,6 +12,10 @@ export interface IClientLearning extends Document {
|
|
|
10
12
|
|
|
11
13
|
const ClientLearningSchema = new Schema<IClientLearning>(
|
|
12
14
|
{
|
|
15
|
+
iid: {
|
|
16
|
+
type: String,
|
|
17
|
+
trim: true,
|
|
18
|
+
},
|
|
13
19
|
name: {
|
|
14
20
|
type: String,
|
|
15
21
|
required: true,
|
|
@@ -37,6 +43,22 @@ const ClientLearningSchema = new Schema<IClientLearning>(
|
|
|
37
43
|
}
|
|
38
44
|
);
|
|
39
45
|
|
|
46
|
+
ClientLearningSchema.pre('save', async function(next) {
|
|
47
|
+
if (!this.iid) {
|
|
48
|
+
let unique = false;
|
|
49
|
+
while (!unique) {
|
|
50
|
+
const id = generateRandomIID();
|
|
51
|
+
const existing = await mongoose.models.clientlearning.findOne({ iid: id });
|
|
52
|
+
if (!existing) {
|
|
53
|
+
this.iid = id;
|
|
54
|
+
unique = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
next();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
ClientLearningSchema.index({ iid: 1 }, { unique: true });
|
|
40
62
|
// Compound indexes for common query patterns
|
|
41
63
|
ClientLearningSchema.index({ client: 1 });
|
|
42
64
|
// Sparse indexes for optional fields
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
-
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
3
|
export interface IClientLinks extends Document {
|
|
4
|
+
iid: string;
|
|
4
5
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
6
|
title: string;
|
|
6
7
|
description?: string;
|
|
@@ -13,6 +14,10 @@ export interface IClientLinks extends Document {
|
|
|
13
14
|
|
|
14
15
|
const ClientLinksSchema = new Schema<IClientLinks>(
|
|
15
16
|
{
|
|
17
|
+
iid: {
|
|
18
|
+
type: String,
|
|
19
|
+
trim: true,
|
|
20
|
+
},
|
|
16
21
|
organizationId: {
|
|
17
22
|
type: mongoose.Schema.Types.ObjectId,
|
|
18
23
|
ref: "organization",
|
|
@@ -51,8 +56,24 @@ const ClientLinksSchema = new Schema<IClientLinks>(
|
|
|
51
56
|
{
|
|
52
57
|
timestamps: true,
|
|
53
58
|
}
|
|
54
|
-
);
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
ClientLinksSchema.pre('save', async function(next) {
|
|
62
|
+
if (!this.iid) {
|
|
63
|
+
let unique = false;
|
|
64
|
+
while (!unique) {
|
|
65
|
+
const id = generateRandomIID();
|
|
66
|
+
const existing = await mongoose.models.clientlink.findOne({ iid: id });
|
|
67
|
+
if (!existing) {
|
|
68
|
+
this.iid = id;
|
|
69
|
+
unique = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
next();
|
|
74
|
+
});
|
|
55
75
|
|
|
76
|
+
ClientLinksSchema.index({ iid: 1 }, { unique: true });
|
|
56
77
|
// Compound indexes for common query patterns
|
|
57
78
|
ClientLinksSchema.index({ client: 1 });
|
|
58
79
|
ClientLinksSchema.index({ client: 1, private: 1 });
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IClientNextSteps extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
name: string;
|
|
5
7
|
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
6
8
|
client?: mongoose.Schema.Types.ObjectId;
|
|
@@ -10,6 +12,10 @@ export interface IClientNextSteps extends Document {
|
|
|
10
12
|
|
|
11
13
|
const ClientNextStepsSchema = new Schema<IClientNextSteps>(
|
|
12
14
|
{
|
|
15
|
+
iid: {
|
|
16
|
+
type: String,
|
|
17
|
+
trim: true,
|
|
18
|
+
},
|
|
13
19
|
name: {
|
|
14
20
|
type: String,
|
|
15
21
|
required: true,
|
|
@@ -36,6 +42,20 @@ const ClientNextStepsSchema = new Schema<IClientNextSteps>(
|
|
|
36
42
|
}
|
|
37
43
|
);
|
|
38
44
|
|
|
45
|
+
ClientNextStepsSchema.pre('save', async function(next) {
|
|
46
|
+
if (!this.iid) {
|
|
47
|
+
let unique = false;
|
|
48
|
+
while (!unique) {
|
|
49
|
+
const id = generateRandomIID();
|
|
50
|
+
const existing = await mongoose.models.clientnextstep.findOne({ iid: id });
|
|
51
|
+
if (!existing) {
|
|
52
|
+
this.iid = id;
|
|
53
|
+
unique = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
next();
|
|
58
|
+
});
|
|
39
59
|
ClientNextStepsSchema.index({
|
|
40
60
|
client: 1,
|
|
41
61
|
viewId: 1,
|