后台:大区列表

This commit is contained in:
luying
2021-12-04 18:47:01 +08:00
parent b8fff7cc83
commit 9e15773055
11 changed files with 282 additions and 227 deletions

View File

@@ -2,6 +2,7 @@ import { COUNTER } from './../consts';
import { CounterModel } from './Counter';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';
import ServerStategy from './ServerStategy';
/**
@@ -31,15 +32,32 @@ export default class Region extends BaseModel {
@prop({ required: true })
gamePort: number; // 长链接地址
public static async createNewRegion(params: RegionUpdate) {
@prop({ required: true })
latestServer: number; // 最新服
@prop({ required: true })
serverCount: number; // 总数
@prop({ required: true })
remark: string; // 备注
@prop({ required: true, type: () => ServerStategy, _id: false })
stategy: ServerStategy; // 策略配置
public static async createNewRegion(params: RegionUpdate, uid = 1) {
let id = await CounterModel.getNewCounter(COUNTER.REGION);
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $setOnInsert: params }, { new: true, upsert: true }).lean();
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $setOnInsert: { ...params, createdBy: uid}, $set: { updatedBy: uid } }, { new: true, upsert: true }).lean();
return rec;
}
public static async updateRegion(id: number, params: RegionUpdate, uid = 1) {
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $set: { ...params, updatedBy: uid } }, { new: true }).lean();
return rec;
}
public static async getAllRegion() {
const rec: RegionType[] = await RegionModel.find().select('-_id').lean();
const rec: RegionType[] = await RegionModel.find().select('-_id -stategty').lean();
return rec;
}