diff --git a/src/controllers/ChangePositionController.ts b/src/controllers/ChangePositionController.ts index 294ff7f6..49b925a1 100644 --- a/src/controllers/ChangePositionController.ts +++ b/src/controllers/ChangePositionController.ts @@ -4,14 +4,12 @@ import { Post, Put, Delete, - Patch, Route, Security, Tags, Body, Path, Request, - Example, SuccessResponse, Response, Query, @@ -20,18 +18,18 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; -import { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm"; +import { In, Not, Brackets } from "typeorm"; import { RequestWithUser } from "../middlewares/user"; -import { - ChangePosition, - CreateChangePosition, - UpdateChangePosition +import { + ChangePosition, + CreateChangePosition, + UpdateChangePosition, } from "../entities/ChangePosition"; -import { - ProfileChangePosition, - CreateProfileChangePosition, +import { + ProfileChangePosition, + CreateProfileChangePosition, UpdateProfileChangePosition, - SelectProfileChangePosition + SelectProfileChangePosition, } from "../entities/ProfileChangePosition"; import { OrgRoot } from "../entities/OrgRoot"; import { OrgChild1 } from "../entities/OrgChild1"; @@ -48,8 +46,8 @@ import CallAPI from "../interfaces/call-api"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class ChangePositionController extends Controller { - private changePositionRepository = AppDataSource.getRepository(ChangePosition); - private profileChangePositionRepository = AppDataSource.getRepository(ProfileChangePosition); + private changePositionRepository = AppDataSource.getRepository(ChangePosition); + private profileChangePositionRepository = AppDataSource.getRepository(ProfileChangePosition); private orgRootRepository = AppDataSource.getRepository(OrgRoot); private child1Repository = AppDataSource.getRepository(OrgChild1); private child2Repository = AppDataSource.getRepository(OrgChild2); @@ -70,7 +68,7 @@ export class ChangePositionController extends Controller { const _changePosition = await this.changePositionRepository.findOne({ where: { name: body.name }, }); - if(_changePosition){ + if (_changePosition) { throw new HttpError( HttpStatusCode.INTERNAL_SERVER_ERROR, "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", @@ -79,9 +77,9 @@ export class ChangePositionController extends Controller { const changePosition = new ChangePosition(); Object.assign(changePosition, body); - changePosition.date = new Date, - changePosition.status = "WAITTING", - changePosition.createdUserId = request.user.sub; + (changePosition.date = new Date()), + (changePosition.status = "WAITTING"), + (changePosition.createdUserId = request.user.sub); changePosition.createdFullName = request.user.name; changePosition.lastUpdateUserId = request.user.sub; changePosition.lastUpdateFullName = request.user.name; @@ -126,17 +124,17 @@ export class ChangePositionController extends Controller { @Path() id: string, @Body() body: UpdateChangePosition, ) { - const changePosition = await this.changePositionRepository.findOneBy({ id }); - if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); + if (!changePosition) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); const checkDuplicate = await this.changePositionRepository.find({ - where: { + where: { id: Not(id), - name: body.name + name: body.name, }, }); - if(checkDuplicate.length > 0){ + if (checkDuplicate.length > 0) { throw new HttpError( HttpStatusCode.INTERNAL_SERVER_ERROR, "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", @@ -165,10 +163,10 @@ export class ChangePositionController extends Controller { .createQueryBuilder("changePosition") .leftJoinAndSelect("changePosition.profileChangePosition", "profileChangePosition") .where( - searchKeyword - ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" + searchKeyword + ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" : "1=1", - { keyword: `%${searchKeyword}%` } + { keyword: `%${searchKeyword}%` }, ) .orderBy("changePosition.date", "ASC") .skip((page - 1) * pageSize) @@ -181,7 +179,7 @@ export class ChangePositionController extends Controller { /** * API รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง สถานะเลือกตำแหน่งแล้ว * - * @summary รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง สถานะเลือกตำแหน่งแล้ว (ADMIN) + * @summary รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง สถานะเลือกตำแหน่งแล้ว (ADMIN) * */ @Get("pending") @@ -190,9 +188,9 @@ export class ChangePositionController extends Controller { relations: ["profileChangePosition"], where: { profileChangePosition: { - status: "PENDING" - } - } + status: "PENDING", + }, + }, }); return new HttpSuccess(profiles); } @@ -201,16 +199,15 @@ export class ChangePositionController extends Controller { * API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง * * @summary API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) - * + * * @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง */ @Get("{id}") - async GetChangePositionById( @Path() id: string ) { - - const data = await this.changePositionRepository.findOne({ + async GetChangePositionById(@Path() id: string) { + const data = await this.changePositionRepository.findOne({ relations: ["profileChangePosition"], - where: { id: id }} - ); + where: { id: id }, + }); if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); return new HttpSuccess(data); } @@ -229,18 +226,19 @@ export class ChangePositionController extends Controller { @Request() request: RequestWithUser, ) { const changePosition = await this.changePositionRepository.findOneBy({ id: changePositionId }); - if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); + if (!changePosition) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); const profileChangePositions: ProfileChangePosition[] = []; const profiles = new ProfileChangePosition(); for (const data of body.profiles) { - Object.assign(profiles, data); + Object.assign(profiles, data); let positionOld = data.positionOld ? `${data.positionOld}` : ""; - let rootOld = data.rootOld ? data.positionOld ? `/${data.rootOld}` : `${data.rootOld}` : ""; + let rootOld = data.rootOld ? (data.positionOld ? `/${data.rootOld}` : `${data.rootOld}`) : ""; profiles.changePositionId = changePositionId; - profiles.organizationPositionOld = `${positionOld}${rootOld}`, - profiles.status = "WAITTING", - profiles.createdUserId = request.user.sub; + (profiles.organizationPositionOld = `${positionOld}${rootOld}`), + (profiles.status = "WAITTING"), + (profiles.createdUserId = request.user.sub); profiles.createdFullName = request.user.name; profiles.lastUpdateUserId = request.user.sub; profiles.lastUpdateFullName = request.user.name; @@ -270,16 +268,15 @@ export class ChangePositionController extends Controller { * API รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง * * @summary API รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง (ADMIN) - * + * * @param {string} changePositionId Id รอบย้ายสับเปลี่ยนตำแหน่ง */ @Get("profile-all/{changePositionId}") - async GetProfileChangePositionLists( + async GetProfileChangePositionLists( @Path() changePositionId: string, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query() searchKeyword: string = "", - ) { const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition) .createQueryBuilder("profileChangePosition") @@ -287,7 +284,7 @@ export class ChangePositionController extends Controller { .andWhere( new Brackets((qb) => { qb.where( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.prefix LIKE :keyword" : "1=1", { @@ -295,7 +292,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.firstName LIKE :keyword" : "1=1", { @@ -303,7 +300,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.lastName LIKE :keyword" : "1=1", { @@ -311,7 +308,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.citizenId LIKE :keyword" : "1=1", { @@ -319,7 +316,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.birthDate LIKE :keyword" : "1=1", { @@ -327,7 +324,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.lastUpdatedAt LIKE :keyword" : "1=1", { @@ -335,13 +332,13 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.status LIKE :keyword" : "1=1", { keyword: `%${searchKeyword}%`, }, - ) + ); }), ) .orderBy("profileChangePosition.createdAt", "ASC") @@ -356,17 +353,19 @@ export class ChangePositionController extends Controller { * API รายละเอียดรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง * * @summary API รายละเอียดรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง (ADMIN) - * + * * @param {string} id Id รายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง */ @Get("profile/{id}") - async GetProfileChangePositionById( - @Path() id: string - ) { + async GetProfileChangePositionById(@Path() id: string) { const profileChangePos = await this.profileChangePositionRepository.findOne({ - where: { id: id } + where: { id: id }, }); - if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง"); + if (!profileChangePos) + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง", + ); return new HttpSuccess(profileChangePos); } @@ -383,9 +382,12 @@ export class ChangePositionController extends Controller { @Path() id: string, @Body() body: UpdateProfileChangePosition, ) { - const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); - if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้"); + if (!profileChangePos) + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้", + ); profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateFullName = request.user.name; @@ -395,7 +397,7 @@ export class ChangePositionController extends Controller { profileChangePos.positionLevelOld = body.positionLevelOld; profileChangePos.organizationPositionOld = body.organizationPositionOld; profileChangePos.amountOld = body.amountOld; - profileChangePos.reason = body.reason? String(body.reason) : ""; + profileChangePos.reason = body.reason ? String(body.reason) : ""; profileChangePos.dateCurrent = body.dateCurrent; await this.profileChangePositionRepository.save(profileChangePos); return new HttpSuccess(); @@ -414,9 +416,12 @@ export class ChangePositionController extends Controller { @Path() id: string, @Body() body: SelectProfileChangePosition, ) { - const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); - if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้"); + if (!profileChangePos) + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้", + ); switch (body.node) { case 0: { @@ -507,18 +512,18 @@ export class ChangePositionController extends Controller { profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateFullName = request.user.name; - profileChangePos.node = body.node; - profileChangePos.nodeId = body.nodeId; - profileChangePos.orgRevisionId = body.orgRevisionId; - profileChangePos.posmasterId = body.posmasterId; - profileChangePos.posMasterNo = body.posMasterNo; - profileChangePos.positionId = body.positionId; - profileChangePos.position = body.position; - profileChangePos.positionField = body.positionField; - profileChangePos.posTypeId = String(body.posTypeId); - profileChangePos.posTypeName = body.posTypeName; - profileChangePos.posLevelId = String(body.posLevelId); - profileChangePos.posLevelName = body.posLevelName; + profileChangePos.node = body.node; + profileChangePos.nodeId = body.nodeId; + profileChangePos.orgRevisionId = body.orgRevisionId; + profileChangePos.posmasterId = body.posmasterId; + profileChangePos.posMasterNo = body.posMasterNo; + profileChangePos.positionId = body.positionId; + profileChangePos.position = body.position; + profileChangePos.positionField = body.positionField; + profileChangePos.posTypeId = String(body.posTypeId); + profileChangePos.posTypeName = body.posTypeName; + profileChangePos.posLevelId = String(body.posLevelId); + profileChangePos.posLevelName = body.posLevelName; profileChangePos.status = "PENDING"; await this.profileChangePositionRepository.save(profileChangePos); return new HttpSuccess(); @@ -534,24 +539,24 @@ export class ChangePositionController extends Controller { async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) { const profilechangePositions = await this.changePositionRepository.find({ relations: ["profileChangePosition"], - where: { id: In(requestBody.id) } - }); + where: { id: In(requestBody.id) }, + }); - for (const item of profilechangePositions) { - item.status = "REPORT"; - item.lastUpdateUserId = request.user.sub; - item.lastUpdateFullName = request.user.name; - if (item.profileChangePosition) { - for (const profile of item.profileChangePosition) { - profile.status = "REPORT"; - profile.lastUpdateUserId = request.user.sub; - profile.lastUpdateFullName = request.user.name; - await this.profileChangePositionRepository.save(profile); - } + for (const item of profilechangePositions) { + item.status = "REPORT"; + item.lastUpdateUserId = request.user.sub; + item.lastUpdateFullName = request.user.name; + if (item.profileChangePosition) { + for (const profile of item.profileChangePosition) { + profile.status = "REPORT"; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + await this.profileChangePositionRepository.save(profile); } - await this.changePositionRepository.save(item); } - return new HttpSuccess(); + await this.changePositionRepository.save(item); + } + return new HttpSuccess(); } /** @@ -573,11 +578,11 @@ export class ChangePositionController extends Controller { await Promise.all( body.result.map(async (v) => { const profile = await this.profileChangePositionRepository.findOne({ - where: { id: v.id } + where: { id: v.id }, }); if (profile != null) { await new CallAPI() - .PostData(request, "org/profile/salary", { + .PostData(request, "/org/profile/salary", { profileId: profile.id, date: new Date(), }) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 6d639914..ef8e35a0 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -3,23 +3,19 @@ import { Get, Post, Put, - Delete, - Patch, Route, Security, Tags, Body, Path, Request, - Example, SuccessResponse, Response, - Query, } from "tsoa"; import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; -import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1"; +import { OrgChild1 } from "../entities/OrgChild1"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { In, IsNull, Not } from "typeorm"; @@ -29,7 +25,6 @@ import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; import { PosMaster } from "../entities/PosMaster"; import { Position } from "../entities/Position"; -import { log } from "console"; import CallAPI from "../interfaces/call-api"; import { ProfileSalary } from "../entities/ProfileSalary"; import { Profile } from "../entities/Profile"; @@ -1680,7 +1675,7 @@ export class OrganizationController extends Controller { : item != null && item?.orgRoot != null ? `${item.orgRoot.orgRootShortName}${item.posMasterNo}` : null; - await new CallAPI().PostData(request, "org/profile/salary", { + await new CallAPI().PostData(request, "/org/profile/salary", { profileId: item.next_holderId, date: new Date(), amount: profileSalary?.amount ?? null, diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 2ab1a147..a9de638b 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -37,7 +37,6 @@ import { import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosType } from "../entities/EmployeePosType"; import { RequestWithUser } from "../middlewares/user"; -import { Position } from "../entities/Position"; import { Province } from "../entities/Province"; import { District } from "../entities/District"; import { SubDistrict } from "../entities/SubDistrict"; @@ -63,7 +62,6 @@ import { } from "../entities/ProfileEmployeeEmployment"; import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory"; import CallAPI from "../interfaces/call-api"; -import e from "cors"; import { EmployeePosition } from "../entities/EmployeePosition"; import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; @@ -3131,7 +3129,7 @@ export class ProfileEmployeeController extends Controller { }); if (profile != null) { await new CallAPI() - .PostData(request, "org/profile-employee/salary", { + .PostData(request, "/org/profile-employee/salary", { profileEmployeeId: profile.id, date: new Date(), amount: v.amount, @@ -3148,9 +3146,9 @@ export class ProfileEmployeeController extends Controller { profile.statusTemp = "DONE"; profile.employeeClass = "PERM"; await this.profileRepo.save(profile); - }); + }) await new CallAPI() - .PostData(request, "org/employee/pos/report/current", { + .PostData(request, "/org/employee/pos/report/current", { posmasterId: profile.posmasterIdTemp, positionId: profile.positionIdTemp, profileId: profile.id,