Files
ZYZ/shared/db/ActivityGrowthPoint.ts
2021-05-26 17:35:56 +08:00

41 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 活动系统 - 成长任务活动积分点兑换奖励
*/
@index({ roleId: 1 })
export default class Activity_Growth_Point extends BaseModel {
@prop({ required: true })
serverId: number; // 活动Id
@prop({ required: true })
activityId: number; // 活动Id
@prop({ required: true })
roleId: string; // 用户Id
@prop({ required: true })
ids: number[]; // id数组领取过的奖励id
//当日奖章领取记录
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number) {
let result: ActivityGrowthPointModelType = await ActivityGrowthPointModel.findOneAndUpdate({ serverId, roleId, activityId },
{ $push: { ids: id } }, { upsert: true, new: true }).lean(true);
return result;
}
//根据活动id查询活动数据
public static async findData(serverId: number, activityId: number, roleId: string) {
let result: ActivityGrowthPointModelType = await ActivityGrowthPointModel.findOne({ serverId, roleId, activityId }).lean(true);
return result;
}
//删除活动领取记录
public static async deleteActivity(serverId: number, activityId: number, roleId: string) {
await ActivityGrowthPointModel.deleteMany({ serverId, roleId, activityId });
}
}
export const ActivityGrowthPointModel = getModelForClass(Activity_Growth_Point);
export interface ActivityGrowthPointModelType extends Pick<DocumentType<Activity_Growth_Point>, keyof Activity_Growth_Point> { }
export type ActivityGrowthPointModelTypeParam = Partial<ActivityGrowthPointModelType>; // 将所有字段变成可选项