军团,创建查询列表,查询个人军团信息

This commit is contained in:
luying
2021-01-19 16:18:45 +08:00
parent 71c5182926
commit ee21a21e80
8 changed files with 220 additions and 97 deletions
@@ -4,10 +4,12 @@ import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB } from '../../../consts';
import { UserGuildModel } from '../../../db/UserGuild';
import { checkAuth } from '../../../services/guildService';
import { GuildModel } from '../../../db/Guild';
import { RoleModel } from '../../../db/Role';
import { RoleModel, RoleType } from '../../../db/Role';
import { GUILD } from '../../../pubUtils/dicParam';
import { handleCost } from '../../../services/rewardService';
import { getGoldObject } from '../../../pubUtils/itemUtils';
import { getSeconds } from '../../../pubUtils/timeUtil';
import { GuildListInfo } from '../../../pubUtils/interface';
export default function (app: Application) {
return new GuildHandler(app);
@@ -17,7 +19,7 @@ export class GuildHandler {
constructor(private app: Application) {
}
//TODO创建军团
// 创建军团
async createGuild(msg: { name: string, icon: number, notice: string }, session: BackendSession) {
const roleId = session.get('roleId');
@@ -25,7 +27,7 @@ export class GuildHandler {
const { name, icon, notice } = msg;
// 检查权限是否够,包括是否参过团
const { auth } = await UserGuildModel.getMyGuild(roleId);
const auth = await UserGuildModel.getMyAuth(roleId);
const checkResult = checkAuth(GUILD_OPERATE.CREATE_GUILD, auth);
if(!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
@@ -42,33 +44,63 @@ export class GuildHandler {
await handleCost(roleId, sid, [getGoldObject(GUILD.GUILD_CREATE_COST)]);
// 创建公会
const guild = await GuildModel.createGuild({ name, icon, notice, leader: role._id, members: [roleId], ce: role.ce });
const guild = await GuildModel.createGuild({ name, icon, notice }, role);
if(!guild) return resResult(STATUS.GUILD_CREATE_ERROR);
const userGuild = await UserGuildModel.createUserGuild({ guildCode: guild.code, roleId, role: role._id, guild: guild._id, auth: GUILD_AUTH.LEADER, job: GUILD_JOB.JIANGJUN });
const userGuild = await UserGuildModel.createUserGuild(guild.code, role, true);
if(!userGuild) return resResult(STATUS.GUILD_CREATE_ERROR);
// TODO 加入排行
const rank = 0;
// TODO 加入channel
// 返回
const result = { ...guild, rank, myInfo: {...userGuild}};
const result = { ...guild, rank, myInfo: userGuild};
return resResult(STATUS.SUCCESS, result);
}
//TODO 获取军团列表
// 获取军团列表
async getGuildList(msg: { page: number, showPeopleMax: boolean, name: string }, session: BackendSession) {
const roleId = session.get('roleId');
// const sid = session.get('sid');
const { page = 1, showPeopleMax, name } = msg;
const list = [{
code: "code",
name: "name",
icon: 1,
lv: 0,
memberCnt: 0,
leader: "leader",
ceLimit: 0,
quitTime: 0,
hasApply: true
}];
return resResult(STATUS.SUCCESS, { list });
const guildList = await GuildModel.findByCondition(page, showPeopleMax, name);
// TODO 加入申请列表
const { quitGuildTime: quitTime = 0 } = await RoleModel.findByRoleId(roleId);
const list = new Array<GuildListInfo>();
for(let guild of guildList) {
let info = new GuildListInfo(guild);
// TODO 查询申请
info.setApply(false);
list.push(info);
}
return resResult(STATUS.SUCCESS, { quitTime, list });
}
// 团员获取自己军团详细信息
async getMyGuildInfo(msg: { }, session: BackendSession) {
const roleId = session.get('roleId');
//TODO 检查权限是否够 等策划表
const userGuild = await UserGuildModel.getMyGuild(roleId, 'honour job auth guildCode');
if(!userGuild) {
return resResult(STATUS.SUCCESS, { hasGuild: false })
};
const guild = await GuildModel.findByCode(userGuild.guildCode);
// TODO 获取排行榜
const rank = 0;
// 返回
const result = { hasGuild: true, ...guild, rank, myInfo: userGuild};
return resResult(STATUS.SUCCESS, result);
}
}
+50 -47
View File
@@ -56,51 +56,6 @@ describe('军团测试', function() {
done();
});
it('创建军团', function (done) {
pinusClient.request('battle.guildHandler.createGuild', { name: "test", icon: 1, notice: "notice" }, (res) => {
console.log(JSON.stringify(res))
// 消息回调
expect(res).to.be.an('object');
expect(res.code).equal(0);
expect(res.data).to.be.an('object');
expect(res.data).to.have.deep.property('code').that.is.an('string');
expect(res.data).to.have.deep.property('name').that.is.an('string');
expect(res.data).to.have.deep.property('icon').that.is.an('number');
expect(res.data).to.have.deep.property('notice').that.is.an('string');
expect(res.data).to.have.deep.property('introduce').that.is.an('string');
expect(res.data).to.have.deep.property('rank').that.is.an('number');
expect(res.data).to.have.deep.property('lv').that.is.an('number');
expect(res.data).to.have.deep.property('fund').that.is.an('number');
expect(res.data).to.have.deep.property('memberCnt').that.is.an('number');
expect(res.data).to.have.deep.property('managerCnt').that.is.an('number');
expect(res.data).to.have.deep.property('activeDaily').that.is.an('number');
expect(res.data).to.have.deep.property('activeWeekly').that.is.an('number');
expect(res.data).to.have.deep.property('ceLimit').that.is.an('number');
expect(res.data).to.have.deep.property('isAuto').that.is.an('boolean');
expect(res.data).to.have.deep.property('leader').that.is.an('object');
expect(res.data.leader).to.have.deep.property('name').that.is.an('string');
expect(res.data.leader).to.have.deep.property('sHid').that.is.an('number');
expect(res.data.leader).to.have.deep.property('headHid').that.is.an('number');
expect(res.data.leader).to.have.deep.property('lv').that.is.an('number');
expect(res.data.leader).to.have.deep.property('loginTime').that.is.an('number');
expect(res.data).to.have.deep.property('myInfo').that.is.an('object');
expect(res.data.myInfo).to.have.deep.property('honour').that.is.an('number');
expect(res.data.myInfo).to.have.deep.property('active').that.is.an('number');
expect(res.data.myInfo).to.have.deep.property('job').that.is.an('number');
expect(res.data.myInfo).to.have.deep.property('auth').that.is.an('number');
expect(res.data).to.have.deep.property('structure').that.is.an('array');
res.data.structure.forEach(list => {
expect(list).to.have.deep.property('id').that.is.a('number');
expect(list).to.have.deep.property('lv').that.is.a('number');
});
done();
});
});
it('获取军团列表', function(done) {
pinusClient.request('battle.guildHandler.getGuildList', {page:1, showPeopleMax: true, name: ""} , (res) => {
console.log(JSON.stringify(res))
@@ -109,18 +64,66 @@ describe('军团测试', function() {
expect(res.code).equal(0);
expect(res.data).to.be.an('object');
expect(res.data).to.have.deep.property('list').that.is.an('array');
expect(res.data).to.have.deep.property('quitTime').that.is.an('number');
res.data.list.forEach(list => {
expect(list).to.have.deep.property('code').that.is.a('string');
expect(list).to.have.deep.property('name').that.is.a('string');
expect(list).to.have.deep.property('icon').that.is.a('number');
expect(list).to.have.deep.property('lv').that.is.a('number');
expect(list).to.have.deep.property('peopleNum').that.is.a('number');
expect(list).to.have.deep.property('memberCnt').that.is.a('number');
expect(list).to.have.deep.property('leader').that.is.a('string');
expect(list).to.have.deep.property('ceLimit').that.is.a('number');
expect(list).to.have.deep.property('quitTime').that.is.a('number');
expect(list).to.have.deep.property('hasApply').that.is.a('boolean');
});
done();
});
});
it('获取个人军团', function (done) {
pinusClient.request('battle.guildHandler.getMyGuildInfo', { }, (res) => {
// 消息回调
expect(res).to.be.an('object');
expect(res.code).equal(0);
expect(res.data).to.be.an('object');
expect(res.data).to.have.deep.property('hasGuild').that.is.an('boolean');
if(res.data.hasGuild) {
expect(res.data).to.have.deep.property('code').that.is.an('string');
expect(res.data).to.have.deep.property('name').that.is.an('string');
expect(res.data).to.have.deep.property('icon').that.is.an('number');
expect(res.data).to.have.deep.property('notice').that.is.an('string');
expect(res.data).to.have.deep.property('introduce').that.is.an('string');
expect(res.data).to.have.deep.property('rank').that.is.an('number');
expect(res.data).to.have.deep.property('lv').that.is.an('number');
expect(res.data).to.have.deep.property('fund').that.is.an('number');
expect(res.data).to.have.deep.property('memberCnt').that.is.an('number');
expect(res.data).to.have.deep.property('managerCnt').that.is.an('number');
expect(res.data).to.have.deep.property('activeDaily').that.is.an('number');
expect(res.data).to.have.deep.property('activeWeekly').that.is.an('number');
expect(res.data).to.have.deep.property('ceLimit').that.is.an('number');
expect(res.data).to.have.deep.property('isAuto').that.is.an('boolean');
expect(res.data).to.have.deep.property('leader').that.is.an('object');
expect(res.data.leader).to.have.deep.property('roleName').that.is.an('string');
expect(res.data.leader).to.have.deep.property('sHid').that.is.an('number');
expect(res.data.leader).to.have.deep.property('headHid').that.is.an('number');
expect(res.data.leader).to.have.deep.property('lv').that.is.an('number');
expect(res.data.leader).to.have.deep.property('ce').that.is.an('number');
expect(res.data.leader).to.have.deep.property('loginTime').that.is.an('number');
expect(res.data).to.have.deep.property('myInfo').that.is.an('object');
expect(res.data.myInfo).to.have.deep.property('honour').that.is.an('number');
expect(res.data.myInfo).to.have.deep.property('job').that.is.an('number');
expect(res.data.myInfo).to.have.deep.property('auth').that.is.an('number');
expect(res.data).to.have.deep.property('structure').that.is.an('array');
res.data.structure.forEach(list => {
expect(list).to.have.deep.property('id').that.is.a('number');
expect(list).to.have.deep.property('lv').that.is.a('number');
});
}
done();
});
});
});