后台:任务对应活动
This commit is contained in:
@@ -20,9 +20,9 @@ export default class Activity_Task_Point extends BaseModel {
|
||||
point: number; // 增加点数
|
||||
|
||||
//更新活动数据
|
||||
public static async updateData(taskType: number, taskId: number, activityId: number, point: number) {
|
||||
public static async updateData(taskType: number, taskId: number, activityId: number, point: number, uid = 1) {
|
||||
let result: ActivityTaskPointModelType = await ActivityTaskPointModel.findOneAndUpdate(
|
||||
{ taskType, taskId }, { $set: { activityId, point } }, { upsert: true, new: true }
|
||||
{ taskType, taskId, activityId }, { $set: { point, updatedBy: uid }, $setOnInsert: { createdBy: uid } }, { upsert: true, new: true }
|
||||
).lean(true);
|
||||
return result;
|
||||
}
|
||||
@@ -39,6 +39,44 @@ export default class Activity_Task_Point extends BaseModel {
|
||||
await ActivityTaskPointModel.deleteOne({ taskType, taskId, activityId });
|
||||
}
|
||||
|
||||
public static async createDataIfNotExist(taskType: number, taskId: number, activityId: number, point: number, uid = 1) {
|
||||
let result: ActivityTaskPointModelType = await ActivityTaskPointModel.findOneAndUpdate(
|
||||
{ taskType, taskId, activityId }, { $setOnInsert: { point, createdBy: uid, updatedBy: uid } }, { upsert: true, new: true }
|
||||
).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static getSearchObj(form: {taskType?: number, taskId?: number, activityId?: number}) {
|
||||
let searchObj = {};
|
||||
if(form['taskType']) searchObj['taskType'] = form.taskType;
|
||||
if(form['taskId']) searchObj['taskId'] = form.taskId;
|
||||
if(form['activityId']) searchObj['activityId'] = form.activityId;
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: {taskType?: number, taskId?: number, activityId?: number} = {}) {
|
||||
|
||||
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: ActivityTaskPointModelType[] = await ActivityTaskPointModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: {taskType?: number, taskId?: number, activityId?: number} = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await ActivityTaskPointModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const ActivityTaskPointModel = getModelForClass(Activity_Task_Point);
|
||||
|
||||
Reference in New Issue
Block a user