Improve API definitions
This commit is contained in:
parent
c29f912461
commit
3aece449e4
15 changed files with 136 additions and 34 deletions
|
|
@ -3,8 +3,11 @@ const ms = require('ms');
|
|||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import create from '../../../../services/following/create';
|
||||
import getParams from '../../get-params';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
||||
desc: {
|
||||
'ja-JP': '指定したユーザーをフォローします。',
|
||||
'en-US': 'Follow a user.'
|
||||
|
|
@ -17,24 +20,32 @@ export const meta = {
|
|||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'following-write'
|
||||
kind: 'following-write',
|
||||
|
||||
params: {
|
||||
userId: $.type(ID).note({
|
||||
desc: {
|
||||
'ja-JP': '対象のユーザーのID',
|
||||
'en-US': 'Target user ID'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
if (user._id.equals(userId)) {
|
||||
if (user._id.equals(ps.userId)) {
|
||||
return rej('followee is yourself');
|
||||
}
|
||||
|
||||
// Get followee
|
||||
const followee = await User.findOne({
|
||||
_id: userId
|
||||
_id: ps.userId
|
||||
}, {
|
||||
fields: {
|
||||
data: false,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ const ms = require('ms');
|
|||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import deleteFollowing from '../../../../services/following/delete';
|
||||
import getParams from '../../get-params';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
||||
desc: {
|
||||
'ja-JP': '指定したユーザーのフォローを解除します。',
|
||||
'en-US': 'Unfollow a user.'
|
||||
|
|
@ -17,24 +20,32 @@ export const meta = {
|
|||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'following-write'
|
||||
kind: 'following-write',
|
||||
|
||||
params: {
|
||||
userId: $.type(ID).note({
|
||||
desc: {
|
||||
'ja-JP': '対象のユーザーのID',
|
||||
'en-US': 'Target user ID'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the followee is yourself
|
||||
if (user._id.equals(userId)) {
|
||||
if (user._id.equals(ps.userId)) {
|
||||
return rej('followee is yourself');
|
||||
}
|
||||
|
||||
// Get followee
|
||||
const followee = await User.findOne({
|
||||
_id: userId
|
||||
_id: ps.userId
|
||||
}, {
|
||||
fields: {
|
||||
data: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue