summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/show.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 06:48:26 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 06:48:26 +0900
commit6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a (patch)
treed9319e37433f57c70cdf9e66b57b525fd7bfc881 /src/api/endpoints/posts/show.ts
parentwip (diff)
downloadsharkey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.gz
sharkey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.tar.bz2
sharkey-6e181ee0f1ca2ecd0fdf3a78654607ef112f2a6a.zip
wip
Diffstat (limited to 'src/api/endpoints/posts/show.ts')
-rw-r--r--src/api/endpoints/posts/show.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/api/endpoints/posts/show.ts b/src/api/endpoints/posts/show.ts
new file mode 100644
index 0000000000..712ef1e160
--- /dev/null
+++ b/src/api/endpoints/posts/show.ts
@@ -0,0 +1,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
+ }));
+});