50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
|
|
/**
|
|||
|
|
* 访问日志模型
|
|||
|
|
* TypeGoose 定义,符合 Tailchat 插件标准模式
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import { db } from 'tailchat-server-sdk';
|
|||
|
|
const { getModelForClass, prop, modelOptions, TimeStamps, index } = db;
|
|||
|
|
|
|||
|
|
@modelOptions({ options: { customName: 'p_saleschat_accesslog' } })
|
|||
|
|
@index({ inviteCode: 1 })
|
|||
|
|
@index({ timestamp: 1 })
|
|||
|
|
@index({ inviteCode: 1, timestamp: -1 })
|
|||
|
|
export class AccessLog extends TimeStamps implements db.Base {
|
|||
|
|
_id: db.Types.ObjectId;
|
|||
|
|
id: string;
|
|||
|
|
|
|||
|
|
/** 邀请码 */
|
|||
|
|
@prop({ required: true })
|
|||
|
|
inviteCode: string;
|
|||
|
|
|
|||
|
|
/** 访客 ID */
|
|||
|
|
@prop()
|
|||
|
|
visitorId?: string;
|
|||
|
|
|
|||
|
|
/** 访问类型:click / scan / join */
|
|||
|
|
@prop({ required: true })
|
|||
|
|
accessType: 'click' | 'scan' | 'join';
|
|||
|
|
|
|||
|
|
/** 访问时间 */
|
|||
|
|
@prop({ default: () => new Date() })
|
|||
|
|
timestamp: Date;
|
|||
|
|
|
|||
|
|
/** IP 地址 */
|
|||
|
|
@prop()
|
|||
|
|
ipAddress?: string;
|
|||
|
|
|
|||
|
|
/** User-Agent */
|
|||
|
|
@prop()
|
|||
|
|
userAgent?: string;
|
|||
|
|
|
|||
|
|
/** 来源 */
|
|||
|
|
@prop()
|
|||
|
|
referrer?: string;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export type AccessLogDocument = db.DocumentType<AccessLog>;
|
|||
|
|
const model = getModelForClass(AccessLog);
|
|||
|
|
export type AccessLogModel = typeof model;
|
|||
|
|
export default model;
|