Skip to content

Commit

Permalink
fix(server): fixed illegal removal of unowned trigger (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Mar 25, 2023
1 parent a1e42b1 commit 260b335
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions server/src/trigger/trigger.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ export class TriggerController {
@ApiResponse({ type: ResponseUtil })
@UseGuards(JwtAuthGuard, ApplicationAuthGuard)
@Delete(':id')
async remove(@Param('id') id: string) {
const res = await this.triggerService.remove(id)
async remove(@Param('id') id: string, @Param('appid') appid: string) {
// check if trigger exists
const trigger = await this.triggerService.findOne(appid, id)
if (!trigger) {
return ResponseUtil.error('Trigger not found')
}

const res = await this.triggerService.remove(appid, id)
return ResponseUtil.ok(res)
}
}
16 changes: 12 additions & 4 deletions server/src/trigger/trigger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,25 @@ export class TriggerService {
return res
}

async findOne(appid: string, id: string) {
const res = await this.prisma.cronTrigger.findFirst({
where: { id, appid },
})

return res
}

async findAll(appid: string) {
const res = await this.prisma.cronTrigger.findMany({
where: { appid },
where: { appid, state: TriggerState.Active },
})

return res
}

async remove(id: string) {
const res = await this.prisma.cronTrigger.update({
where: { id },
async remove(appid: string, id: string) {
const res = await this.prisma.cronTrigger.updateMany({
where: { id, appid },
data: {
state: TriggerState.Deleted,
},
Expand Down

0 comments on commit 260b335

Please sign in to comment.