diff options
| author | syuilo⭐️ <Syuilotan@yahoo.co.jp> | 2017-03-03 19:54:40 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-03 19:54:40 +0900 |
| commit | 3ce6601f0436da23589384990dfb6c12cec5a5b4 (patch) | |
| tree | b7b9cc14d9787f06c72d013bc25690a9470e6bbe /src/api/endpoints/following | |
| parent | fix(package): update whatwg-fetch to version 2.0.3 (diff) | |
| parent | done (diff) | |
| download | misskey-3ce6601f0436da23589384990dfb6c12cec5a5b4.tar.gz misskey-3ce6601f0436da23589384990dfb6c12cec5a5b4.tar.bz2 misskey-3ce6601f0436da23589384990dfb6c12cec5a5b4.zip | |
Merge pull request #232 from syuilo/#226
#226、あとTypeScriptにした
Diffstat (limited to 'src/api/endpoints/following')
| -rw-r--r-- | src/api/endpoints/following/create.ts (renamed from src/api/endpoints/following/create.js) | 15 | ||||
| -rw-r--r-- | src/api/endpoints/following/delete.ts (renamed from src/api/endpoints/following/delete.js) | 15 |
2 files changed, 8 insertions, 22 deletions
diff --git a/src/api/endpoints/following/create.js b/src/api/endpoints/following/create.ts index 46ff77ddf1..0edc122b94 100644 --- a/src/api/endpoints/following/create.js +++ b/src/api/endpoints/following/create.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../it'; import User from '../../models/user'; import Following from '../../models/following'; import notify from '../../common/notify'; @@ -23,15 +23,8 @@ module.exports = (params, user) => const follower = user; // Get 'user_id' parameter - let userId = params.user_id; - if (userId === undefined || userId === null) { - return rej('user_id is required'); - } - - // Validate id - if (!mongo.ObjectID.isValid(userId)) { - return rej('incorrect user_id'); - } + const [userId, userIdErr] = it(params.user_id, 'id', true); + if (userIdErr) return rej('invalid user_id param'); // 自分自身 if (user._id.equals(userId)) { @@ -40,7 +33,7 @@ module.exports = (params, user) => // Get followee const followee = await User.findOne({ - _id: new mongo.ObjectID(userId) + _id: userId }, { fields: { data: false, diff --git a/src/api/endpoints/following/delete.js b/src/api/endpoints/following/delete.ts index 1085013d03..7f0e908068 100644 --- a/src/api/endpoints/following/delete.js +++ b/src/api/endpoints/following/delete.ts @@ -3,7 +3,7 @@ /** * Module dependencies */ -import * as mongo from 'mongodb'; +import it from '../../it'; import User from '../../models/user'; import Following from '../../models/following'; import event from '../../event'; @@ -22,15 +22,8 @@ module.exports = (params, user) => const follower = user; // Get 'user_id' parameter - let userId = params.user_id; - if (userId === undefined || userId === null) { - return rej('user_id is required'); - } - - // Validate id - if (!mongo.ObjectID.isValid(userId)) { - return rej('incorrect user_id'); - } + const [userId, userIdErr] = it(params.user_id, 'id', true); + if (userIdErr) return rej('invalid user_id param'); // Check if the followee is yourself if (user._id.equals(userId)) { @@ -39,7 +32,7 @@ module.exports = (params, user) => // Get followee const followee = await User.findOne({ - _id: new mongo.ObjectID(userId) + _id: userId }, { fields: { data: false, |