feat: update user code that has no associated branch

This commit is contained in:
Methapon2001 2024-04-18 18:00:19 +07:00
parent 721f3bce6e
commit d8034e221c

View file

@ -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 },
});
}
}