军团:添加踢人解散退出,添加权限
This commit is contained in:
+28
-4
@@ -41,23 +41,35 @@ export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true, default: new Date() })
|
||||
refTimeWeekly: number;
|
||||
|
||||
public static async getMyAuth(roleId: string, userGuild?: UserGuildType) {
|
||||
public static async getMyAuth(roleId: string, guildCode?: string, userGuild?: UserGuildType) {
|
||||
let myGuild: UserGuildType;
|
||||
if(!userGuild) {
|
||||
myGuild = await this.getMyGuild(roleId, 'auth');
|
||||
} else {
|
||||
myGuild = userGuild;
|
||||
}
|
||||
|
||||
if(guildCode && userGuild && userGuild.guildCode != guildCode) {
|
||||
return GUILD_AUTH.OTHERS;
|
||||
}
|
||||
|
||||
return myGuild?myGuild.auth: GUILD_AUTH.OTHERS;
|
||||
}
|
||||
|
||||
public static async getMyGuild(roleId: string, select?: string) {
|
||||
|
||||
const myGuild: UserGuildType = await UserGuildModel.findOne({ roleId, status: USER_GUILD_STATUS.ON })
|
||||
.select(select)
|
||||
.lean();
|
||||
.select(select).lean();
|
||||
return myGuild;
|
||||
}
|
||||
|
||||
public static async getListByGuild(guildCode: string, select?: string) {
|
||||
const userGuilds: UserGuildType[] = await UserGuildModel.find({ guildCode, status: USER_GUILD_STATUS.ON })
|
||||
.select(select)
|
||||
.populate('role', 'roleId roleName ce headHid sHid lv title', 'Role')
|
||||
.lean();
|
||||
return userGuilds;
|
||||
}
|
||||
|
||||
public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) {
|
||||
const doc = new UserGuildModel();
|
||||
@@ -65,12 +77,24 @@ export default class UserGuild extends BaseModel {
|
||||
let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER;
|
||||
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth });
|
||||
delete update._id;
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
.select('honourWeekly job auth')
|
||||
.lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async dismiss(guildCode: string) {
|
||||
const result = await UserGuildModel.updateMany({guildCode}, {status: USER_GUILD_STATUS.DISMISSED});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 玩家退出公会
|
||||
public static async quit(guildCode: string, roleId: string) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ guildCode, roleId, status: USER_GUILD_STATUS.ON }, {status: USER_GUILD_STATUS.QUIT}, {new: true});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
Reference in New Issue
Block a user