拍卖行:简单数据库操作

This commit is contained in:
liangtongchuan
2021-03-16 12:24:35 +08:00
parent 8d071b4bac
commit 2bb852135d
2 changed files with 34 additions and 1 deletions

View File

@@ -1,13 +1,14 @@
import { BidRec } from './../domain/dbGeneral';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
/**
* 竞拍物品表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ code: 1 })
@index({ guildCode: 1 })
@index({ guildCode: 1, createdAt: -1 })
export default class Lot extends BaseModel {
@prop({ required: true, default: 0 })
auctionStage: number; // 0初始添加1军团拍卖2世界拍卖3拍卖结束
@@ -35,6 +36,23 @@ export default class Lot extends BaseModel {
begin: Date; // 竞拍开始时间
@prop({ required: true })
end: Date; // 竞拍结束时间
public static async createRec(data: LotParam) {
const code = genCode(8);
const docData = new LotModel();
const result: LotType = await LotModel.findOneAndUpdate({ code }, { ...docData.toJSON(), ...data, code }, { upsert: true, new: true }).select('-_id').lean();
return result;
}
public static async findLot(code: string) {
const result = await LotModel.findOne({ code }).select('-_id -__v').lean();
return result;
}
public static async findGuildLotsByTime(guildCode: string, time: Date) {
const results = await LotModel.find({ guildCode, createdAt: { $gte: time } }).select('-_id -__v').lean();
return results;
}
}
export const LotModel = getModelForClass(Lot);