diff --git a/src/controllers/groups.js b/src/controllers/groups.js index 6e601d892c..d4776df02d 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -195,7 +195,9 @@ api.update = function(req, res, next) { } api.attachGroup = function(req, res, next) { - Group.findById(req.params.gid, function(err, group){ + var gid = req.params.gid; + var q = (gid == 'party') ? Group.findOne({type: 'party', members: {'$in': [res.locals.user._id]}}) : Group.findById(gid); + q.exec(function(err, group){ if(err) return res.json(500, {err:err}); if(!group) return res.json(404, {err: "Group not found"}); res.locals.group = group; @@ -203,6 +205,10 @@ api.attachGroup = function(req, res, next) { }) } +api.getChat = function(req, res, next) { + return res.json(res.locals.group.chat); +} + /** * TODO make this it's own ngResource so we don't have to send down group data with each chat post */ diff --git a/src/routes/apiv2.coffee b/src/routes/apiv2.coffee index 90632ec6ff..a4692c2013 100644 --- a/src/routes/apiv2.coffee +++ b/src/routes/apiv2.coffee @@ -461,12 +461,20 @@ module.exports = (swagger, v2) -> middleware: [auth.auth, groups.attachGroup] action: groups.questAbort - #TODO GET /groups/:gid/chat #TODO PUT /groups/:gid/chat/:messageId - "/groups/{gid}/chat": + "/groups/{gid}/chat:GET": + spec: + path: "/groups/{gid}/chat" + description: "Get all chat messages" + middleware: [auth.auth, groups.attachGroup] + action: groups.getChat + + + "/groups/{gid}/chat:POST": spec: method: 'POST' + path: "/groups/{gid}/chat" description: "Send a chat message" parameters: [ query 'message', 'Chat message','string'