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', () => {
|
||||
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_GROUPS_USER_CAN_VIEW = 5;
|
||||
|
||||
@@ -87,6 +88,11 @@ describe('GET /groups', () => {
|
||||
.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 () => {
|
||||
await expect(user.get('/groups?type=privateGuilds'))
|
||||
.to.eventually.have.a.lengthOf(NUMBER_OF_USERS_PRIVATE_GUILDS);
|
||||
|
||||
@@ -79,7 +79,7 @@ api.createGroup = {
|
||||
* @apiName GetGroups
|
||||
* @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
|
||||
*/
|
||||
|
||||
@@ -149,25 +149,35 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
||||
queries.push(this.getGroup({user, groupId: 'party', fields: groupFields, populateLeader}));
|
||||
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': {
|
||||
let privateGroupQuery = this.find({
|
||||
let privateGuildsQuery = this.find({
|
||||
type: 'guild',
|
||||
privacy: 'private',
|
||||
_id: {$in: user.guilds},
|
||||
}).select(groupFields);
|
||||
if (populateLeader === true) privateGroupQuery.populate('leader', nameFields);
|
||||
privateGroupQuery.sort(sort).exec();
|
||||
queries.push(privateGroupQuery);
|
||||
if (populateLeader === true) privateGuildsQuery.populate('leader', nameFields);
|
||||
privateGuildsQuery.sort(sort).exec();
|
||||
queries.push(privateGuildsQuery);
|
||||
break;
|
||||
}
|
||||
case 'publicGuilds': {
|
||||
let publicGroupQuery = this.find({
|
||||
let publicGuildsQuery = this.find({
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
}).select(groupFields);
|
||||
if (populateLeader === true) publicGroupQuery.populate('leader', nameFields);
|
||||
publicGroupQuery.sort(sort).exec();
|
||||
queries.push(publicGroupQuery); // TODO use lean?
|
||||
if (populateLeader === true) publicGuildsQuery.populate('leader', nameFields);
|
||||
publicGuildsQuery.sort(sort).exec();
|
||||
queries.push(publicGuildsQuery); // TODO use lean?
|
||||
break;
|
||||
}
|
||||
case 'tavern': {
|
||||
|
||||
Reference in New Issue
Block a user