summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-08-30 17:31:39 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-08-30 17:31:39 +0900
commite7415dd42bf656a24d70c49776ff7c84a1838f9e (patch)
tree517b326e16cdacda245661b2bfb15585a4bfa09d /src/api/endpoints
parentMerge branch 'master' of https://github.com/syuilo/misskey (diff)
downloadsharkey-e7415dd42bf656a24d70c49776ff7c84a1838f9e.tar.gz
sharkey-e7415dd42bf656a24d70c49776ff7c84a1838f9e.tar.bz2
sharkey-e7415dd42bf656a24d70c49776ff7c84a1838f9e.zip
Implement #746
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/i/pin.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/api/endpoints/i/pin.ts b/src/api/endpoints/i/pin.ts
new file mode 100644
index 0000000000..a94950d22b
--- /dev/null
+++ b/src/api/endpoints/i/pin.ts
@@ -0,0 +1,44 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User from '../../models/user';
+import Post from '../../models/post';
+import serialize from '../../serializers/user';
+
+/**
+ * Pin post
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise<any>}
+ */
+module.exports = async (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');
+
+ // Fetch pinee
+ const post = await Post.findOne({
+ _id: postId,
+ user_id: user._id
+ });
+
+ if (post === null) {
+ return rej('post not found');
+ }
+
+ await User.update(user._id, {
+ $set: {
+ pinned_post_id: post._id
+ }
+ });
+
+ // Serialize
+ const iObj = await serialize(user, user, {
+ detail: true
+ });
+
+ // Send response
+ res(iObj);
+});