mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
refactoring dashboard
This commit is contained in:
22
dashboard/shared/schema/metrics/EventSchema.ts
Normal file
22
dashboard/shared/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
dashboard/shared/schema/metrics/SessionSchema.ts
Normal file
23
dashboard/shared/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
dashboard/shared/schema/metrics/VisitSchema.ts
Normal file
45
dashboard/shared/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);
|
||||
|
||||
Reference in New Issue
Block a user