From b78d0618b47c35858f95289e5c9abc72ed3031ad Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 1 Feb 2024 13:28:46 +0700 Subject: [PATCH] fix org_053 --- src/controllers/PositionController.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 2f23cb7b..ed88196b 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -780,14 +780,20 @@ export class PositionController extends Controller { ...typeCondition, ...checkChildConditions, }, + skip: (body.page - 1) * body.pageSize, + take: body.pageSize, }); - if (!posMaster || posMaster.length === 0) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } + const total = posMaster.length; + + // if (!posMaster || posMaster.length === 0) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + // } + const formattedData = await Promise.all( posMaster.map(async (posMaster) => { const positions = await this.positionRepository.find({ where: { posMasterId: posMaster.id }, + relations:["posLevel","posType","posExecutive"] }); return { @@ -813,7 +819,7 @@ export class PositionController extends Controller { }; }), ); - return new HttpSuccess(formattedData); + return new HttpSuccess({data:formattedData,total}); } catch (error) { return error; }