2018-08-30 19:50:03 +00:00
|
|
|
import { authWithHeaders } from '../../middlewares/auth';
|
2018-09-21 13:12:20 +00:00
|
|
|
import * as inboxLib from '../../libs/inbox';
|
2018-08-30 19:50:03 +00:00
|
|
|
|
|
|
|
|
let api = {};
|
|
|
|
|
|
|
|
|
|
/* NOTE most inbox routes are either in the user or members controller */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @api {get} /api/v3/inbox/messages Get inbox messages for a user
|
|
|
|
|
* @apiName GetInboxMessages
|
|
|
|
|
* @apiGroup Inbox
|
|
|
|
|
* @apiDescription Get inbox messages for a user
|
|
|
|
|
*
|
2019-03-31 18:52:53 +00:00
|
|
|
* @apiParam (Query) {Number} page Load the messages of the selected Page - 10 Messages per Page
|
2019-04-26 16:45:05 +00:00
|
|
|
* @apiParam (Query) {GUID} conversation Loads only the messages of a conversation
|
2019-03-31 18:52:53 +00:00
|
|
|
*
|
2018-08-30 19:50:03 +00:00
|
|
|
* @apiSuccess {Array} data An array of inbox messages
|
|
|
|
|
*/
|
|
|
|
|
api.getInboxMessages = {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '/inbox/messages',
|
|
|
|
|
middlewares: [authWithHeaders()],
|
|
|
|
|
async handler (req, res) {
|
2018-09-21 13:12:20 +00:00
|
|
|
const user = res.locals.user;
|
2019-03-31 18:52:53 +00:00
|
|
|
const page = req.query.page;
|
2019-04-26 16:45:05 +00:00
|
|
|
const conversation = req.query.conversation;
|
2018-08-30 19:50:03 +00:00
|
|
|
|
2019-03-31 18:52:53 +00:00
|
|
|
const userInbox = await inboxLib.getUserInbox(user, {
|
2019-04-26 16:45:05 +00:00
|
|
|
page, conversation,
|
2019-03-31 18:52:53 +00:00
|
|
|
});
|
2018-09-21 13:12:20 +00:00
|
|
|
|
|
|
|
|
res.respond(200, userInbox);
|
2018-08-30 19:50:03 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = api;
|