fix: removeFavoritedUser
This commit is contained in:
parent
72f3d9ec9b
commit
c23570c25d
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user