后台:公告列表
This commit is contained in:
@@ -39,7 +39,8 @@ export const COUNTER = {
|
||||
SERVER_GROUP: { name: 'group', def: 1 },
|
||||
SERVER_BY_TYPE: { name: 'serverby', def: 1 },
|
||||
SERVER: { name: 'server', def: 1 },
|
||||
ACTIVITY_GROUP_TYPE: { name: 'actgrptype', def: 1 }
|
||||
ACTIVITY_GROUP_TYPE: { name: 'actgrptype', def: 1 },
|
||||
NOTICE: { name: 'notice', def: 1 }
|
||||
};
|
||||
|
||||
export const DEFAULT_HEROES = [19, 53, 46, 40, 22, 56, 32, 28, 18];
|
||||
|
||||
+48
-1
@@ -1,7 +1,8 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { formatTime } from '../pubUtils/timeUtil';
|
||||
import { TIME_FORMAT } from '../consts'
|
||||
import { TIME_FORMAT, COUNTER } from '../consts'
|
||||
import { CounterModel } from './Counter';
|
||||
|
||||
/**
|
||||
* 游戏字段接口
|
||||
@@ -54,6 +55,51 @@ export default class Notice extends BaseModel {
|
||||
.lean({ virtuals: true });
|
||||
return notices;
|
||||
}
|
||||
|
||||
public static async updateNotice(id: number|string, values: NoticeTypeParam, uid = 1) {
|
||||
if(id == 'new') {
|
||||
id = await CounterModel.getNewCounter(COUNTER.NOTICE);
|
||||
}
|
||||
delete values.id;
|
||||
let rec: NoticeType = await NoticeModel.findOneAndUpdate({ id }, { $set: {...values, updatedBy: uid}, $setOnInsert: { createdBy: uid } },
|
||||
{ new: true, upsert: true }).lean(true);
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async delNotice(id: number) {
|
||||
let rec: NoticeType = await NoticeModel.findOneAndDelete({ id }).lean();
|
||||
return rec
|
||||
}
|
||||
|
||||
private static getSearchObj(form: { type?: number, content?: string }) {
|
||||
let searchObj = {};
|
||||
if(form['type']) searchObj['type'] = form.type;
|
||||
if(form['content']) searchObj['content'] = { $regex: new RegExp(form.content.toString(), 'i') };
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: { type?: number, content?: string } = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
let sort = {};
|
||||
if(sortField && sortOrder) {
|
||||
if(sortOrder == 'ascend') {
|
||||
sort[sortField] = 1;
|
||||
} else if (sortOrder == 'descend') {
|
||||
sort[sortField] = -1;
|
||||
}
|
||||
}
|
||||
const result: NoticeType[] = await NoticeModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: { type?: number, content?: string } = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await NoticeModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const NoticeModel = getModelForClass(Notice);
|
||||
@@ -61,3 +107,4 @@ export const NoticeModel = getModelForClass(Notice);
|
||||
export interface NoticeType extends Pick<DocumentType<Notice>, keyof Notice>{
|
||||
id: number;
|
||||
};
|
||||
export type NoticeTypeParam = Partial<NoticeType>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user