53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
// src/models/web-visit.ts
|
|
// Copyright (C) 2026 Robert Colbert <rob.colbert@openplatform.us>
|
|
// All Rights Reserved
|
|
|
|
import { Schema, Types, Document, model } from "mongoose";
|
|
|
|
import { DtpLog } from "../lib/log.js";
|
|
import { IUser } from "./user.js";
|
|
const log = new DtpLog({
|
|
name: "WebVisitModel",
|
|
slug: "webVisit",
|
|
});
|
|
|
|
export interface IWebVisit extends Document {
|
|
_id: Types.ObjectId;
|
|
created: Date;
|
|
url: string;
|
|
user?: IUser | Types.ObjectId;
|
|
userAgent?: string;
|
|
referrer?: string;
|
|
ipAddress?: string;
|
|
country?: string;
|
|
region?: string;
|
|
eu: boolean;
|
|
timezone?: string;
|
|
city?: string;
|
|
latitude?: number;
|
|
longitude?: number;
|
|
metroCode?: number;
|
|
}
|
|
export const WebVisitSchema = new Schema<IWebVisit>({
|
|
created: { type: Date, default: Date.now },
|
|
url: { type: String, required: true },
|
|
user: { type: Types.ObjectId, index: 1, ref: "User" },
|
|
userAgent: { type: String },
|
|
referrer: { type: String },
|
|
ipAddress: { type: String },
|
|
country: { type: String },
|
|
region: { type: String },
|
|
eu: { type: Boolean, default: false },
|
|
timezone: { type: String },
|
|
city: { type: String },
|
|
latitude: { type: Number },
|
|
longitude: { type: Number },
|
|
metroCode: { type: Number },
|
|
});
|
|
export const WebVisit = model<IWebVisit>("WebVisit", WebVisitSchema);
|
|
|
|
(async () => {
|
|
log.info("Syncing indexes...");
|
|
await WebVisit.syncIndexes();
|
|
})();
|