Skip to content

Commit

Permalink
feat: decrement likes from favs animals when a user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlbDR committed Apr 10, 2024
1 parent c7eed68 commit f9b80b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/presentation/animals/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class AnimalService {
slug: animal.slug,
action: 'create-animal',
},
'animal-created-deleted'
'animal-created-deleted-notification'
);

return animal;
Expand Down Expand Up @@ -316,7 +316,7 @@ export class AnimalService {
slug: animal.slug,
action: 'create-animal',
},
'animal-created-deleted'
'animal-created-deleted-notification'
);

return animal;
Expand Down Expand Up @@ -539,7 +539,7 @@ export class AnimalService {
slug: animal.slug,
action: 'delete-animal',
},
'animal-created-deleted'
'animal-created-deleted-notification'
);
}

Expand Down
20 changes: 20 additions & 0 deletions src/presentation/users/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export class UserService {
prisma.user.findUnique({
where: { email: user.email },
include: {
userFav: true,
shelter: {
select: {
images: true,
Expand Down Expand Up @@ -398,6 +399,25 @@ export class UserService {
if (imagesToDelete.length > 0)
await this.s3Service.deleteFiles(imagesToDelete);

userToDelete.userFav.map(async (animal) => {
console.log({ animal: animal.name });
await prisma.animal.update({
where: { id: animal.id },
data: {
numFavs: { decrement: 1 },
},
});
});

this.notificationService.addMessageToQueue(
{
action: 'user-deleted',
username: userToDelete.username,
role: userToDelete.role,
},
'user-deleted-notification'
);

await prisma.user.delete({ where: { email: userToDelete.email } });
}

Expand Down

0 comments on commit f9b80b2

Please sign in to comment.