添加数据库类型别名

This commit is contained in:
luying
2020-12-15 18:08:29 +08:00
parent 1565dd206a
commit 2d774fc0e4
38 changed files with 393 additions and 321 deletions

View File

@@ -1,5 +1,5 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop } from '@typegoose/typegoose';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
const moment = require('moment');
/**
@@ -27,16 +27,17 @@ export default class Sms extends BaseModel {
countToday: number;
public static async findByTel(tel: string, lean = true) {
const sms = await smsModel.findOne({ tel }).lean(lean);
const sms: SmsType = await smsModel.findOne({ tel }).lean(lean);
return sms;
}
public static async updateByTel(tel: string, code: string, used: boolean, updateTime: Date, countToday: number, lean = true) {
await smsModel.findOneAndUpdate({ tel }, { code, used, updateTime, countToday }, { upsert: true }).lean(lean);
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { code, used, updateTime, countToday }, { upsert: true }).lean(lean);
return sms;
}
public static async validateSms(tel: string, code: string, lean = true) {
const record = await smsModel.findOneAndUpdate({ tel, code, used: false }, { used: true }).lean(lean);
const record: SmsType = await smsModel.findOneAndUpdate({ tel, code, used: false }, { used: true }).lean(lean);
return !!record;
}
@@ -63,3 +64,5 @@ export default class Sms extends BaseModel {
}
export const smsModel = getModelForClass(Sms);
export interface SmsType extends Pick<DocumentType<Sms>, keyof Sms>{};