mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
add GET group
This commit is contained in:
@@ -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};
|
||||||
|
|||||||
54
website/src/controllers/api-v3/groups.js
Normal file
54
website/src/controllers/api-v3/groups.js
Normal 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;
|
||||||
Reference in New Issue
Block a user