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
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
const api = {};
|
2018-08-30 19:50:03 +00:00
|
|
|
|
|
|
|
|
/* 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',
|
2024-08-12 21:45:35 +00:00
|
|
|
middlewares: [authWithHeaders({ userFieldsToInclude: ['profile', 'contributor', 'backer', 'inbox'] })],
|
2018-08-30 19:50:03 +00:00
|
|
|
async handler (req, res) {
|
2019-10-08 14:57:10 +00:00
|
|
|
const { user } = res.locals;
|
|
|
|
|
const { page } = req.query;
|
|
|
|
|
const { conversation } = req.query;
|
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
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-02 17:45:27 +00:00
|
|
|
export default api;
|