add shared

This commit is contained in:
Litlyx
2024-06-01 15:27:21 +02:00
parent 9caec3b92b
commit 75f0787c3b
23 changed files with 866 additions and 0 deletions

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);

View 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);