reddichat/packages/user/src/remove-favorited-user.js
2020-12-09 22:06:18 -06:00

13 lines
418 B
JavaScript

import {ModelMap} from '@latus/db';
export default async (latus, socket, user, other) => {
const {Favorite} = ModelMap(latus);
const favorite = await Favorite.findOne(
{where: {channel: `/u/${other.redditUsername}`, user_id: user.id}},
);
if (favorite) {
await Favorite.destroy({where: {id: favorite.id}});
socket.to(`/u/${user.id}`).send(['RemoveFavorite', `/u/${other.redditUsername}`]);
}
};