mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add shared
This commit is contained in:
22
shared/schema/ProjectSchema.ts
Normal file
22
shared/schema/ProjectSchema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TProject = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
owner: Schema.Types.ObjectId,
|
||||
name: string,
|
||||
premium: boolean,
|
||||
premium_type?: number,
|
||||
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 },
|
||||
premium_expire_at: { type: Date },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
export const ProjectModel = model<TProject>('projects', ProjectSchema);
|
||||
26
shared/schema/ProjectsCounts.ts
Normal file
26
shared/schema/ProjectsCounts.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TProjectCount = {
|
||||
_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 ProjectCountSchema = new Schema<TProjectCount>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
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 ProjectCountModel = model<TProjectCount>('project_counts', ProjectCountSchema);
|
||||
22
shared/schema/UserSchema.ts
Normal file
22
shared/schema/UserSchema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { model, Schema } from 'mongoose';
|
||||
|
||||
export type TUser = {
|
||||
email: string,
|
||||
name: string,
|
||||
given_name: string,
|
||||
locale: string,
|
||||
picture: string,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const UserSchema = new Schema<TUser>({
|
||||
email: { type: String, unique: true, index: 1 },
|
||||
name: String,
|
||||
given_name: String,
|
||||
locale: String,
|
||||
picture: String,
|
||||
created_at: { type: Date, default: () => Date.now() }
|
||||
})
|
||||
|
||||
export const UserModel = model<TUser>('users', UserSchema);
|
||||
|
||||
14
shared/schema/UserSettings.ts
Normal file
14
shared/schema/UserSettings.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TUserSettings = {
|
||||
user_id: Schema.Types.ObjectId,
|
||||
active_project_id: Schema.Types.ObjectId
|
||||
}
|
||||
|
||||
const UserSettingsSchema = new Schema<TUserSettings>({
|
||||
user_id: { type: Types.ObjectId, unique: true, index: 1 },
|
||||
active_project_id: Schema.Types.ObjectId,
|
||||
});
|
||||
|
||||
export const UserSettingsModel = model<TUserSettings>('user_settings', UserSettingsSchema);
|
||||
|
||||
20
shared/schema/ai/AiChatSchema.ts
Normal file
20
shared/schema/ai/AiChatSchema.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { model, Schema } from 'mongoose';
|
||||
|
||||
export type TAiChatSchema = {
|
||||
_id: Schema.Types.ObjectId,
|
||||
project_id: Schema.Types.ObjectId,
|
||||
messages: any[],
|
||||
title: string,
|
||||
created_at: Date,
|
||||
updated_at: Date
|
||||
}
|
||||
|
||||
const AiChatSchema = new Schema<TAiChatSchema>({
|
||||
project_id: { type: Schema.Types.ObjectId, index: 1 },
|
||||
messages: [{ _id: false, type: Schema.Types.Mixed }],
|
||||
title: { type: String, required: true },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
updated_at: { type: Date, default: () => Date.now() },
|
||||
});
|
||||
|
||||
export const AiChatModel = model<TAiChatSchema>('ai_chats', AiChatSchema);
|
||||
18
shared/schema/broker/LimitNotifySchema.ts
Normal file
18
shared/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);
|
||||
18
shared/schema/metrics/EventSchema.ts
Normal file
18
shared/schema/metrics/EventSchema.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
export type TEvent = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
name: string,
|
||||
metadata: Record<string, string>,
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const EventSchema = new Schema<TEvent>({
|
||||
project_id: { type: Types.ObjectId, index: 1 },
|
||||
name: { type: String, required: true },
|
||||
metadata: Schema.Types.Mixed,
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
export const EventModel = model<TEvent>('events', EventSchema);
|
||||
|
||||
21
shared/schema/metrics/SessionSchema.ts
Normal file
21
shared/schema/metrics/SessionSchema.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { model, Schema, Types } from 'mongoose';
|
||||
|
||||
|
||||
export type TSession = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
session: 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 },
|
||||
duration: { type: Number, required: true, default: 0 },
|
||||
updated_at: { type: Date, default: () => Date.now() },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
export const SessionModel = model<TSession>('sessions', SessionSchema);
|
||||
|
||||
39
shared/schema/metrics/VisitSchema.ts
Normal file
39
shared/schema/metrics/VisitSchema.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { model, Schema } from 'mongoose';
|
||||
|
||||
export type TVisit = {
|
||||
project_id: Schema.Types.ObjectId,
|
||||
|
||||
browser: string,
|
||||
os: string,
|
||||
|
||||
continent: string,
|
||||
country: string,
|
||||
|
||||
device: string,
|
||||
|
||||
website: string,
|
||||
page: string,
|
||||
referrer: string,
|
||||
|
||||
created_at: Date
|
||||
}
|
||||
|
||||
const VisitSchema = new Schema<TVisit>({
|
||||
project_id: { type: Schema.Types.ObjectId, index: 1 },
|
||||
|
||||
browser: { type: String, required: true },
|
||||
os: { type: String, required: true },
|
||||
|
||||
continent: { type: String },
|
||||
country: { type: String },
|
||||
|
||||
device: { type: String },
|
||||
|
||||
website: { type: String, required: true },
|
||||
page: { type: String, required: true },
|
||||
referrer: { type: String, required: true },
|
||||
created_at: { type: Date, default: () => Date.now() },
|
||||
})
|
||||
|
||||
export const VisitModel = model<TVisit>('visits', VisitSchema);
|
||||
|
||||
Reference in New Issue
Block a user