codebase-models 2.1.24 → 3.0.0
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-stage.yml +33 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +14 -8
- package/dist/src/constant.d.ts +24 -1
- package/dist/src/constant.js +89 -3
- package/dist/src/models/Client.d.ts +1 -1
- package/dist/src/models/Client.js +7 -4
- package/dist/src/models/{SegmentCombination.d.ts → Invitation.d.ts} +15 -14
- package/dist/src/models/Invitation.js +55 -0
- package/dist/src/models/Organization.d.ts +8 -15
- package/dist/src/models/Organization.js +10 -58
- package/dist/src/models/{QueryLog.d.ts → Package.d.ts} +7 -7
- package/dist/src/models/{QueryLog.js → Package.js} +10 -19
- package/dist/src/models/{Segment.d.ts → Thread.d.ts} +7 -10
- package/dist/src/models/Thread.js +78 -0
- package/dist/src/models/ThreadMessage.d.ts +35 -0
- package/dist/src/models/ThreadMessage.js +86 -0
- package/dist/src/models/User.d.ts +8 -5
- package/dist/src/models/User.js +13 -37
- package/dist/src/models/UserIdentity.d.ts +35 -0
- package/dist/src/models/{SegmentCombination.js → UserIdentity.js} +11 -47
- package/dist/src/models/UserOrganization.d.ts +33 -0
- package/dist/src/models/{Segment.js → UserOrganization.js} +10 -33
- package/dist/src/models/UserPermission.d.ts +4 -11
- package/dist/src/models/UserPermission.js +27 -10
- package/index.ts +12 -6
- package/package.json +1 -1
- package/src/constant.ts +88 -3
- package/src/models/Client.ts +8 -5
- package/src/models/Invitation.ts +50 -0
- package/src/models/Organization.ts +18 -73
- package/src/models/Package.ts +24 -0
- package/src/models/Thread.ts +57 -0
- package/src/models/ThreadMessage.ts +67 -0
- package/src/models/User.ts +21 -43
- package/src/models/UserIdentity.ts +26 -0
- package/src/models/UserOrganization.ts +23 -0
- package/src/models/UserPermission.ts +31 -21
- package/src/models/QueryLog.ts +0 -35
- package/src/models/Segment.ts +0 -50
- package/src/models/SegmentCombination.ts +0 -68
package/src/models/Client.ts
CHANGED
|
@@ -18,7 +18,7 @@ const PropertySchema: Schema = new Schema<IProperty>({
|
|
|
18
18
|
|
|
19
19
|
export interface IClient extends Document {
|
|
20
20
|
iid: string;
|
|
21
|
-
|
|
21
|
+
organization: mongoose.Schema.Types.ObjectId;
|
|
22
22
|
name: string;
|
|
23
23
|
slug?: string;
|
|
24
24
|
viewId?: string;
|
|
@@ -42,10 +42,14 @@ const ClientSchema: Schema = new Schema<IClient>(
|
|
|
42
42
|
iid: {
|
|
43
43
|
type: String,
|
|
44
44
|
trim: true,
|
|
45
|
+
unique: true,
|
|
46
|
+
default: () => generateRandomIID()
|
|
45
47
|
},
|
|
46
|
-
|
|
48
|
+
organization: { type: mongoose.Schema.Types.ObjectId,
|
|
47
49
|
ref: "organization",
|
|
48
|
-
default: null
|
|
50
|
+
default: null,
|
|
51
|
+
required: true
|
|
52
|
+
},
|
|
49
53
|
name: { type: String, required: true },
|
|
50
54
|
slug: {
|
|
51
55
|
type: String,
|
|
@@ -96,10 +100,9 @@ ClientSchema.pre('save', async function(next) {
|
|
|
96
100
|
next();
|
|
97
101
|
});
|
|
98
102
|
|
|
99
|
-
ClientSchema.index({ iid: 1 }, { unique: true });
|
|
100
103
|
// Add compound indexes for better query performance
|
|
101
104
|
ClientSchema.index({ active: 1 });
|
|
102
|
-
ClientSchema.index({
|
|
105
|
+
ClientSchema.index({ organization: 1, active: 1 });
|
|
103
106
|
ClientSchema.index({ name: 1 }, { collation: { locale: 'en', strength: 2 } }); // Case-insensitive search
|
|
104
107
|
ClientSchema.index({ tier: 1, active: 1 }); // For tier-based queries
|
|
105
108
|
ClientSchema.index({ onboardDate: 1 }); // For date-based queries
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
|
+
|
|
4
|
+
export interface IInvitation extends Document {
|
|
5
|
+
iid: string;
|
|
6
|
+
email: string;
|
|
7
|
+
invitedBy: mongoose.Types.ObjectId; // user who sent the invite
|
|
8
|
+
organization: mongoose.Types.ObjectId;
|
|
9
|
+
client?: mongoose.Types.ObjectId; // optional (invite to specific client)
|
|
10
|
+
role?: string; // optional role name
|
|
11
|
+
permissions?: mongoose.Schema.Types.Mixed;
|
|
12
|
+
token: string;
|
|
13
|
+
status: string;
|
|
14
|
+
expiresAt: Date;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
updatedAt: Date;
|
|
17
|
+
}
|
|
18
|
+
const InvitationSchema = new Schema<IInvitation>({
|
|
19
|
+
iid: { type: String, unique: true, default: () => generateRandomIID() },
|
|
20
|
+
email: { type: String, required: true },
|
|
21
|
+
invitedBy: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
|
|
22
|
+
organization: { type: mongoose.Schema.Types.ObjectId, ref: "organization", required: true },
|
|
23
|
+
client: { type: mongoose.Schema.Types.ObjectId, ref: "client" },
|
|
24
|
+
role: { type: String, enum: ["owner", "admin", "member"], default: "member" },
|
|
25
|
+
permissions: { type: mongoose.Schema.Types.Mixed, required: true, default: {
|
|
26
|
+
dashboard: true,
|
|
27
|
+
reporting: false,
|
|
28
|
+
insights: false,
|
|
29
|
+
documentsAndLinks: false,
|
|
30
|
+
cvrReports: false,
|
|
31
|
+
abTesting: false,
|
|
32
|
+
abTestingDefault: true,
|
|
33
|
+
manageExperiments: false,
|
|
34
|
+
preCalculations: false,
|
|
35
|
+
} },
|
|
36
|
+
token: { type: String, unique: true, required: true },
|
|
37
|
+
status: { type: String, enum: ["pending", "accepted", "expired", "revoked"], default: "pending" },
|
|
38
|
+
expiresAt: { type: Date, default: Date.now() + 1000 * 60 * 60 * 24 * 30 },
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
timestamps: true
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
InvitationSchema.index({ email: 1, organization: 1 });
|
|
45
|
+
InvitationSchema.index({ token: 1 }, { unique: true });
|
|
46
|
+
|
|
47
|
+
const Invitation = mongoose.models.invitation || model<IInvitation>("invitation", InvitationSchema);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
export default Invitation;
|
|
@@ -1,86 +1,31 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IOrganization extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
name: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
zip: string;
|
|
13
|
-
country: string;
|
|
14
|
-
phone: string;
|
|
15
|
-
logo: string;
|
|
16
|
-
website: string;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
updatedAt: Date;
|
|
19
|
-
isActive: boolean;
|
|
7
|
+
ownerId: mongoose.Schema.Types.ObjectId;
|
|
8
|
+
stripeCustomerId?: string;
|
|
9
|
+
packageId?: mongoose.Schema.Types.ObjectId;
|
|
10
|
+
subscriptionId: String;
|
|
11
|
+
subscriptionStatus: String;
|
|
12
|
+
lastPaymentDate: Date;
|
|
13
|
+
currentPeriodEnd: Date;
|
|
20
14
|
}
|
|
21
15
|
const OrganizationSchema = new Schema<IOrganization>({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
},
|
|
16
|
+
iid: { type: String, default: () => generateRandomIID() },
|
|
17
|
+
name: { type: String, required: true },
|
|
18
|
+
ownerId: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
|
|
19
|
+
stripeCustomerId: String,
|
|
20
|
+
packageId: { type: mongoose.Types.ObjectId, ref: "package" },
|
|
21
|
+
subscriptionId: String,
|
|
22
|
+
subscriptionStatus: String,
|
|
23
|
+
lastPaymentDate: Date,
|
|
24
|
+
currentPeriodEnd: Date,
|
|
79
25
|
}, {
|
|
80
26
|
timestamps: true
|
|
81
27
|
});
|
|
82
28
|
const Organization = mongoose.models.organization || model<IOrganization>("organization", OrganizationSchema);
|
|
83
29
|
|
|
84
|
-
OrganizationSchema.index({ name: 1, isActive: 1 });
|
|
85
30
|
|
|
86
31
|
export default Organization;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID, PackageFeaturesConstants } from "../constant";
|
|
3
|
+
|
|
4
|
+
export interface IPackage extends Document {
|
|
5
|
+
iid: string;
|
|
6
|
+
name: string;
|
|
7
|
+
stripeProductId: string;
|
|
8
|
+
features: mongoose.Schema.Types.Mixed;
|
|
9
|
+
// userPermissions: mongoose.Schema.Types.ObjectId;
|
|
10
|
+
}
|
|
11
|
+
const PackageSchema = new Schema<IPackage>({
|
|
12
|
+
iid: { type: String, unique: true, default: () => generateRandomIID() },
|
|
13
|
+
name: { type: String, required: true },
|
|
14
|
+
stripeProductId: { type: String},
|
|
15
|
+
// userPermissions: { type: mongoose.Schema.Types.ObjectId, ref: "userpermission", required: true },
|
|
16
|
+
features: { type: mongoose.Schema.Types.Mixed, required: true, default: PackageFeaturesConstants },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
timestamps: true
|
|
20
|
+
});
|
|
21
|
+
const Package = mongoose.models.package || model<IPackage>("package", PackageSchema);
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export default Package;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
|
+
|
|
4
|
+
export interface IThread extends Document {
|
|
5
|
+
iid: string;
|
|
6
|
+
organization: mongoose.Schema.Types.ObjectId;
|
|
7
|
+
user: mongoose.Schema.Types.ObjectId;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ThreadSchema = new Schema<IThread>(
|
|
12
|
+
{
|
|
13
|
+
iid: {
|
|
14
|
+
type: String,
|
|
15
|
+
trim: true,
|
|
16
|
+
},
|
|
17
|
+
name: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
default: "New Conversation",
|
|
21
|
+
},
|
|
22
|
+
organization: {
|
|
23
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
24
|
+
ref: "organization",
|
|
25
|
+
default: null,
|
|
26
|
+
},
|
|
27
|
+
user: {
|
|
28
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
29
|
+
ref: "user",
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
timestamps: true,
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
ThreadSchema.pre('save', async function(next) {
|
|
39
|
+
if (!this.iid) {
|
|
40
|
+
let unique = false;
|
|
41
|
+
while (!unique) {
|
|
42
|
+
const id = generateRandomIID();
|
|
43
|
+
const existing = await mongoose.models.thread.findOne({ iid: id });
|
|
44
|
+
if (!existing) {
|
|
45
|
+
this.iid = id;
|
|
46
|
+
unique = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
next();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
ThreadSchema.index({ iid: 1 }, { unique: true });
|
|
54
|
+
|
|
55
|
+
const Thread = mongoose.models.thread || model<IThread>("thread", ThreadSchema);
|
|
56
|
+
|
|
57
|
+
export default Thread;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
|
+
|
|
4
|
+
export interface IThreadMessage extends Document {
|
|
5
|
+
iid: string;
|
|
6
|
+
organization: mongoose.Schema.Types.ObjectId;
|
|
7
|
+
thread: mongoose.Schema.Types.ObjectId;
|
|
8
|
+
status: string;
|
|
9
|
+
user: mongoose.Schema.Types.ObjectId;
|
|
10
|
+
message: mongoose.Schema.Types.Mixed;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const ThreadMessageSchema = new Schema<IThreadMessage>(
|
|
14
|
+
{
|
|
15
|
+
iid: {
|
|
16
|
+
type: String,
|
|
17
|
+
trim: true,
|
|
18
|
+
},
|
|
19
|
+
organization: {
|
|
20
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
21
|
+
ref: "organization",
|
|
22
|
+
default: null,
|
|
23
|
+
},
|
|
24
|
+
thread: {
|
|
25
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
26
|
+
ref: "thread",
|
|
27
|
+
default: null,
|
|
28
|
+
},
|
|
29
|
+
user: {
|
|
30
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
31
|
+
ref: "user",
|
|
32
|
+
default: null,
|
|
33
|
+
},
|
|
34
|
+
status: {
|
|
35
|
+
type: String,
|
|
36
|
+
enum: ["pending", "success", "failed"],
|
|
37
|
+
default: "pending",
|
|
38
|
+
},
|
|
39
|
+
message: {
|
|
40
|
+
type: mongoose.Schema.Types.Mixed,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
timestamps: true,
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
ThreadMessageSchema.pre('save', async function(next) {
|
|
49
|
+
if (!this.iid) {
|
|
50
|
+
let unique = false;
|
|
51
|
+
while (!unique) {
|
|
52
|
+
const id = generateRandomIID();
|
|
53
|
+
const existing = await mongoose.models.threadmessage.findOne({ iid: id });
|
|
54
|
+
if (!existing) {
|
|
55
|
+
this.iid = id;
|
|
56
|
+
unique = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
next();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
ThreadMessageSchema.index({ iid: 1 }, { unique: true });
|
|
64
|
+
|
|
65
|
+
const ThreadMessage = mongoose.models.threadmessage || model<IThreadMessage>("threadmessage", ThreadMessageSchema);
|
|
66
|
+
|
|
67
|
+
export default ThreadMessage;
|
package/src/models/User.ts
CHANGED
|
@@ -1,70 +1,48 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID, RolesConstants } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IUser extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
name: string;
|
|
5
7
|
email: string;
|
|
8
|
+
image: string;
|
|
9
|
+
client: mongoose.Schema.Types.ObjectId[];
|
|
6
10
|
password: string;
|
|
7
11
|
token: string;
|
|
8
|
-
role?: mongoose.Schema.Types.ObjectId[];
|
|
9
12
|
deactivated: boolean;
|
|
10
|
-
client?: mongoose.Schema.Types.ObjectId[];
|
|
11
13
|
twoFactor: boolean;
|
|
12
|
-
|
|
13
|
-
updatedAt: Date;
|
|
14
|
+
emailVerified: boolean;
|
|
14
15
|
resetLink: string;
|
|
15
|
-
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
16
16
|
bigqueryToken: string;
|
|
17
17
|
expirybqToken: string;
|
|
18
18
|
refreshToken: string;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
isSSOUser: boolean;
|
|
22
|
+
role: mongoose.Schema.Types.ObjectId[] | null;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
const UserSchema = new Schema<IUser>(
|
|
22
26
|
{
|
|
27
|
+
iid: { type: String, unique: true, default: () => generateRandomIID() },
|
|
23
28
|
name: String,
|
|
24
|
-
email: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
password: {
|
|
30
|
-
type: String,
|
|
31
|
-
required: true,
|
|
32
|
-
},
|
|
29
|
+
email: { type: String, unique: true, required: true },
|
|
30
|
+
client: { type: [mongoose.Schema.Types.ObjectId], ref: "client", default: null },
|
|
31
|
+
password: { type: String, required: true },
|
|
32
|
+
image: String,
|
|
33
33
|
token: String,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
deactivated: {
|
|
39
|
-
type: Boolean,
|
|
40
|
-
default: false,
|
|
41
|
-
},
|
|
42
|
-
client: {
|
|
43
|
-
type: [mongoose.Schema.Types.ObjectId],
|
|
44
|
-
ref: "client",
|
|
45
|
-
default: null,
|
|
46
|
-
},
|
|
47
|
-
twoFactor: {
|
|
48
|
-
type: Boolean,
|
|
49
|
-
default: false,
|
|
50
|
-
},
|
|
51
|
-
organizationId: {
|
|
52
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
53
|
-
ref: "organization",
|
|
54
|
-
default: null,
|
|
55
|
-
},
|
|
34
|
+
deactivated: { type: Boolean, default: false },
|
|
35
|
+
twoFactor: { type: Boolean, default: false },
|
|
36
|
+
emailVerified: { type: Boolean, default: false },
|
|
37
|
+
resetLink: String,
|
|
56
38
|
bigqueryToken: String,
|
|
57
39
|
expirybqToken: String,
|
|
58
40
|
refreshToken: String,
|
|
41
|
+
isSSOUser: { type: Boolean, default: false },
|
|
42
|
+
role: { type: [mongoose.Schema.Types.ObjectId], ref: "role", default: null },
|
|
59
43
|
},
|
|
60
|
-
{
|
|
61
|
-
timestamps: true,
|
|
62
|
-
}
|
|
44
|
+
{ timestamps: true }
|
|
63
45
|
);
|
|
64
46
|
|
|
65
|
-
// Add compound indexes for common query patterns
|
|
66
|
-
UserSchema.index({ organizationId: 1, role: 1 });
|
|
67
|
-
UserSchema.index({ organizationId: 1, client: 1 });
|
|
68
|
-
|
|
69
47
|
const User = mongoose.models.user || model<IUser>("user", UserSchema);
|
|
70
48
|
export default User;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
|
+
|
|
4
|
+
export interface IUserIdentity extends Document {
|
|
5
|
+
iid: string;
|
|
6
|
+
user: mongoose.Schema.Types.ObjectId;
|
|
7
|
+
provider: "google" | "microsoft" | "github" | "facebook" | "apple";
|
|
8
|
+
providerUserId: string;
|
|
9
|
+
email: string;
|
|
10
|
+
metadata?: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const UserIdentitySchema = new Schema<IUserIdentity>(
|
|
14
|
+
{
|
|
15
|
+
iid: { type: String, unique: true, default: () => generateRandomIID() },
|
|
16
|
+
user: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
|
|
17
|
+
email: { type: String, unique: true, required: true },
|
|
18
|
+
providerUserId: { type: String, required: true },
|
|
19
|
+
provider: { type: String, enum: ["google", "microsoft", "github", "facebook", "apple"], required: true },
|
|
20
|
+
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
|
21
|
+
},
|
|
22
|
+
{ timestamps: true }
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const UserIdentity = mongoose.models.useridentity || model<IUserIdentity>("useridentity", UserIdentitySchema);
|
|
26
|
+
export default UserIdentity;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import mongoose, { model, Schema } from "mongoose";
|
|
2
|
+
import { generateRandomIID } from "../constant";
|
|
3
|
+
|
|
4
|
+
export interface IUserOrganization extends Document {
|
|
5
|
+
iid: string;
|
|
6
|
+
user: mongoose.Schema.Types.ObjectId;
|
|
7
|
+
organization: mongoose.Schema.Types.ObjectId;
|
|
8
|
+
role: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const UserOrganizationSchema = new Schema<IUserOrganization>(
|
|
12
|
+
{
|
|
13
|
+
iid: { type: String, unique: true, default: () => generateRandomIID() },
|
|
14
|
+
user: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
|
|
15
|
+
organization: { type: mongoose.Schema.Types.ObjectId, ref: "organization", required: true },
|
|
16
|
+
role: { type: String, enum: ["owner", "admin", "member"], default: "member" }
|
|
17
|
+
},
|
|
18
|
+
{ timestamps: true }
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
UserOrganizationSchema.index({ user: 1, organization: 1 }, { unique: true });
|
|
22
|
+
const UserOrganization = mongoose.models.userorganization || model<IUserOrganization>("userorganization", UserOrganizationSchema);
|
|
23
|
+
export default UserOrganization;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
+
import { generateRandomIID, PackageFeaturesConstants } from "../constant";
|
|
2
3
|
|
|
3
4
|
export interface IUserPermission extends Document {
|
|
5
|
+
iid: string;
|
|
4
6
|
userId: mongoose.Schema.Types.ObjectId;
|
|
5
7
|
clientId: mongoose.Schema.Types.ObjectId;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
insights: boolean;
|
|
10
|
-
documentsAndLinks: boolean;
|
|
11
|
-
cvrReports: boolean;
|
|
12
|
-
abTesting: boolean;
|
|
13
|
-
abTestingDefault: boolean;
|
|
14
|
-
manageExperiments: boolean;
|
|
15
|
-
preCalculations: boolean;
|
|
16
|
-
}
|
|
8
|
+
organizationId: mongoose.Schema.Types.ObjectId;
|
|
9
|
+
role: string;
|
|
10
|
+
permissions: mongoose.Schema.Types.Mixed;
|
|
17
11
|
createdAt: Date;
|
|
18
12
|
updatedAt: Date;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
const UserPermissionSchema = new Schema<IUserPermission>({
|
|
16
|
+
iid: {
|
|
17
|
+
type: String,
|
|
18
|
+
unique: true,
|
|
19
|
+
default: () => generateRandomIID()
|
|
20
|
+
},
|
|
22
21
|
userId: {
|
|
23
22
|
type: mongoose.Schema.Types.ObjectId,
|
|
24
23
|
ref: "user",
|
|
@@ -29,17 +28,28 @@ const UserPermissionSchema = new Schema<IUserPermission>({
|
|
|
29
28
|
ref: "client",
|
|
30
29
|
required: true,
|
|
31
30
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
dashboard: { type: Boolean, default: true },
|
|
31
|
+
role: {
|
|
32
|
+
type: String,
|
|
33
|
+
enum: ["member", "admin", "owner"],
|
|
34
|
+
default: "member",
|
|
35
|
+
},
|
|
36
|
+
organizationId: {
|
|
37
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
38
|
+
ref: "organization",
|
|
39
|
+
required: true,
|
|
42
40
|
},
|
|
41
|
+
permissions: { type: mongoose.Schema.Types.Mixed, required: true, default: PackageFeaturesConstants },
|
|
42
|
+
// permissions: {
|
|
43
|
+
// abTestingDefault: { type: Boolean, default: true },
|
|
44
|
+
// abTesting: { type: Boolean, default: false },
|
|
45
|
+
// preCalculations: { type: Boolean, default: false },
|
|
46
|
+
// reporting: { type: Boolean, default: true },
|
|
47
|
+
// insights: { type: Boolean, default: true },
|
|
48
|
+
// documentsAndLinks: { type: Boolean, default: true },
|
|
49
|
+
// cvrReports: { type: Boolean, default: true },
|
|
50
|
+
// manageExperiments: { type: Boolean, default: false },
|
|
51
|
+
// dashboard: { type: Boolean, default: true },
|
|
52
|
+
// },
|
|
43
53
|
},
|
|
44
54
|
{
|
|
45
55
|
timestamps: true,
|
package/src/models/QueryLog.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
-
|
|
3
|
-
export interface IQueryLog extends Document {
|
|
4
|
-
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
5
|
-
query: string;
|
|
6
|
-
timeTaken: number;
|
|
7
|
-
user?: mongoose.Schema.Types.ObjectId;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const QueryLogSchema = new Schema<IQueryLog>(
|
|
11
|
-
{
|
|
12
|
-
organizationId: {
|
|
13
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
14
|
-
ref: "organization",
|
|
15
|
-
default: null,
|
|
16
|
-
},
|
|
17
|
-
query: {
|
|
18
|
-
type: String,
|
|
19
|
-
},
|
|
20
|
-
timeTaken: {
|
|
21
|
-
type: Number,
|
|
22
|
-
},
|
|
23
|
-
user: {
|
|
24
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
25
|
-
ref: "user",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
timestamps: true,
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const QueryLog = mongoose.models.querylog || model<IQueryLog>("querylog", QueryLogSchema);
|
|
34
|
-
|
|
35
|
-
export default QueryLog;
|
package/src/models/Segment.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import mongoose, { Document, Schema, model } from "mongoose";
|
|
2
|
-
|
|
3
|
-
export interface ISegment extends Document {
|
|
4
|
-
name?: string;
|
|
5
|
-
key?: string;
|
|
6
|
-
values?: string;
|
|
7
|
-
segmentType?: string;
|
|
8
|
-
client?: mongoose.Schema.Types.ObjectId;
|
|
9
|
-
published?: boolean;
|
|
10
|
-
organizationId?: mongoose.Schema.Types.ObjectId;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const SegmentSchema = new Schema<ISegment>(
|
|
14
|
-
{
|
|
15
|
-
organizationId: {
|
|
16
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
17
|
-
ref: "organization",
|
|
18
|
-
default: null,
|
|
19
|
-
},
|
|
20
|
-
name: {
|
|
21
|
-
type: String,
|
|
22
|
-
},
|
|
23
|
-
key: {
|
|
24
|
-
type: String,
|
|
25
|
-
},
|
|
26
|
-
values: {
|
|
27
|
-
type: String,
|
|
28
|
-
},
|
|
29
|
-
segmentType: {
|
|
30
|
-
type: String,
|
|
31
|
-
default: "general",
|
|
32
|
-
},
|
|
33
|
-
client: {
|
|
34
|
-
type: [mongoose.Schema.Types.ObjectId],
|
|
35
|
-
ref: "client",
|
|
36
|
-
default: null,
|
|
37
|
-
},
|
|
38
|
-
published: {
|
|
39
|
-
type: Boolean,
|
|
40
|
-
default: true,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
timestamps: true,
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const Segment = mongoose.models.segment || model<ISegment>("segment", SegmentSchema);
|
|
49
|
-
|
|
50
|
-
export default Segment;
|