特定インスタンスからのフォローを全解除できるように

This commit is contained in:
syuilo
2019-02-07 21:59:18 +09:00
parent 15cac10d7b
commit e43c9c0e21
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import $ from 'cafy';
import define from '../../../define';
import Instance from '../../../../../models/instance';
import Following from '../../../../../models/following';
import User from '../../../../../models/user';
import deleteFollowing from '../../../../../services/following/delete';
export const meta = {
requireCredential: true,
requireModerator: true,
params: {
host: {
validator: $.str
}
}
};
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const instance = await Instance
.findOne({ host: ps.host });
if (instance == null) {
return rej('instance not found');
}
const followings = await Following.find({
'_follower.host': { $ne: null }
});
const pairs = await Promise.all(followings.map(f => Promise.all([
User.findOne({ _id: f.followerId }),
User.findOne({ _id: f.followeeId })
])));
for (const pair of pairs) {
deleteFollowing(pair[0], pair[1]);
}
res();
}));