diff --git a/src/controllers/branch-user-controller.ts b/src/controllers/branch-user-controller.ts index 19ffcd9..d33b307 100644 --- a/src/controllers/branch-user-controller.ts +++ b/src/controllers/branch-user-controller.ts @@ -157,6 +157,12 @@ export class BranchUserController extends Controller { await prisma.$transaction( body.user.map((v) => prisma.branchUser.deleteMany({ where: { branchId, userId: v } })), ); + await prisma.user.updateMany({ + where: { + branch: { none: {} }, + }, + data: { code: null }, + }); } @Delete("{userId}") @@ -164,6 +170,13 @@ export class BranchUserController extends Controller { await prisma.branchUser.deleteMany({ where: { branchId, userId }, }); + await prisma.user.updateMany({ + where: { + id: userId, + branch: { none: {} }, + }, + data: { code: null }, + }); } } @@ -253,6 +266,12 @@ export class UserBranchController extends Controller { await prisma.$transaction( body.branch.map((v) => prisma.branchUser.deleteMany({ where: { userId, branchId: v } })), ); + await prisma.user.updateMany({ + where: { + branch: { none: {} }, + }, + data: { code: null }, + }); } @Delete("{branchId}") @@ -260,5 +279,12 @@ export class UserBranchController extends Controller { await prisma.branchUser.deleteMany({ where: { branchId, userId }, }); + await prisma.user.updateMany({ + where: { + id: userId, + branch: { none: {} }, + }, + data: { code: null }, + }); } }