军团,创建查询列表,查询个人军团信息
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
import Role from './Role';
|
||||
import Role, { RoleType } from './Role';
|
||||
import Guild from './Guild';
|
||||
import { GUILD_AUTH, USER_GUILD_STATUS, GUILD_JOB } from '../consts';
|
||||
import { GUILD } from '../pubUtils/dicParam';
|
||||
|
||||
class ActiveRecord {
|
||||
@prop({ required: true })
|
||||
@@ -22,9 +23,6 @@ export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true })
|
||||
role: Ref<Role>;
|
||||
|
||||
@prop({ required: true })
|
||||
guild: Ref<Guild>;
|
||||
|
||||
@prop({ required: true, default: GUILD_AUTH.MEMBER, enum: GUILD_AUTH })
|
||||
auth: number;
|
||||
|
||||
@@ -45,18 +43,32 @@ export default class UserGuild extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: new Date() })
|
||||
refTimeWeekly: number;
|
||||
|
||||
public static async getMyGuild(roleId: string) {
|
||||
const myGuild: UserGuildType = await UserGuildModel.findOne({ roleId, status: USER_GUILD_STATUS.ON }).populate('guild').lean();
|
||||
return myGuild||{ auth: GUILD_AUTH.OTHERS };
|
||||
|
||||
public static async getMyAuth(roleId: string, userGuild?: UserGuildType) {
|
||||
let myGuild: UserGuildType;
|
||||
if(!userGuild) {
|
||||
myGuild = await this.getMyGuild(roleId, 'auth');
|
||||
} else {
|
||||
myGuild = userGuild;
|
||||
}
|
||||
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();
|
||||
return myGuild;
|
||||
}
|
||||
|
||||
|
||||
public static async createUserGuild(params: UserGuildCreateParam) {
|
||||
public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) {
|
||||
const doc = new UserGuildModel();
|
||||
const update = Object.assign(doc.toJSON(), params);
|
||||
let job = isLeader? GUILD_JOB.JIANGJUN: GUILD_JOB.SHIZHANG;
|
||||
let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER;
|
||||
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, job, auth });
|
||||
delete update._id;
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ guildCode: params.guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
.select('honour job auth')
|
||||
.lean();
|
||||
|
||||
@@ -68,4 +80,3 @@ export const UserGuildModel = getModelForClass(UserGuild);
|
||||
|
||||
export interface UserGuildType extends Pick<DocumentType<UserGuild>, keyof UserGuild> { };
|
||||
export type UserGuildUpdateParam = Partial<UserGuildType>; // 将所有字段变成可选项
|
||||
type UserGuildCreateParam = Pick<UserGuildType, 'guildCode'|'roleId'|'role'|'guild'|'auth'|'job'>;
|
||||
Reference in New Issue
Block a user