summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/following/stalk.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints/following/stalk.ts')
-rw-r--r--src/server/api/endpoints/following/stalk.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/server/api/endpoints/following/stalk.ts b/src/server/api/endpoints/following/stalk.ts
new file mode 100644
index 0000000000..f0bc8cbdfc
--- /dev/null
+++ b/src/server/api/endpoints/following/stalk.ts
@@ -0,0 +1,35 @@
+import $ from 'cafy'; import ID from '../../../../cafy-id';
+import Following from '../../../../models/following';
+
+/**
+ * Stalk a user
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ const follower = user;
+
+ // Get 'userId' parameter
+ const [userId, userIdErr] = $.type(ID).get(params.userId);
+ if (userIdErr) return rej('invalid userId param');
+
+ // Fetch following
+ const following = await Following.findOne({
+ followerId: follower._id,
+ followeeId: userId
+ });
+
+ if (following === null) {
+ return rej('following not found');
+ }
+
+ // Stalk
+ await Following.update({ _id: following._id }, {
+ $set: {
+ stalk: true
+ }
+ });
+
+ // Send response
+ res();
+
+ // TODO: イベント
+});