blob: 712ef1e1608c645c209e7c51e1cbb8cb9d5de004 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
'use strict';
/**
* Module dependencies
*/
import it from '../../it';
import Post from '../../models/post';
import serialize from '../../serializers/post';
/**
* Show a post
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
// Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id', true);
if (postIdErr) return rej('invalid post_id param');
// Get post
const post = await Post.findOne({
_id: postId
});
if (post === null) {
return rej('post not found');
}
// Serialize
res(await serialize(post, user, {
detail: true
}));
});
|