feat: add order field
This commit is contained in:
parent
aa8dcdaf86
commit
0bd2c1ecf2
11 changed files with 79 additions and 26 deletions
|
|
@ -0,0 +1,29 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Branch" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Customer" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "CustomerBranch" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Employee" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Product" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ProductGroup" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ProductType" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Service" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Work" ADD COLUMN "statusOrder" INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
@ -212,7 +212,8 @@ model Branch {
|
||||||
headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id])
|
headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id])
|
||||||
headOfficeId String?
|
headOfficeId String?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -312,7 +313,8 @@ model User {
|
||||||
|
|
||||||
birthDate DateTime?
|
birthDate DateTime?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -339,7 +341,8 @@ model Customer {
|
||||||
customerNameEN String
|
customerNameEN String
|
||||||
taxNo String?
|
taxNo String?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -393,7 +396,8 @@ model CustomerBranch {
|
||||||
payDate DateTime
|
payDate DateTime
|
||||||
wageRate Int
|
wageRate Int
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -452,7 +456,8 @@ model Employee {
|
||||||
customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull)
|
customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull)
|
||||||
customerBranchId String?
|
customerBranchId String?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -544,8 +549,10 @@ model Service {
|
||||||
detail String
|
detail String
|
||||||
attributes Json?
|
attributes Json?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
work Work[]
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
|
work Work[]
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -560,7 +567,8 @@ model Work {
|
||||||
name String
|
name String
|
||||||
attributes Json?
|
attributes Json?
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
service Service? @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
service Service? @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
||||||
serviceId String?
|
serviceId String?
|
||||||
|
|
@ -596,7 +604,8 @@ model ProductGroup {
|
||||||
detail String
|
detail String
|
||||||
remark String
|
remark String
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -614,7 +623,8 @@ model ProductType {
|
||||||
detail String
|
detail String
|
||||||
remark String
|
remark String
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
createdBy String?
|
createdBy String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
@ -638,7 +648,8 @@ model Product {
|
||||||
agentPrice Int
|
agentPrice Int
|
||||||
serviceCharge Int
|
serviceCharge Int
|
||||||
|
|
||||||
status Status @default(CREATED)
|
status Status @default(CREATED)
|
||||||
|
statusOrder Int @default(0)
|
||||||
|
|
||||||
remark String?
|
remark String?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,7 @@ export class BranchContactController extends Controller {
|
||||||
@Body() body: BranchContactCreate,
|
@Body() body: BranchContactCreate,
|
||||||
) {
|
) {
|
||||||
if (!(await prisma.branch.findFirst({ where: { id: branchId } }))) {
|
if (!(await prisma.branch.findFirst({ where: { id: branchId } }))) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatus.BAD_REQUEST, "Branch cannot be found.", "branchBadReq");
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
"Branch cannot be found.",
|
|
||||||
"branchBadReq",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const record = await prisma.branchContact.create({
|
const record = await prisma.branchContact.create({
|
||||||
data: { ...body, branchId, createdBy: req.user.name, updateBy: req.user.name },
|
data: { ...body, branchId, createdBy: req.user.name, updateBy: req.user.name },
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,7 @@ export class BranchController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
code,
|
code,
|
||||||
isHeadOffice: !headOfficeId,
|
isHeadOffice: !headOfficeId,
|
||||||
province: { connect: provinceId ? { id: provinceId } : undefined },
|
province: { connect: provinceId ? { id: provinceId } : undefined },
|
||||||
|
|
@ -384,6 +385,7 @@ export class BranchController extends Controller {
|
||||||
include: { province: true, district: true, subDistrict: true },
|
include: { province: true, district: true, subDistrict: true },
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
isHeadOffice: headOfficeId !== undefined ? headOfficeId === null : undefined,
|
isHeadOffice: headOfficeId !== undefined ? headOfficeId === null : undefined,
|
||||||
province: {
|
province: {
|
||||||
connect: provinceId ? { id: provinceId } : undefined,
|
connect: provinceId ? { id: provinceId } : undefined,
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,7 @@ export class CustomerBranchController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
branchNo: count + 1,
|
branchNo: count + 1,
|
||||||
code: `${customer.code}-${(count + 1).toString().padStart(2, "0")}`,
|
code: `${customer.code}-${(count + 1).toString().padStart(2, "0")}`,
|
||||||
customer: { connect: { id: customerId } },
|
customer: { connect: { id: customerId } },
|
||||||
|
|
@ -365,6 +366,7 @@ export class CustomerBranchController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
customer: { connect: customerId ? { id: customerId } : undefined },
|
customer: { connect: customerId ? { id: customerId } : undefined },
|
||||||
province: {
|
province: {
|
||||||
connect: provinceId ? { id: provinceId } : undefined,
|
connect: provinceId ? { id: provinceId } : undefined,
|
||||||
|
|
@ -403,7 +405,11 @@ export class CustomerBranchController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (record.status !== Status.CREATED) {
|
if (record.status !== Status.CREATED) {
|
||||||
throw new HttpError(HttpStatus.FORBIDDEN, "Customer branch is in used.", "customerBranchInUsed");
|
throw new HttpError(
|
||||||
|
HttpStatus.FORBIDDEN,
|
||||||
|
"Customer branch is in used.",
|
||||||
|
"customerBranchInUsed",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prisma.customerBranch.delete({ where: { id: branchId } }).then((v) => {
|
return await prisma.customerBranch.delete({ where: { id: branchId } }).then((v) => {
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,7 @@ export class CustomerController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...payload,
|
...payload,
|
||||||
|
statusOrder: +(payload.status === "INACTIVE"),
|
||||||
code: `${last.key.slice(9)}${last.value.toString().padStart(6, "0")}`,
|
code: `${last.key.slice(9)}${last.value.toString().padStart(6, "0")}`,
|
||||||
branch: {
|
branch: {
|
||||||
createMany: {
|
createMany: {
|
||||||
|
|
@ -420,6 +421,7 @@ export class CustomerController extends Controller {
|
||||||
where: { id: customerId },
|
where: { id: customerId },
|
||||||
data: {
|
data: {
|
||||||
...payload,
|
...payload,
|
||||||
|
statusOrder: +(payload.status === "INACTIVE"),
|
||||||
branch:
|
branch:
|
||||||
(customerBranch && {
|
(customerBranch && {
|
||||||
deleteMany: {
|
deleteMany: {
|
||||||
|
|
|
||||||
|
|
@ -395,6 +395,7 @@ export class EmployeeController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
code: `${customerBranch.customer.code}-${customerBranch.branchNo.toString().padStart(2, "0")}-${new Date().getFullYear().toString().slice(-2).padStart(2, "0")}${last.value.toString().padStart(4, "0")}`,
|
code: `${customerBranch.customer.code}-${customerBranch.branchNo.toString().padStart(2, "0")}-${new Date().getFullYear().toString().slice(-2).padStart(2, "0")}${last.value.toString().padStart(4, "0")}`,
|
||||||
employeeWork: {
|
employeeWork: {
|
||||||
createMany: {
|
createMany: {
|
||||||
|
|
@ -562,6 +563,7 @@ export class EmployeeController extends Controller {
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
code,
|
code,
|
||||||
customerBranch: { connect: customerBranchId ? { id: customerBranchId } : undefined },
|
customerBranch: { connect: customerBranchId ? { id: customerBranchId } : undefined },
|
||||||
employeeWork: employeeWork
|
employeeWork: employeeWork
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ export class ProductGroup extends Controller {
|
||||||
return await tx.productGroup.create({
|
return await tx.productGroup.create({
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
code: `G${last.value.toString().padStart(2, "0")}`,
|
code: `G${last.value.toString().padStart(2, "0")}`,
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
|
|
@ -124,7 +125,7 @@ export class ProductGroup extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const record = await prisma.productGroup.update({
|
const record = await prisma.productGroup.update({
|
||||||
data: { ...body, updateBy: req.user.name },
|
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updateBy: req.user.name },
|
||||||
where: { id: groupId },
|
where: { id: groupId },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,7 @@ export class ProductController extends Controller {
|
||||||
return await prisma.product.create({
|
return await prisma.product.create({
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
code: `${body.code.toLocaleUpperCase()}${last.value.toString().padStart(3, "0")}`,
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
|
|
@ -229,13 +230,13 @@ export class ProductController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const record = await prisma.product.update({
|
const record = await prisma.product.update({
|
||||||
data: { ...body, updateBy: req.user.name },
|
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updateBy: req.user.name },
|
||||||
where: { id: productId },
|
where: { id: productId },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (productType.status === "CREATED") {
|
if (productType.status === "CREATED") {
|
||||||
await prisma.productType.update({
|
await prisma.productType.updateMany({
|
||||||
where: { id: body.productTypeId },
|
where: { id: body.productTypeId, status: Status.CREATED },
|
||||||
data: { status: Status.ACTIVE },
|
data: { status: Status.ACTIVE },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ export class ProductType extends Controller {
|
||||||
return await tx.productType.create({
|
return await tx.productType.create({
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
|
statusOrder: +(body.status === "INACTIVE"),
|
||||||
code: `T${productGroup.code}${last.value.toString().padStart(2, "0")}`,
|
code: `T${productGroup.code}${last.value.toString().padStart(2, "0")}`,
|
||||||
createdBy: req.user.name,
|
createdBy: req.user.name,
|
||||||
updateBy: req.user.name,
|
updateBy: req.user.name,
|
||||||
|
|
@ -161,13 +162,13 @@ export class ProductType extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const record = await prisma.productType.update({
|
const record = await prisma.productType.update({
|
||||||
data: { ...body, updateBy: req.user.name },
|
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updateBy: req.user.name },
|
||||||
where: { id: typeId },
|
where: { id: typeId },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (productGroup?.status === "CREATED") {
|
if (productGroup?.status === "CREATED") {
|
||||||
await prisma.productGroup.update({
|
await prisma.productGroup.update({
|
||||||
where: { id: body.productGroupId },
|
where: { id: body.productGroupId, status: Status.CREATED },
|
||||||
data: { status: Status.ACTIVE },
|
data: { status: Status.ACTIVE },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,8 +209,7 @@ export class UserController extends Controller {
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!record)
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound");
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "userNotFound");
|
|
||||||
|
|
||||||
return Object.assign(record, {
|
return Object.assign(record, {
|
||||||
profileImageUrl: await minio.presignedGetObject(
|
profileImageUrl: await minio.presignedGetObject(
|
||||||
|
|
@ -268,6 +267,7 @@ export class UserController extends Controller {
|
||||||
firstName: body.firstName,
|
firstName: body.firstName,
|
||||||
lastName: body.lastName,
|
lastName: body.lastName,
|
||||||
requiredActions: ["UPDATE_PASSWORD"],
|
requiredActions: ["UPDATE_PASSWORD"],
|
||||||
|
enabled: rest.status !== "INACTIVE",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!userId || typeof userId !== "string") {
|
if (!userId || typeof userId !== "string") {
|
||||||
|
|
@ -288,6 +288,7 @@ export class UserController extends Controller {
|
||||||
data: {
|
data: {
|
||||||
id: userId,
|
id: userId,
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
username,
|
username,
|
||||||
userRole: role.name,
|
userRole: role.name,
|
||||||
province: { connect: provinceId ? { id: provinceId } : undefined },
|
province: { connect: provinceId ? { id: provinceId } : undefined },
|
||||||
|
|
@ -386,7 +387,7 @@ export class UserController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.username) {
|
if (body.username) {
|
||||||
await editUser(userId, { username: body.username });
|
await editUser(userId, { username: body.username, enabled: body.status !== "INACTIVE" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const { provinceId, districtId, subDistrictId, ...rest } = body;
|
const { provinceId, districtId, subDistrictId, ...rest } = body;
|
||||||
|
|
@ -415,6 +416,7 @@ export class UserController extends Controller {
|
||||||
include: { province: true, district: true, subDistrict: true },
|
include: { province: true, district: true, subDistrict: true },
|
||||||
data: {
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
|
statusOrder: +(rest.status === "INACTIVE"),
|
||||||
userRole,
|
userRole,
|
||||||
code:
|
code:
|
||||||
(lastUserOfType &&
|
(lastUserOfType &&
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue