Skip to content

Commit

Permalink
feat: deleteNotification route, controller, service
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlbDR committed Apr 15, 2024
1 parent f9bf4b5 commit 06e3369
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/presentation/users/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ export class UserController {

await this.userService.readNotification(user, id);

res.status(HttpCodes.OK).json({ message: 'Notification marked as read' });
res.status(HttpCodes.OK).json({ message: 'Notificación leida' });
};

deleteNotification = async (req: Request, res: Response) => {
const { id } = req.params;
const user = req.user;
await this.userService.deleteNotification(user, id);
res.status(HttpCodes.OK).json({ message: 'Notificación borrada' });
};
}
6 changes: 6 additions & 0 deletions src/presentation/users/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export class UserRoutes {
userController.readNotification
);

router.delete(
'/me/notifications/:id',
authMiddleware.authenticateUser,
userController.deleteNotification
);

// Animals
router.get(
'/me/animals/',
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 @@ -866,4 +866,24 @@ export class UserService {

return true;
}

public async deleteNotification(user: PayloadUser, id: string) {
const notification = await prisma.notification.findUnique({
where: {
id,
},
});

if (!notification) throw new NotFoundError('Notification not found');

CheckPermissions.check(user, notification.userId);

await prisma.notification.delete({
where: {
id,
},
});

return true;
}
}

0 comments on commit 06e3369

Please sign in to comment.