Skip to content

Commit

Permalink
fix: delete order
Browse files Browse the repository at this point in the history
  • Loading branch information
DFanso committed Apr 27, 2024
1 parent 2866477 commit c197871
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 13 additions & 2 deletions API/src/jobs/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,18 @@ export class JobsController {
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.jobsService.remove(+id);
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
async remove(@Param('id') id: string) {
const context = this.clsService.get<AppClsStore>();
if (!context || !context.user) {
throw new HttpException('User not found', HttpStatus.BAD_REQUEST);
}

const user = await this.userService.findOne({ _id: context.user.id });
if (!user || user.type !== UserType.Admin) {
throw new HttpException('Unauthorized User', HttpStatus.UNAUTHORIZED);
}
return this.jobsService.remove(id);
}
}
10 changes: 8 additions & 2 deletions API/src/jobs/jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ export class JobsService {
return jobsNearingDelivery;
}

remove(id: number) {
return `This action removes a #${id} job`;
async remove(id: string): Promise<{ deleted: boolean; id: string }> {
const result = await this.jobModel.deleteOne({ _id: id }).exec();

if (result.deletedCount === 0) {
throw new HttpException('Bid not found', HttpStatus.NOT_FOUND);
}

return { deleted: true, id };
}
}

0 comments on commit c197871

Please sign in to comment.