File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 ( {
You can’t perform that action at this time.
0 commit comments