import BaseModel from './BaseModel'; import { prop, DocumentType, getModelForClass } from '@typegoose/typegoose'; import { WHITE_LIST_TYPE } from '../consts'; export default class WhiteList extends BaseModel { @prop({ required: true, enum: WHITE_LIST_TYPE }) type: WHITE_LIST_TYPE; // 区号 @prop({ required: true }) str: string; // ip或手机号 public static async checkIp(ip: string) { const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.IP, str: ip }).lean(); return rec; } public static async checkTel(tel: string) { const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.TEL, str: tel }).lean(); return rec; } } export const WhiteListModel = getModelForClass(WhiteList); export interface WhiteListModelType extends Pick, keyof WhiteList> { } export type WhiteListModelTypeParam = Partial; // 将所有字段变成可选项