fix: removeFavoritedUser

This commit is contained in:
cha0s 2020-07-22 02:21:45 -05:00
parent 72f3d9ec9b
commit c23570c25d
2 changed files with 15 additions and 14 deletions

View File

@ -2,6 +2,20 @@ import RemoveFavorite from '~/common/packets/remove-favorite.packet';
import {allModels} from '~/server/models/registrar'; import {allModels} from '~/server/models/registrar';
export const removeFavoritedUser = async (socket, user, other) => {
const {Favorite} = allModels();
const favorites = await user.getFavorites();
const toRemove = favorites.find(({channel}) => channel === `/u/${other.redditUsername}`);
if (toRemove) {
await Favorite.destroy({
where: {
id: toRemove.id,
},
});
socket.to(`/user/${user.id}`, new RemoveFavorite(`/u/${other.redditUsername}`));
}
};
export default { export default {
Packet: RemoveFavorite, Packet: RemoveFavorite,
validator: () => true, validator: () => true,

View File

@ -1,23 +1,10 @@
import {Op} from 'sequelize'; import {Op} from 'sequelize';
import RemoveFavorite from '~/common/packets/remove-favorite.packet';
import RemoveFriend from '~/common/packets/remove-friend.packet'; import RemoveFriend from '~/common/packets/remove-friend.packet';
import {allModels} from '~/server/models/registrar'; import {allModels} from '~/server/models/registrar';
export const removeFavoritedUser = async (socket, user, other) => { import {removeFavoritedUser} from './remove-favorite';
const {Favorite} = allModels();
const favorites = await user.getFavorites();
const toRemove = favorites.find(({channel}) => channel === `/u/${other.redditUsername}`);
if (toRemove) {
await Favorite.destroy({
where: {
id: toRemove.id,
},
});
socket.to(`/user/${user.id}`, new RemoveFavorite(`/u/${other.redditUsername}`));
}
};
export default { export default {
Packet: RemoveFriend, Packet: RemoveFriend,