feat: update status when delete user or branch

This must be handle accordingly when new model has relation when these model.
This commit is contained in:
Methapon2001 2024-04-04 11:07:09 +07:00
parent 7830d1ee63
commit a86b01bc3e
2 changed files with 22 additions and 0 deletions

View file

@ -283,6 +283,17 @@ export class BranchController extends Controller {
throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "data_in_used");
}
await prisma.user.updateMany({
where: {
NOT: {
branch: { some: {} },
},
},
data: {
status: Status.CREATED,
},
});
return await prisma.branch.delete({
include: {
province: true,

View file

@ -329,6 +329,17 @@ export class UserController extends Controller {
forceDelete: true,
});
await prisma.branch.updateMany({
where: {
NOT: {
user: { some: {} },
},
},
data: {
status: Status.CREATED,
},
});
return await prisma.user.delete({
include: {
province: true,