Skip to content

Commit 1b17422

Browse files
committed
refactor(handler): Improve database query conditions for deletion operations
1 parent c44706f commit 1b17422

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/handler.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,17 @@ export async function getAppEditPageHandler(req: Request, res: Response) {
412412
export async function postDeleteAppChannelHandler(req: Request, res: Response) {
413413
const { aid, cid } = req.params;
414414

415-
await db('app_channels').where({ id: cid }).del();
415+
await db('app_channels')
416+
.where('app_channels.id', cid)
417+
.andWhere(function () {
418+
this.whereExists(function () {
419+
this.select('apps.id')
420+
.from('apps')
421+
.where('apps.id', aid)
422+
.andWhere('apps.user_id', req.session?.user?.id);
423+
});
424+
})
425+
.delete();
416426

417427
return res.redirect(`/apps/${aid}/channels?toast=🗑️ deleted`);
418428
}
@@ -421,7 +431,17 @@ export async function postDeleteAppChannelHandler(req: Request, res: Response) {
421431
export async function postDeleteAppNotificationHandler(req: Request, res: Response) {
422432
const { id, nid } = req.params;
423433

424-
await db('notifications').where({ id: nid }).del();
434+
await db('notifications')
435+
.where('notifications.id', nid)
436+
.andWhere(function () {
437+
this.whereExists(function () {
438+
this.select('apps.id')
439+
.from('apps')
440+
.where('apps.id', id)
441+
.andWhere('apps.user_id', req.session?.user?.id);
442+
});
443+
})
444+
.delete();
425445

426446
req.flash('info', '🗑️ deleted');
427447

0 commit comments

Comments
 (0)