change: branch code now have 5 digit

This commit is contained in:
Methapon Metanipat 2024-08-26 13:15:23 +07:00
parent a312b797c7
commit 2d056d3b56

View file

@ -180,9 +180,9 @@ export class BranchController extends Controller {
) { ) {
const where = { const where = {
AND: { AND: {
zipCode,
headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined), headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined),
NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined }, NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined },
zipCode,
}, },
OR: [ OR: [
{ nameEN: { contains: query } }, { nameEN: { contains: query } },
@ -323,7 +323,7 @@ export class BranchController extends Controller {
if (last.value === 1) { if (last.value === 1) {
const exist = await tx.branch.findFirst({ const exist = await tx.branch.findFirst({
where: { code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(6, "0")}` }, where: { code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(5, "0")}` },
}); });
if (exist) if (exist)
throw new HttpError( throw new HttpError(
@ -352,7 +352,7 @@ export class BranchController extends Controller {
data: { data: {
...rest, ...rest,
statusOrder: +(rest.status === "INACTIVE"), statusOrder: +(rest.status === "INACTIVE"),
code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(6, "0")}`, code: `${code?.toLocaleUpperCase()}${`${last.value - 1}`.padStart(5, "0")}`,
bank: bank ? { createMany: { data: bank } } : undefined, bank: bank ? { createMany: { data: bank } } : undefined,
isHeadOffice: !headOfficeId, isHeadOffice: !headOfficeId,
contact: { contact: {