refactor!: user code gen
This commit is contained in:
parent
e0b3ed6383
commit
c434b085bc
1 changed files with 10 additions and 3 deletions
|
|
@ -28,12 +28,19 @@ async function userBranchCodeGen(branch: Branch, user: User[]) {
|
||||||
|
|
||||||
const typ = usr.userType;
|
const typ = usr.userType;
|
||||||
|
|
||||||
|
const mapTypeNo = {
|
||||||
|
USER: 1,
|
||||||
|
MESSENGER: 2,
|
||||||
|
DELEGATE: 3,
|
||||||
|
AGENCY: 4,
|
||||||
|
}[typ];
|
||||||
|
|
||||||
const last = await tx.runningNo.upsert({
|
const last = await tx.runningNo.upsert({
|
||||||
where: {
|
where: {
|
||||||
key: `BR_USR_${branch.code.slice(4).padEnd(3, "0")}${typ !== "USER" ? typ.charAt(0).toLocaleUpperCase() : ""}`,
|
key: `BR_USR_${branch.code}_${mapTypeNo}`,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
key: `BR_USR_${branch.code.slice(4).padEnd(3, "0")}${typ !== "USER" ? typ.charAt(0).toLocaleUpperCase() : ""}`,
|
key: `BR_USR_${branch.code}_${mapTypeNo}`,
|
||||||
value: 1,
|
value: 1,
|
||||||
},
|
},
|
||||||
update: { value: { increment: 1 } },
|
update: { value: { increment: 1 } },
|
||||||
|
|
@ -42,7 +49,7 @@ async function userBranchCodeGen(branch: Branch, user: User[]) {
|
||||||
await tx.user.update({
|
await tx.user.update({
|
||||||
where: { id: usr.id },
|
where: { id: usr.id },
|
||||||
data: {
|
data: {
|
||||||
code: `${last.key.slice(7)}${last.value.toString().padStart(4, "0")}`,
|
code: mapTypeNo + `${last.value}`.padStart(6, "9"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue