Skip to content

Commit

Permalink
🔨 fix: delete user with pet medical record (#1914)
Browse files Browse the repository at this point in the history
<!--
Thanks for opening a PR! Your contribution is much appreciated!
-->

## 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`
  • Loading branch information
whitigol authored Feb 14, 2024
1 parent b37bde7 commit 301f6ad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions apps/api/src/controllers/admin/manage/manage-users-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 301f6ad

Please sign in to comment.