fix: auto gen user code
This commit is contained in:
parent
30acdfdd32
commit
849a7d0078
1 changed files with 8 additions and 4 deletions
|
|
@ -126,16 +126,20 @@ export class BranchUserController extends Controller {
|
||||||
for (const g of Object.values(UserType)) {
|
for (const g of Object.values(UserType)) {
|
||||||
if (group[g].length === 0) continue;
|
if (group[g].length === 0) continue;
|
||||||
|
|
||||||
const last = await prisma.user.findFirst({
|
const last = await prisma.branchUser.findFirst({
|
||||||
orderBy: { createdAt: "desc" },
|
orderBy: { createdAt: "desc" },
|
||||||
|
include: { user: true },
|
||||||
where: {
|
where: {
|
||||||
userType: g,
|
branchId,
|
||||||
code: { startsWith: `${branch.code.slice(2, 5).padEnd(3, "0")}` },
|
user: {
|
||||||
|
userType: g,
|
||||||
|
code: { startsWith: `${branch.code.slice(4).padEnd(3, "0")}` },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const code = (idx: number) =>
|
const code = (idx: number) =>
|
||||||
`${branch.code.slice(4).padEnd(3, "0")}${g !== "USER" ? g.charAt(0) : ""}${(+(last?.code?.slice(-4) || 0) + idx + 1).toString().padStart(4, "0")}`;
|
`${branch.code.slice(4).padEnd(3, "0")}${g !== "USER" ? g.charAt(0) : ""}${(+(last?.user.code?.slice(-4) || 0) + idx + 1).toString().padStart(4, "0")}`;
|
||||||
|
|
||||||
await prisma.$transaction(
|
await prisma.$transaction(
|
||||||
group[g].map((v, i) =>
|
group[g].map((v, i) =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue