diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index cbba0397..d051704a 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -80,6 +80,55 @@ export class ProfileSalaryController extends Controller { return new HttpSuccess(record); } + @Get("tenure/{profileId}") + public async getPositionTenure(@Path() profileId: string, @Request() req: RequestWithUser) { + const position = await AppDataSource.query( + "CALL GetProfileSalaryPosition(?)", + [profileId] + ); + const _position = position.length > 0 ? position[0] : [] + const mapPosition = _position.length > 1 + ? _position + .slice(1) + .map((curr: any, index: number) => ({ + year: curr.Years ? Math.floor(Number(curr.Years)) : 0, + month: curr.Months ? Math.floor(Number(curr.Months)) : 0, + day: curr.Days ? Math.floor(Number(curr.Days)) : 0, + name: _position[index]?.positionName + })) + : []; + + const posLevel = [{ + year: 1, + month: 0, + day: 0, + name: "ต้น", + }]; + + const posExecutive = await AppDataSource.query( + "CALL GetProfileSalaryExecutive(?)", + [profileId] + ); + const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : [] + const mapPosExecutive = _posExecutive.length > 1 + ? _posExecutive + .slice(1) + .map((curr: any, index: number) => ({ + year: curr.Years ? Math.floor(Number(curr.Years)) : 0, + month: curr.Months ? Math.floor(Number(curr.Months)) : 0, + day: curr.Days ? Math.floor(Number(curr.Days)) : 0, + name: _posExecutive[index]?.positionName + })) + : []; + + return new HttpSuccess({ + position: mapPosition, + posLevel: posLevel, + posExecutive: mapPosExecutive + }); + } + + @Get("admin/{profileId}") public async getSalaryAdmin(@Path() profileId: string, @Request() req: RequestWithUser) { let _workflow = await new permission().Workflow(req, profileId, "SYS_SALARY_OFFICER");