From 301f6ad126bc086e3f0ea3701e2895443ab85ada Mon Sep 17 00:00:00 2001 From: Whitigol <36452182+WhitigolProd@users.noreply.github.com> Date: Wed, 14 Feb 2024 01:42:54 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20fix:=20delete=20user=20with=20pe?= =?UTF-8?q?t=20medical=20record=20(#1914)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Bug - [x] Related issues linked using closes #1904 ## Feature - [ ] Related issues linked using `closes: #number` - [ ] There is only 1 db migration with no breaking changes. ## Translations - [ ] `.json` files are formatted: `pnpm format` - [ ] Translations are correct - [ ] New translation? It's been added to `i18n.config.mjs` --- .../admin/manage/manage-users-controller.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/apps/api/src/controllers/admin/manage/manage-users-controller.ts b/apps/api/src/controllers/admin/manage/manage-users-controller.ts index 63fca9c90..ace455883 100644 --- a/apps/api/src/controllers/admin/manage/manage-users-controller.ts +++ b/apps/api/src/controllers/admin/manage/manage-users-controller.ts @@ -143,6 +143,24 @@ export class ManageUsersController { @BodyParams("userIds", String) userIds: string[], @BodyParams("days", Number) days = 30, ) { + await prisma.petMedicalRecord.deleteMany({ + where: { + pet: { + citizen: { + userId: { in: userIds }, + }, + }, + }, + }); + + await prisma.pet.deleteMany({ + where: { + citizen: { + userId: { in: userIds }, + }, + }, + }); + const arr = await prisma.$transaction( userIds.map((id) => prisma.user.deleteMany({ @@ -472,6 +490,24 @@ export class ManageUsersController { throw new NotFound("notFound"); } + await prisma.petMedicalRecord.deleteMany({ + where: { + pet: { + citizen: { + userId: user.id, + }, + }, + }, + }); + + await prisma.pet.deleteMany({ + where: { + citizen: { + userId: user.id, + }, + }, + }); + await prisma.user.delete({ where: { id: user.id,