Refactoring, Clean up and bug fixes

This commit is contained in:
syuilo
2018-11-02 03:32:24 +09:00
parent b4b9e76c8d
commit 931bdc6aac
108 changed files with 1722 additions and 1539 deletions

View File

@@ -1,6 +1,7 @@
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import User, { ILocalUser } from '../../../../models/user';
import Mute from '../../../../models/mute';
import getParams from '../../get-params';
export const meta = {
desc: {
@@ -10,24 +11,30 @@ export const meta = {
requireCredential: true,
kind: 'account/write'
kind: 'account/write',
params: {
userId: {
validator: $.type(ID),
transform: transform,
},
}
};
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const muter = user;
// Get 'userId' parameter
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Check if the mutee is yourself
if (user._id.equals(userId)) {
if (user._id.equals(ps.userId)) {
return rej('mutee is yourself');
}
// Get mutee
const mutee = await User.findOne({
_id: userId
_id: ps.userId
}, {
fields: {
data: false,
@@ -54,6 +61,5 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
_id: exist._id
});
// Send response
res();
});