add GET group

This commit is contained in:
Matteo Pagliazzi
2015-12-18 16:32:37 +01:00
parent e53bd5079a
commit 7adc060312
3 changed files with 56 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ api.getChat = {
if (groupId === 'party' || user.party._id === groupId) { if (groupId === 'party' || user.party._id === groupId) {
query = {type: 'party', _id: user.party._id}; query = {type: 'party', _id: user.party._id};
} else if (user.guilds.indexOf(groupId)) { } else if (user.guilds.indexOf(groupId) !== -1) {
query = {type: 'guild', _id: groupId}; query = {type: 'guild', _id: groupId};
} else { } else {
query = {type: 'guild', privacy: 'public', _id: groupId}; query = {type: 'guild', privacy: 'public', _id: groupId};

View File

@@ -0,0 +1,54 @@
import { authWithHeaders } from '../../middlewares/api-v3/auth';
import cron from '../../middlewares/api-v3/cron';
import { model as Group } from '../../models/group';
import {
NotFound,
} from '../../libs/api-v3/errors';
let api = {};
/**
* @api {get} /groups/:groupId Get group
* @apiVersion 3.0.0
* @apiName GetGroup
* @apiGroup Group
*
* @apiParam {UUID} groupId The group _id
*
* @apiSuccess {Object} group The group object
*/
api.getGroup = {
method: 'GET',
url: '/groups/:groupId',
middlewares: [authWithHeaders(), cron],
handler (req, res, next) {
let user = res.locals.user;
let groupId = req.params.groupId;
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
let validationErrors = req.validationErrors();
if (validationErrors) return next(validationErrors);
let query;
if (groupId === 'party' || user.party._id === groupId) {
query = {type: 'party', _id: user.party._id};
} else if (user.guilds.indexOf(groupId) !== -1) {
query = {type: 'guild', _id: groupId};
} else {
query = {type: 'guild', privacy: 'public', _id: groupId};
}
Group
.findOne(query).exec()
.then(group => {
if (!group) throw new NotFound(res.t('groupNotFound'));
res.respond(200, group);
})
.catch(next);
},
};
export default api;