diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index d4025ca..ef7b634 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -147,26 +147,29 @@ export class CustomerController extends Controller { @Get("{customerId}") @Security("keycloak") async getById(@Path() customerId: string) { - const record = await prisma.customer.findFirst({ - include: { - branch: { - include: { - province: true, - district: true, - subDistrict: true, + const [record, countEmployee] = await prisma.$transaction([ + prisma.customer.findFirst({ + include: { + branch: { + include: { + province: true, + district: true, + subDistrict: true, + }, + orderBy: { createdAt: "asc" }, }, - orderBy: { createdAt: "asc" }, + createdBy: true, + updatedBy: true, }, - createdBy: true, - updatedBy: true, - }, - where: { id: customerId }, - }); + where: { id: customerId }, + }), + prisma.employee.count({ where: { customerBranch: { customerId } } }), + ]); if (!record) { throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "customerNotFound"); } - return record; + return Object.assign(record, { _count: { employee: countEmployee } }); } @Post()