军团:邀请被邀请

This commit is contained in:
luying
2021-01-20 19:30:11 +08:00
parent d9eda973ed
commit 89c7b117b2
8 changed files with 171 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
import Role, { RoleType } from './Role';
import Guild, { GuildType } from './Guild';
import { GUILD_AUTH, USER_GUILD_STATUS, GUILD_JOB, GUILD_APPLY_STATUS, GUILD_APPLY_TYPE, GUILD_PER_PAGE, GUILD_STATUS } from '../consts';
import { GUILD_APPLY_TYPE, GUILD_PER_PAGE } from '../consts';
import { genCode } from '../pubUtils/util';
@index({ roleId: 1 })
@@ -25,6 +25,7 @@ export default class UserGuildApply extends BaseModel {
@prop({ required: true, enum: GUILD_APPLY_TYPE, select: false})
type: number;
// 创建申请或邀请
public static async createUserGuildApply(role: RoleType, guild: GuildType, type: number) {
const applyCode = genCode(10);
const doc = new UserGuildApplyModel();
@@ -35,36 +36,43 @@ export default class UserGuildApply extends BaseModel {
return result;
}
// 删除玩家发出的所有申请
public static async deleteApply(roleId: string) {
const result = await UserGuildApplyModel.deleteMany({ roleId, type: GUILD_APPLY_TYPE.APPLY });
return result;
}
// 删除公会收到的所有申请
public static async deleteApplyByGuild(guildCode: string) {
const result = await UserGuildApplyModel.deleteMany({ guildCode, type: GUILD_APPLY_TYPE.APPLY });
return result;
}
// 根据唯一code批量删除
public static async deleteApplyByApplyCode(applyCodeList: string[]) {
const result = await UserGuildApplyModel.deleteMany({ applyCode: { $in: applyCodeList}, type: GUILD_APPLY_TYPE.APPLY });
return result;
}
// 根绝唯一code查询申请或邀请
public static async findByCode(applyCode: string) {
const userGuildApply: UserGuildApplyType = await UserGuildApplyModel.findOne({ applyCode }).lean();
return userGuildApply;
}
// 查询用户的申请列表
public static async findApplyByRole(roleId: string) {
const userGuildApply: UserGuildApplyType[] = await UserGuildApplyModel.find({ roleId, type: GUILD_APPLY_TYPE.APPLY }).lean();
return userGuildApply;
}
// 根据唯一code查询申请或邀请
public static async getListByApplyCode(applyCodeList: string[]) {
const userGuildApply: UserGuildApplyType[] = await UserGuildApplyModel.find({ applyCode: { $in: applyCodeList}, type: GUILD_APPLY_TYPE.APPLY }).lean();
return userGuildApply;
}
// 查询公会收到的申请
public static async getListByGuild(code: string, lastApplyCode: string) {
let condition = { guildCode: code, type: GUILD_APPLY_TYPE.APPLY };
if(lastApplyCode) {
@@ -78,6 +86,30 @@ export default class UserGuildApply extends BaseModel {
.limit(GUILD_PER_PAGE).lean();
return list
}
// 查询玩家的邀请列表
public static async getListByRole(roleId: string, lastApplyCode: string) {
let condition = { roleId, type: GUILD_APPLY_TYPE.INVITE };
if(lastApplyCode) {
const lastApply = await this.findByCode(lastApplyCode);
condition["createdAt"] = { $lt: lastApply.createdAt };
}
const list: UserGuildApplyType[] = await UserGuildApplyModel.find(condition)
.sort({ createdAt: -1 })
.select('applyCode guild')
.populate({
path: 'guild',
select: 'code icon name lv memberCnt leader ceLimit',
model: 'Guild',
populate: {
path: 'leader',
select: 'roleName',
model: 'Role'
}
})
.limit(GUILD_PER_PAGE).lean();
return list
}
}
export const UserGuildApplyModel = getModelForClass(UserGuildApply);