mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
v3: GET /groups accept a guilds type which returns all the guilds the user is a member of
This commit is contained in:
@@ -9,7 +9,8 @@ import {
|
|||||||
|
|
||||||
describe('GET /groups', () => {
|
describe('GET /groups', () => {
|
||||||
let user;
|
let user;
|
||||||
const NUMBER_OF_PUBLIC_GUILDS = 3;
|
const NUMBER_OF_PUBLIC_GUILDS = 3; // 2 + the tavern
|
||||||
|
const NUMBER_OF_PUBLIC_GUILDS_USER_IS_MEMBER = 1;
|
||||||
const NUMBER_OF_USERS_PRIVATE_GUILDS = 1;
|
const NUMBER_OF_USERS_PRIVATE_GUILDS = 1;
|
||||||
const NUMBER_OF_GROUPS_USER_CAN_VIEW = 5;
|
const NUMBER_OF_GROUPS_USER_CAN_VIEW = 5;
|
||||||
|
|
||||||
@@ -87,6 +88,11 @@ describe('GET /groups', () => {
|
|||||||
.to.eventually.have.a.lengthOf(NUMBER_OF_PUBLIC_GUILDS);
|
.to.eventually.have.a.lengthOf(NUMBER_OF_PUBLIC_GUILDS);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns all the user\'s guilds when guilds passed in as query', async () => {
|
||||||
|
await expect(user.get('/groups?type=guilds'))
|
||||||
|
.to.eventually.have.a.lengthOf(NUMBER_OF_PUBLIC_GUILDS_USER_IS_MEMBER + NUMBER_OF_USERS_PRIVATE_GUILDS);
|
||||||
|
});
|
||||||
|
|
||||||
it('returns all private guilds user is a part of when privateGuilds passed in as query', async () => {
|
it('returns all private guilds user is a part of when privateGuilds passed in as query', async () => {
|
||||||
await expect(user.get('/groups?type=privateGuilds'))
|
await expect(user.get('/groups?type=privateGuilds'))
|
||||||
.to.eventually.have.a.lengthOf(NUMBER_OF_USERS_PRIVATE_GUILDS);
|
.to.eventually.have.a.lengthOf(NUMBER_OF_USERS_PRIVATE_GUILDS);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ api.createGroup = {
|
|||||||
* @apiName GetGroups
|
* @apiName GetGroups
|
||||||
* @apiGroup Group
|
* @apiGroup Group
|
||||||
*
|
*
|
||||||
* @apiParam {string} type The type of groups to retrieve. Must be a query string representing a list of values like 'tavern,party'. Possible values are party, privateGuilds, publicGuilds, tavern
|
* @apiParam {string} type The type of groups to retrieve. Must be a query string representing a list of values like 'tavern,party'. Possible values are party, guilds, privateGuilds, publicGuilds, tavern
|
||||||
*
|
*
|
||||||
* @apiSuccess {Array} data An array of the requested groups
|
* @apiSuccess {Array} data An array of the requested groups
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -149,25 +149,35 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
|||||||
queries.push(this.getGroup({user, groupId: 'party', fields: groupFields, populateLeader}));
|
queries.push(this.getGroup({user, groupId: 'party', fields: groupFields, populateLeader}));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'guilds': {
|
||||||
|
let userGuildsQuery = this.find({
|
||||||
|
type: 'guild',
|
||||||
|
_id: {$in: user.guilds},
|
||||||
|
}).select(groupFields);
|
||||||
|
if (populateLeader === true) userGuildsQuery.populate('leader', nameFields);
|
||||||
|
userGuildsQuery.sort(sort).exec();
|
||||||
|
queries.push(userGuildsQuery);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'privateGuilds': {
|
case 'privateGuilds': {
|
||||||
let privateGroupQuery = this.find({
|
let privateGuildsQuery = this.find({
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
privacy: 'private',
|
privacy: 'private',
|
||||||
_id: {$in: user.guilds},
|
_id: {$in: user.guilds},
|
||||||
}).select(groupFields);
|
}).select(groupFields);
|
||||||
if (populateLeader === true) privateGroupQuery.populate('leader', nameFields);
|
if (populateLeader === true) privateGuildsQuery.populate('leader', nameFields);
|
||||||
privateGroupQuery.sort(sort).exec();
|
privateGuildsQuery.sort(sort).exec();
|
||||||
queries.push(privateGroupQuery);
|
queries.push(privateGuildsQuery);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'publicGuilds': {
|
case 'publicGuilds': {
|
||||||
let publicGroupQuery = this.find({
|
let publicGuildsQuery = this.find({
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
privacy: 'public',
|
privacy: 'public',
|
||||||
}).select(groupFields);
|
}).select(groupFields);
|
||||||
if (populateLeader === true) publicGroupQuery.populate('leader', nameFields);
|
if (populateLeader === true) publicGuildsQuery.populate('leader', nameFields);
|
||||||
publicGroupQuery.sort(sort).exec();
|
publicGuildsQuery.sort(sort).exec();
|
||||||
queries.push(publicGroupQuery); // TODO use lean?
|
queries.push(publicGuildsQuery); // TODO use lean?
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'tavern': {
|
case 'tavern': {
|
||||||
|
|||||||
Reference in New Issue
Block a user