Files
ZYZ/shared/db/WhiteList.ts
2021-07-27 18:02:11 +08:00

27 lines
1.0 KiB
TypeScript

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<DocumentType<WhiteList>, keyof WhiteList> { }
export type WhiteListModelTypeParam = Partial<WhiteListModelType>; // 将所有字段变成可选项