mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
refactoring dashboard
This commit is contained in:
20
shared_global/schema/ApiSettingsSchema.ts
Normal file
20
shared_global/schema/ApiSettingsSchema.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TApiSettings = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
apiKey: string,
|
||||
apiName: string,
|
||||
usage: number,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const ApiSettingsSchema = new Schema<TApiSettings>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
apiKey: { type: String, required: true },
|
||||
apiName: { type: String, required: true },
|
||||
usage: { type: Number, default: 0, required: true, },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
});
|
||||
|
||||
export const ApiSettingsModel = model<TApiSettings>('api_settings', ApiSettingsSchema);
|
||||
16
shared_global/schema/FeedbackSchema.ts
Normal file
16
shared_global/schema/FeedbackSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TFeedback = {
|
||||
user_id: Types.ObjectId,
|
||||
project_id: Types.ObjectId,
|
||||
text: string
|
||||
}
|
||||
|
||||
const FeedbackSchema = new Schema<TFeedback>({
|
||||
user_id: { type: Schema.Types.ObjectId, required: true },
|
||||
project_id: { type: Schema.Types.ObjectId, required: true },
|
||||
text: { type: String, required: true },
|
||||
});
|
||||
|
||||
export const FeedbackModel = model<TFeedback>('feedbacks', FeedbackSchema);
|
||||
|
||||
16
shared_global/schema/OnboardingSchema.ts
Normal file
16
shared_global/schema/OnboardingSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TOnboarding = {
|
||||
user_id: Types.ObjectId,
|
||||
analytics: string,
|
||||
job: string
|
||||
}
|
||||
|
||||
const OnboardingSchema = new Schema<TOnboarding>({
|
||||
user_id: { type: Schema.Types.ObjectId, required: true },
|
||||
analytics: { type: String, required: false },
|
||||
job: { type: String, required: false },
|
||||
});
|
||||
|
||||
export const OnboardingModel = model<TOnboarding>('onboardings', OnboardingSchema);
|
||||
|
||||
14
shared_global/schema/PasswordSchema.ts
Normal file
14
shared_global/schema/PasswordSchema.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TPassword = {
|
||||
email: string,
|
||||
password: string,
|
||||
}
|
||||
|
||||
const PasswordSchema = new Schema<TPassword>({
|
||||
email: { type: String, index: true, unique: true },
|
||||
password: { type: String },
|
||||
});
|
||||
|
||||
export const PasswordModel = model<TPassword>('passwords', PasswordSchema);
|
||||
|
||||
16
shared_global/schema/RegisterSchema.ts
Normal file
16
shared_global/schema/RegisterSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TRegister = {
|
||||
email: string,
|
||||
password: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const RegisterSchema = new Schema<TRegister>({
|
||||
email: { type: String },
|
||||
password: { type: String },
|
||||
created_at: { type: Date, default: () => Date.now() }
|
||||
});
|
||||
|
||||
export const RegisterModel = model<TRegister>('registers', RegisterSchema);
|
||||
|
||||
22
shared_global/schema/TeamMemberSchema.ts
Normal file
22
shared_global/schema/TeamMemberSchema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TeamMemberRole = 'ADMIN' | 'GUEST';
|
||||
|
||||
export type TTeamMember = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
user_id: Schema.Types.ObjectId,
|
||||
role: TeamMemberRole,
|
||||
pending: boolean,
|
||||
created_at: Date,
|
||||
}
|
||||
|
||||
const TeamMemberSchema = new Schema<TTeamMember>({
|
||||
project_id: { type: Types.ObjectId, index: true },
|
||||
user_id: { type: Types.ObjectId, index: true },
|
||||
role: { type: String, required: true },
|
||||
pending: { type: Boolean, required: true },
|
||||
created_at: { type: Date, required: true, default: () => Date.now() },
|
||||
});
|
||||
|
||||
export const TeamMemberModel = model<TTeamMember>('team_members', TeamMemberSchema);
|
||||
38
shared_global/schema/UserSchema.ts
Normal file
38
shared_global/schema/UserSchema.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TUser = {
|
||||
email: string,
|
||||
name: string,
|
||||
given_name: string,
|
||||
locale: string,
|
||||
picture: string,
|
||||
created_at: Date,
|
||||
google_tokens?: {
|
||||
refresh_token?: string;
|
||||
expiry_date?: number;
|
||||
access_token?: string;
|
||||
token_type?: string;
|
||||
id_token?: string;
|
||||
scope?: string;
|
||||
}
|
||||
}
|
||||
|
||||
const UserSchema = new Schema<TUser>({
|
||||
email: { type: String, unique: true, index: 1 },
|
||||
name: String,
|
||||
given_name: String,
|
||||
locale: String,
|
||||
picture: String,
|
||||
google_tokens: {
|
||||
refresh_token: String,
|
||||
expiry_date: Number,
|
||||
access_token: String,
|
||||
token_type: String,
|
||||
id_token: String,
|
||||
scope: String
|
||||
},
|
||||
created_at: { type: Date, default: () => Date.now() }
|
||||
})
|
||||
|
||||
export const UserModel = model<TUser>('users', UserSchema);
|
||||
|
||||
16
shared_global/schema/UserSettings.ts
Normal file
16
shared_global/schema/UserSettings.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TUserSettings = {
|
||||
user_id: Schema.Types.ObjectId,
|
||||
max_projects: number,
|
||||
active_project_id: Schema.Types.ObjectId
|
||||
}
|
||||
|
||||
const UserSettingsSchema = new Schema<TUserSettings>({
|
||||
user_id: { type: Types.ObjectId, unique: true, index: 1 },
|
||||
max_projects: { type: Number, default: 3 },
|
||||
active_project_id: Schema.Types.ObjectId,
|
||||
});
|
||||
|
||||
export const UserSettingsModel = model<TUserSettings>('user_settings', UserSettingsSchema);
|
||||
|
||||
26
shared_global/schema/ai/AiChatSchema.ts
Normal file
26
shared_global/schema/ai/AiChatSchema.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { model, Schema } from 'mongoose';
|
||||
|
||||
export type TAiChatSchema = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
messages: any[],
|
||||
status: string,
|
||||
completed: boolean,
|
||||
title: string,
|
||||
deleted: boolean,
|
||||
created_at: Date,
|
||||
updated_at: Date
|
||||
}
|
||||
|
||||
const AiChatSchema = new Schema<TAiChatSchema>({
|
||||
project_id: { type: Schema.Types.ObjectId, index: 1 },
|
||||
status: { type: String },
|
||||
completed: { type: Boolean },
|
||||
messages: [{ _id: false, type: Schema.Types.Mixed }],
|
||||
title: { type: String, required: true },
|
||||
deleted: { type: Boolean, default: false },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
updated_at: { type: Date, default: () => Date.now() },
|
||||
});
|
||||
|
||||
export const AiChatModel = model<TAiChatSchema>('ai_chats', AiChatSchema);
|
||||
16
shared_global/schema/anomalies/AnomalyDomainSchema.ts
Normal file
16
shared_global/schema/anomalies/AnomalyDomainSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TAnomalyDomain = {
|
||||
project_id: Schema.Types.ObjectId
|
||||
domain: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const AnomalyDomainSchema = new Schema<TAnomalyDomain>({
|
||||
project_id: { type: Types.ObjectId, required: true },
|
||||
domain: { type: String, required: true },
|
||||
created_at: { type: Date, required: true },
|
||||
})
|
||||
|
||||
export const AnomalyDomainModel = model<TAnomalyDomain>('anomaly_domains', AnomalyDomainSchema);
|
||||
16
shared_global/schema/anomalies/AnomalyEventsSchema.ts
Normal file
16
shared_global/schema/anomalies/AnomalyEventsSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TAnomalyEvents = {
|
||||
project_id: Schema.Types.ObjectId
|
||||
eventDate: Date,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const AnomalyEventsSchema = new Schema<TAnomalyEvents>({
|
||||
project_id: { type: Types.ObjectId, required: true },
|
||||
eventDate: { type: Date, required: true },
|
||||
created_at: { type: Date, required: true },
|
||||
})
|
||||
|
||||
export const AnomalyEventsModel = model<TAnomalyEvents>('anomaly_events', AnomalyEventsSchema);
|
||||
16
shared_global/schema/anomalies/AnomalyVisitSchema.ts
Normal file
16
shared_global/schema/anomalies/AnomalyVisitSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TAnomalyVisit = {
|
||||
project_id: Schema.Types.ObjectId
|
||||
visitDate: Date,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const AnomalyVisitSchema = new Schema<TAnomalyVisit>({
|
||||
project_id: { type: Types.ObjectId, required: true },
|
||||
visitDate: { type: Date, required: true },
|
||||
created_at: { type: Date, required: true },
|
||||
})
|
||||
|
||||
export const AnomalyVisitModel = model<TAnomalyVisit>('anomaly_visits', AnomalyVisitSchema);
|
||||
16
shared_global/schema/appsumo/AppsumoCodeSchema.ts
Normal file
16
shared_global/schema/appsumo/AppsumoCodeSchema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TAppsumoCode = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
code: string,
|
||||
used_at: Date,
|
||||
created_at?: Date,
|
||||
}
|
||||
|
||||
const AppsumoCodeSchema = new Schema<TAppsumoCode>({
|
||||
code: { type: String, index: 1 },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
used_at: { type: Date, required: false },
|
||||
});
|
||||
|
||||
export const AppsumoCodeModel = model<TAppsumoCode>('appsumo_codes', AppsumoCodeSchema);
|
||||
15
shared_global/schema/appsumo/AppsumoCodeTrySchema.ts
Normal file
15
shared_global/schema/appsumo/AppsumoCodeTrySchema.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TAppsumoCodeTry = {
|
||||
project_id: Types.ObjectId,
|
||||
codes: string[],
|
||||
valid_codes: string[],
|
||||
}
|
||||
|
||||
const AppsumoCodeTrySchema = new Schema<TAppsumoCodeTry>({
|
||||
project_id: { type: Schema.Types.ObjectId, required: true, unique: true, index: 1 },
|
||||
codes: [{ type: String }],
|
||||
valid_codes: [{ type: String }]
|
||||
});
|
||||
|
||||
export const AppsumoCodeTryModel = model<TAppsumoCodeTry>('appsumo_codes_tries', AppsumoCodeTrySchema);
|
||||
18
shared_global/schema/broker/LimitNotifySchema.ts
Normal file
18
shared_global/schema/broker/LimitNotifySchema.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TLimitNotify = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
limit1: boolean,
|
||||
limit2: boolean,
|
||||
limit3: boolean
|
||||
}
|
||||
|
||||
const LimitNotifySchema = new Schema<TLimitNotify>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
limit1: { type: Boolean },
|
||||
limit2: { type: Boolean },
|
||||
limit3: { type: Boolean }
|
||||
});
|
||||
|
||||
export const LimitNotifyModel = model<TLimitNotify>('limit_notifies', LimitNotifySchema);
|
||||
22
shared_global/schema/metrics/EventSchema.ts
Normal file
22
shared_global/schema/metrics/EventSchema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TEvent = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
name: string,
|
||||
metadata: Record<string, string>,
|
||||
session: string,
|
||||
flowHash: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const EventSchema = new Schema<TEvent>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
name: { type: String, required: true, index: 1 },
|
||||
metadata: Schema.Types.Mixed,
|
||||
session: { type: String, index: 1 },
|
||||
flowHash: { type: String },
|
||||
created_at: { type: Date, default: () => Date.now(), index: true },
|
||||
})
|
||||
|
||||
export const EventModel = model<TEvent>('events', EventSchema);
|
||||
|
||||
23
shared_global/schema/metrics/SessionSchema.ts
Normal file
23
shared_global/schema/metrics/SessionSchema.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TSession = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
session: string,
|
||||
flowHash: string,
|
||||
duration: number,
|
||||
updated_at: Date,
|
||||
created_at: Date,
|
||||
}
|
||||
|
||||
const SessionSchema = new Schema<TSession>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
session: { type: String, required: true, index: 1 },
|
||||
flowHash: { type: String },
|
||||
duration: { type: Number, required: true, default: 0 },
|
||||
updated_at: { type: Date, default: () => Date.now() },
|
||||
created_at: { type: Date, default: () => Date.now(), index: true },
|
||||
})
|
||||
|
||||
export const SessionModel = model<TSession>('sessions', SessionSchema);
|
||||
|
||||
45
shared_global/schema/metrics/VisitSchema.ts
Normal file
45
shared_global/schema/metrics/VisitSchema.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { model, Schema } from 'mongoose';
|
||||
|
||||
export type TVisit = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
|
||||
browser: string,
|
||||
os: string,
|
||||
|
||||
continent: string,
|
||||
country: string,
|
||||
|
||||
session: string,
|
||||
flowHash: string,
|
||||
device: string,
|
||||
|
||||
website: string,
|
||||
page: string,
|
||||
referrer: string,
|
||||
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const VisitSchema = new Schema<TVisit>({
|
||||
project_id: { type: Schema.Types.ObjectId, index: true },
|
||||
|
||||
browser: { type: String, required: true },
|
||||
os: { type: String, required: true },
|
||||
|
||||
continent: { type: String },
|
||||
country: { type: String },
|
||||
|
||||
session: { type: String },
|
||||
flowHash: { type: String },
|
||||
device: { type: String },
|
||||
|
||||
website: { type: String, required: true, index: true },
|
||||
page: { type: String, required: true },
|
||||
referrer: { type: String, required: true },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
VisitSchema.index({ project_id: 1, created_at: -1 });
|
||||
|
||||
export const VisitModel = model<TVisit>('visits', VisitSchema);
|
||||
|
||||
26
shared_global/schema/project/ProjectSchema.ts
Normal file
26
shared_global/schema/project/ProjectSchema.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TProject = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
owner: Schema.Types.ObjectId,
|
||||
name: string,
|
||||
premium: boolean,
|
||||
premium_type: number,
|
||||
customer_id: string,
|
||||
subscription_id: string,
|
||||
premium_expire_at: Date,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const ProjectSchema = new Schema<TProject>({
|
||||
owner: { type: Types.ObjectId, index: 1 },
|
||||
name: { type: String, required: true },
|
||||
premium: { type: Boolean, default: false },
|
||||
premium_type: { type: Number, default: 0 },
|
||||
customer_id: { type: String, required: true },
|
||||
subscription_id: { type: String, required: true },
|
||||
premium_expire_at: { type: Date, required: true },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
export const ProjectModel = model<TProject>('projects', ProjectSchema);
|
||||
20
shared_global/schema/project/ProjectSnapshot.ts
Normal file
20
shared_global/schema/project/ProjectSnapshot.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TProjectSnapshot = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
name: string,
|
||||
from: Date,
|
||||
to: Date,
|
||||
color: string
|
||||
}
|
||||
|
||||
const ProjectSnapshotSchema = new Schema<TProjectSnapshot>({
|
||||
project_id: { type: Types.ObjectId, index: true },
|
||||
name: { type: String, required: true },
|
||||
from: { type: Date, required: true },
|
||||
to: { type: Date, required: true },
|
||||
color: { type: String, required: true },
|
||||
});
|
||||
|
||||
export const ProjectSnapshotModel = model<TProjectSnapshot>('project_snapshots', ProjectSnapshotSchema);
|
||||
22
shared_global/schema/project/ProjectsCounts.ts
Normal file
22
shared_global/schema/project/ProjectsCounts.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TProjectCount = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
events: number,
|
||||
visits: number,
|
||||
sessions: number,
|
||||
lastRecheck?: Date,
|
||||
updated_at: Date
|
||||
}
|
||||
|
||||
const ProjectCountSchema = new Schema<TProjectCount>({
|
||||
project_id: { type: Types.ObjectId, index: true, unique: true },
|
||||
events: { type: Number, required: true, default: 0 },
|
||||
visits: { type: Number, required: true, default: 0 },
|
||||
sessions: { type: Number, required: true, default: 0 },
|
||||
lastRecheck: { type: Date },
|
||||
updated_at: { type: Date }
|
||||
}, { timestamps: { updatedAt: 'updated_at' } });
|
||||
|
||||
export const ProjectCountModel = model<TProjectCount>('project_counts', ProjectCountSchema);
|
||||
26
shared_global/schema/project/ProjectsLimits.ts
Normal file
26
shared_global/schema/project/ProjectsLimits.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TProjectLimit = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
events: number,
|
||||
visits: number,
|
||||
ai_messages: number,
|
||||
limit: number,
|
||||
ai_limit: number,
|
||||
billing_expire_at: Date,
|
||||
billing_start_at: Date,
|
||||
}
|
||||
|
||||
const ProjectLimitSchema = new Schema<TProjectLimit>({
|
||||
project_id: { type: Types.ObjectId, index: true, unique: true },
|
||||
events: { type: Number, required: true, default: 0 },
|
||||
visits: { type: Number, required: true, default: 0 },
|
||||
ai_messages: { type: Number, required: true, default: 0 },
|
||||
limit: { type: Number, required: true },
|
||||
ai_limit: { type: Number, required: true },
|
||||
billing_start_at: { type: Date, required: true },
|
||||
billing_expire_at: { type: Date, required: true },
|
||||
});
|
||||
|
||||
export const ProjectLimitModel = model<TProjectLimit>('project_limits', ProjectLimitSchema);
|
||||
Reference in New Issue
Block a user