2019-02-07 06:59:18 -06:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../../define';
|
|
|
|
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 followings = await Following.find({
|
2019-02-07 08:27:42 -06:00
|
|
|
'_follower.host': ps.host
|
2019-02-07 06:59:18 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
}));
|