// src/models/web-visit.ts // Copyright (C) 2026 Robert Colbert // 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({ 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("WebVisit", WebVisitSchema); (async () => { log.info("Syncing indexes..."); await WebVisit.syncIndexes(); })();