1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-25 12:08:16 +09:00
MisskeyIO/src/api/endpoints/posts/show.ts
syuilo 31f36fa618 ✌️
2017-03-09 03:50:09 +09:00

34 lines
642 B
TypeScript

/**
* Module dependencies
*/
import $ from 'cafy';
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] = $(params.post_id).id().$;
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
}));
});