feat: add delete notification
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 9s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 9s
This commit is contained in:
parent
6265ac8a65
commit
9bf534adce
2 changed files with 35 additions and 5 deletions
|
|
@ -29,7 +29,8 @@ model Notification {
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
||||||
readByUser User[]
|
readByUser User[] @relation(name: "NotificationRead")
|
||||||
|
deleteByUser User[] @relation(name: "NotificationDelete")
|
||||||
}
|
}
|
||||||
|
|
||||||
model NotificationGroup {
|
model NotificationGroup {
|
||||||
|
|
@ -484,7 +485,8 @@ model User {
|
||||||
invoiceCreated Invoice[]
|
invoiceCreated Invoice[]
|
||||||
paymentCreated Payment[]
|
paymentCreated Payment[]
|
||||||
notificationReceive Notification[] @relation("NotificationReceiver")
|
notificationReceive Notification[] @relation("NotificationReceiver")
|
||||||
notificationRead Notification[]
|
notificationRead Notification[] @relation("NotificationRead")
|
||||||
|
notificationDelete Notification[] @relation("NotificationDelete")
|
||||||
taskOrderCreated TaskOrder[] @relation("TaskOrderCreatedByUser")
|
taskOrderCreated TaskOrder[] @relation("TaskOrderCreatedByUser")
|
||||||
creditNoteCreated CreditNote[] @relation("CreditNoteCreatedByUser")
|
creditNoteCreated CreditNote[] @relation("CreditNoteCreatedByUser")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,11 +135,39 @@ export class NotificationController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Delete()
|
||||||
|
@Security("keycloak")
|
||||||
|
async deleteNotificationMany(@Request() req: RequestWithUser, @Body() notificationId: string[]) {
|
||||||
|
if (!notificationId.length) return;
|
||||||
|
|
||||||
|
return await prisma.notification
|
||||||
|
.findMany({ where: { id: { in: notificationId } } })
|
||||||
|
.then(async (v) => {
|
||||||
|
await prisma.$transaction(
|
||||||
|
v.map((v) =>
|
||||||
|
prisma.notification.update({
|
||||||
|
where: { id: v.id },
|
||||||
|
data: {
|
||||||
|
deleteByUser: { connect: { id: req.user.sub } },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Delete("{notificationId}")
|
@Delete("{notificationId}")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async deleteNotification(@Request() req: RequestWithUser, @Path() notificationId: string) {
|
async deleteNotification(@Request() req: RequestWithUser, @Path() notificationId: string) {
|
||||||
const record = await prisma.notification.deleteMany({ where: { id: notificationId } });
|
const record = await prisma.notification.findFirst({ where: { id: notificationId } });
|
||||||
if (record.count === 0) throw notFoundError("Notification");
|
if (!record) throw notFoundError("Notification");
|
||||||
return record;
|
return await prisma.notification.update({
|
||||||
|
where: { id: notificationId },
|
||||||
|
data: {
|
||||||
|
deleteByUser: {
|
||||||
|
disconnect: { id: req.user.sub },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue