Skip to content

Commit 4642eba

Browse files
committed
added userID check
1 parent 460b8b5 commit 4642eba

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/poll/poll.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ export class PollController {
4949

5050
@Delete(':id')
5151
async deletePoll(@Param('id') id: number, @Res() res: Response) {
52+
const userId = 1; // need to implement Auth
5253
try {
53-
const poll = await this.pollService.deletePoll(Number(id));
54+
const poll = await this.pollService.deletePoll(userId, Number(id));
5455

5556
return res.status(200).json({ message: 'Poll deleted', poll: poll });
5657
} catch (error) {

src/poll/poll.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,17 @@ export class PollService {
135135
}
136136
}
137137

138-
async deletePoll(pollId: number) {
138+
async deletePoll(userId: number, pollId: number) {
139139
const poll = await this.databaseService.poll.findUnique({
140140
where: { pollId },
141141
});
142+
142143
if (!poll) {
143144
throw new Error('Poll not found');
144145
}
146+
if (poll.authorUserId !== userId) {
147+
throw new Error('User Not Authorized');
148+
}
145149

146150
return this.databaseService.$transaction(async (tx) => {
147151
const deleted = await tx.poll.delete({

0 commit comments

Comments
 (0)