feat: add user relation on query
This commit is contained in:
parent
2bd30b735d
commit
9f3b8cd290
14 changed files with 259 additions and 41 deletions
|
|
@ -38,6 +38,7 @@ export class BranchContactController extends Controller {
|
|||
) {
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.branchContact.findMany({
|
||||
include: { createdBy: true, updatedBy: true },
|
||||
orderBy: { createdAt: "asc" },
|
||||
where: { branchId },
|
||||
take: pageSize,
|
||||
|
|
@ -79,6 +80,10 @@ export class BranchContactController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "Branch cannot be found.", "branchBadReq");
|
||||
}
|
||||
const record = await prisma.branchContact.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: { ...body, branchId, createdByUserId: req.user.sub, updatedByUserId: req.user.sub },
|
||||
});
|
||||
|
||||
|
|
@ -107,6 +112,7 @@ export class BranchContactController extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.branchContact.update({
|
||||
include: { createdBy: true, updatedBy: true },
|
||||
data: { ...body, updatedByUserId: req.user.sub },
|
||||
where: { id: contactId, branchId },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -173,6 +173,8 @@ export class BranchController extends Controller {
|
|||
subDistrict: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -195,6 +197,8 @@ export class BranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
branch: includeSubBranch && {
|
||||
include: {
|
||||
province: true,
|
||||
|
|
@ -276,6 +280,8 @@ export class BranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...rest,
|
||||
|
|
@ -442,6 +448,8 @@ export class BranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: branchId },
|
||||
});
|
||||
|
|
@ -466,6 +474,8 @@ export class BranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: branchId },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ export class CustomerBranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
_count: true,
|
||||
},
|
||||
where,
|
||||
|
|
@ -177,6 +179,8 @@ export class CustomerBranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: branchId },
|
||||
});
|
||||
|
|
@ -213,6 +217,8 @@ export class CustomerBranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -284,6 +290,8 @@ export class CustomerBranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...rest,
|
||||
|
|
@ -363,6 +371,8 @@ export class CustomerBranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...rest,
|
||||
|
|
@ -411,27 +421,32 @@ export class CustomerBranchController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
return await prisma.customerBranch.delete({ where: { id: branchId } }).then((v) => {
|
||||
new Promise<string[]>((resolve, reject) => {
|
||||
const item: string[] = [];
|
||||
return await prisma.customerBranch
|
||||
.delete({
|
||||
include: { createdBy: true, updatedBy: true },
|
||||
where: { id: branchId },
|
||||
})
|
||||
.then((v) => {
|
||||
new Promise<string[]>((resolve, reject) => {
|
||||
const item: string[] = [];
|
||||
|
||||
const stream = minio.listObjectsV2(
|
||||
MINIO_BUCKET,
|
||||
`${attachmentLocation(record.customerId, branchId)}/`,
|
||||
);
|
||||
const stream = minio.listObjectsV2(
|
||||
MINIO_BUCKET,
|
||||
`${attachmentLocation(record.customerId, branchId)}/`,
|
||||
);
|
||||
|
||||
stream.on("data", (v) => v && v.name && item.push(v.name));
|
||||
stream.on("end", () => resolve(item));
|
||||
stream.on("error", () => reject(new Error("MinIO error.")));
|
||||
}).then((list) => {
|
||||
list.map(async (v) => {
|
||||
await minio.removeObject(MINIO_BUCKET, v, {
|
||||
forceDelete: true,
|
||||
stream.on("data", (v) => v && v.name && item.push(v.name));
|
||||
stream.on("end", () => resolve(item));
|
||||
stream.on("error", () => reject(new Error("MinIO error.")));
|
||||
}).then((list) => {
|
||||
list.map(async (v) => {
|
||||
await minio.removeObject(MINIO_BUCKET, v, {
|
||||
forceDelete: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
return v;
|
||||
});
|
||||
return v;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ export class CustomerController extends Controller {
|
|||
},
|
||||
}
|
||||
: undefined,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
|
|
@ -211,6 +213,8 @@ export class CustomerController extends Controller {
|
|||
subDistrict: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: customerId },
|
||||
});
|
||||
|
|
@ -293,6 +297,8 @@ export class CustomerController extends Controller {
|
|||
subDistrict: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...payload,
|
||||
|
|
@ -417,6 +423,8 @@ export class CustomerController extends Controller {
|
|||
subDistrict: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: customerId },
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ export class EmployeeCheckupController extends Controller {
|
|||
@Get()
|
||||
async list(@Path() employeeId: string) {
|
||||
return prisma.employeeCheckup.findMany({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
where: { employeeId },
|
||||
});
|
||||
|
|
@ -45,6 +49,10 @@ export class EmployeeCheckupController extends Controller {
|
|||
@Get("{checkupId}")
|
||||
async getById(@Path() employeeId: string, @Path() checkupId: string) {
|
||||
const record = await prisma.employeeCheckup.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: checkupId, employeeId },
|
||||
});
|
||||
if (!record) {
|
||||
|
|
@ -85,7 +93,7 @@ export class EmployeeCheckupController extends Controller {
|
|||
const { provinceId, ...rest } = body;
|
||||
|
||||
const record = await prisma.employeeCheckup.create({
|
||||
include: { province: true },
|
||||
include: { province: true, createdBy: true, updatedBy: true },
|
||||
data: {
|
||||
...rest,
|
||||
province: { connect: provinceId ? { id: provinceId } : undefined },
|
||||
|
|
@ -128,7 +136,12 @@ export class EmployeeCheckupController extends Controller {
|
|||
|
||||
const { provinceId, ...rest } = body;
|
||||
|
||||
if (!(await prisma.employeeCheckup.findUnique({ where: { id: checkupId, employeeId } }))) {
|
||||
if (
|
||||
!(await prisma.employeeCheckup.findUnique({
|
||||
include: { createdBy: true, updatedBy: true },
|
||||
where: { id: checkupId, employeeId },
|
||||
}))
|
||||
) {
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Employee checkup cannot be found.",
|
||||
|
|
@ -137,7 +150,7 @@ export class EmployeeCheckupController extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.employeeCheckup.update({
|
||||
include: { province: true },
|
||||
include: { province: true, createdBy: true, updatedBy: true },
|
||||
where: { id: checkupId, employeeId },
|
||||
data: {
|
||||
...rest,
|
||||
|
|
@ -163,6 +176,9 @@ export class EmployeeCheckupController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
return await prisma.employeeCheckup.delete({ where: { id: checkupId, employeeId } });
|
||||
return await prisma.employeeCheckup.delete({
|
||||
include: { createdBy: true, updatedBy: true },
|
||||
where: { id: checkupId, employeeId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,6 +258,8 @@ export class EmployeeController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -290,6 +292,8 @@ export class EmployeeController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: employeeId },
|
||||
});
|
||||
|
|
@ -392,6 +396,8 @@ export class EmployeeController extends Controller {
|
|||
},
|
||||
},
|
||||
employeeWork: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...rest,
|
||||
|
|
@ -561,6 +567,8 @@ export class EmployeeController extends Controller {
|
|||
},
|
||||
},
|
||||
employeeWork: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...rest,
|
||||
|
|
@ -694,7 +702,13 @@ export class EmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Employee is in used.", "employeeInUsed");
|
||||
}
|
||||
|
||||
return await prisma.employee.delete({ where: { id: employeeId } });
|
||||
return await prisma.employee.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: employeeId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get("{employeeId}/edit-history")
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ export class EmployeeOtherInfo extends Controller {
|
|||
@Get()
|
||||
async list(@Path() employeeId: string) {
|
||||
return prisma.employeeOtherInfo.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
where: { employeeId },
|
||||
});
|
||||
|
|
@ -54,6 +58,10 @@ export class EmployeeOtherInfo extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "Employee cannot be found.", "employeeBadReq");
|
||||
|
||||
const record = await prisma.employeeOtherInfo.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
employee: { connect: { id: employeeId } },
|
||||
|
|
@ -83,6 +91,10 @@ export class EmployeeOtherInfo extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.employeeOtherInfo.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: otherInfoId, employeeId },
|
||||
data: { ...body, updatedByUserId: req.user.sub },
|
||||
});
|
||||
|
|
@ -106,6 +118,12 @@ export class EmployeeOtherInfo extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
return await prisma.employeeOtherInfo.delete({ where: { id: otherInfoId, employeeId } });
|
||||
return await prisma.employeeOtherInfo.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: otherInfoId, employeeId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ export class EmployeeWorkController extends Controller {
|
|||
@Get()
|
||||
async list(@Path() employeeId: string) {
|
||||
return prisma.employeeWork.findMany({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
where: { employeeId },
|
||||
});
|
||||
|
|
@ -43,6 +47,10 @@ export class EmployeeWorkController extends Controller {
|
|||
@Get("{workId}")
|
||||
async getById(@Path() employeeId: string, @Path() workId: string) {
|
||||
const record = await prisma.employeeWork.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: workId, employeeId },
|
||||
});
|
||||
if (!record) {
|
||||
|
|
@ -65,6 +73,10 @@ export class EmployeeWorkController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "Employee cannot be found.", "employeeBadReq");
|
||||
|
||||
const record = await prisma.employeeWork.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
employee: { connect: { id: employeeId } },
|
||||
|
|
@ -94,6 +106,10 @@ export class EmployeeWorkController extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.employeeWork.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: workId, employeeId },
|
||||
data: { ...body, updatedByUserId: req.user.sub },
|
||||
});
|
||||
|
|
@ -105,7 +121,13 @@ export class EmployeeWorkController extends Controller {
|
|||
|
||||
@Delete("{workId}")
|
||||
async deleteById(@Path() employeeId: string, @Path() workId: string) {
|
||||
const record = await prisma.employeeWork.findFirst({ where: { id: workId, employeeId } });
|
||||
const record = await prisma.employeeWork.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: workId, employeeId },
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ export class ProductGroup extends Controller {
|
|||
type: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
|
|
@ -139,6 +141,10 @@ export class ProductGroup extends Controller {
|
|||
});
|
||||
|
||||
return await tx.productGroup.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
|
|
@ -171,6 +177,10 @@ export class ProductGroup extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.productGroup.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
where: { id: groupId },
|
||||
});
|
||||
|
|
@ -194,6 +204,12 @@ export class ProductGroup extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Product group is in used.", "productGroupInUsed");
|
||||
}
|
||||
|
||||
return await prisma.productGroup.delete({ where: { id: groupId } });
|
||||
return await prisma.productGroup.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: groupId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ export class ProductController extends Controller {
|
|||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.product.findMany({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -118,6 +122,10 @@ export class ProductController extends Controller {
|
|||
@Security("keycloak")
|
||||
async getProductById(@Path() productId: string) {
|
||||
const record = await prisma.product.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: productId },
|
||||
});
|
||||
|
||||
|
|
@ -145,6 +153,10 @@ export class ProductController extends Controller {
|
|||
@Security("keycloak")
|
||||
async createProduct(@Request() req: RequestWithUser, @Body() body: ProductCreate) {
|
||||
const productType = await prisma.productType.findFirst({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: body.productTypeId },
|
||||
});
|
||||
|
||||
|
|
@ -169,6 +181,10 @@ export class ProductController extends Controller {
|
|||
update: { value: { increment: 1 } },
|
||||
});
|
||||
return await prisma.product.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
|
|
@ -185,6 +201,10 @@ export class ProductController extends Controller {
|
|||
|
||||
if (productType.status === "CREATED") {
|
||||
await prisma.productType.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: body.productTypeId },
|
||||
data: { status: Status.ACTIVE },
|
||||
});
|
||||
|
|
@ -230,6 +250,10 @@ export class ProductController extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.product.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
where: { id: productId },
|
||||
});
|
||||
|
|
@ -268,6 +292,12 @@ export class ProductController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Product is in used.", "productInUsed");
|
||||
}
|
||||
|
||||
return await prisma.product.delete({ where: { id: productId } });
|
||||
return await prisma.product.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: productId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ export class ProductType extends Controller {
|
|||
_count: {
|
||||
select: { product: true },
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
|
|
@ -128,6 +130,10 @@ export class ProductType extends Controller {
|
|||
});
|
||||
|
||||
return await tx.productType.create({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
|
|
@ -178,7 +184,15 @@ export class ProductType extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.productType.update({
|
||||
data: { ...body, statusOrder: +(body.status === "INACTIVE"), updatedByUserId: req.user.sub },
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...body,
|
||||
statusOrder: +(body.status === "INACTIVE"),
|
||||
updatedByUserId: req.user.sub,
|
||||
},
|
||||
where: { id: typeId },
|
||||
});
|
||||
|
||||
|
|
@ -208,6 +222,12 @@ export class ProductType extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Product type is in used.", "productTypeInUsed");
|
||||
}
|
||||
|
||||
return await prisma.productType.delete({ where: { id: typeId } });
|
||||
return await prisma.productType.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: typeId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,8 @@ export class ServiceController extends Controller {
|
|||
prisma.service.findMany({
|
||||
include: {
|
||||
work: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }],
|
||||
where,
|
||||
|
|
@ -135,6 +137,8 @@ export class ServiceController extends Controller {
|
|||
},
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: serviceId },
|
||||
});
|
||||
|
|
@ -168,6 +172,8 @@ export class ServiceController extends Controller {
|
|||
},
|
||||
orderBy: { order: "asc" },
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -239,6 +245,8 @@ export class ServiceController extends Controller {
|
|||
},
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...payload,
|
||||
|
|
@ -301,6 +309,10 @@ export class ServiceController extends Controller {
|
|||
);
|
||||
|
||||
return await tx.service.update({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...payload,
|
||||
statusOrder: +(payload.status === "INACTIVE"),
|
||||
|
|
@ -341,6 +353,12 @@ export class ServiceController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Service is in used.", "serviceInUsed");
|
||||
}
|
||||
|
||||
return await prisma.service.delete({ where: { id: serviceId } });
|
||||
return await prisma.service.delete({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: serviceId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,6 +173,8 @@ export class UserController extends Controller {
|
|||
district: true,
|
||||
subDistrict: true,
|
||||
branch: { include: { branch: includeBranch } },
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -207,6 +209,8 @@ export class UserController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
|
|
@ -287,7 +291,13 @@ export class UserController extends Controller {
|
|||
}
|
||||
|
||||
const record = await prisma.user.create({
|
||||
include: { province: true, district: true, subDistrict: true },
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
id: userId,
|
||||
...rest,
|
||||
|
|
@ -417,7 +427,13 @@ export class UserController extends Controller {
|
|||
}));
|
||||
|
||||
const record = await prisma.user.update({
|
||||
include: { province: true, district: true, subDistrict: true },
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...rest,
|
||||
statusOrder: +(rest.status === "INACTIVE"),
|
||||
|
|
@ -465,6 +481,8 @@ export class UserController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
|
|
@ -502,6 +520,8 @@ export class UserController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
|
|
@ -519,11 +539,6 @@ export class UserAttachmentController extends Controller {
|
|||
@Get()
|
||||
async listAttachment(@Path() userId: string) {
|
||||
const record = await prisma.user.findFirst({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
|
||||
|
|
@ -552,11 +567,6 @@ export class UserAttachmentController extends Controller {
|
|||
@Post()
|
||||
async addAttachment(@Path() userId: string, @Body() payload: { file: string[] }) {
|
||||
const record = await prisma.user.findFirst({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ export class WorkController extends Controller {
|
|||
order: "asc",
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
where,
|
||||
|
|
@ -106,6 +108,10 @@ export class WorkController extends Controller {
|
|||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.product.findMany({
|
||||
include: {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * pageSize,
|
||||
|
|
@ -129,6 +135,8 @@ export class WorkController extends Controller {
|
|||
product: true,
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: {
|
||||
productOnWork: {
|
||||
|
|
@ -175,6 +183,8 @@ export class WorkController extends Controller {
|
|||
order: "asc",
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
data: {
|
||||
...payload,
|
||||
|
|
@ -261,6 +271,8 @@ export class WorkController extends Controller {
|
|||
order: "asc",
|
||||
},
|
||||
},
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
},
|
||||
where: { id: workId },
|
||||
data: {
|
||||
|
|
@ -296,7 +308,10 @@ export class WorkController extends Controller {
|
|||
|
||||
@Delete("{workId}")
|
||||
async deleteWork(@Path() workId: string) {
|
||||
const record = await prisma.work.findFirst({ where: { id: workId } });
|
||||
const record = await prisma.work.findFirst({
|
||||
include: { createdBy: true, updatedBy: true },
|
||||
where: { id: workId },
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "Work cannot be found.", "workNotFound");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue