diff --git a/src/controllers/ApiManageController.ts b/src/controllers/ApiManageController.ts new file mode 100644 index 00000000..66fd875f --- /dev/null +++ b/src/controllers/ApiManageController.ts @@ -0,0 +1,728 @@ +import { ApiKey } from "./../entities/ApiKey"; +import { ApiAttribute } from "./../entities/ApiAttribute"; +import { CreateApi } from "./../entities/ApiName"; +import { PosMaster } from "../entities/PosMaster"; +import { OrgChild4 } from "../entities/OrgChild4"; +import { OrgChild3 } from "../entities/OrgChild3"; +import { OrgChild2 } from "../entities/OrgChild2"; +import { OrgChild1 } from "../entities/OrgChild1"; +import { OrgRoot } from "../entities/OrgRoot"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { ProfileSalary } from "../entities/ProfileSalary"; +import { ProfileOther } from "../entities/ProfileOther"; +import { ProfileNopaid } from "../entities/ProfileNopaid"; +import { ProfileLeave } from "../entities/ProfileLeave"; +import { ProfileInsignia } from "../entities/ProfileInsignia"; +import { ProfileHonor } from "../entities/ProfileHonor"; +import { ProfileGovernment } from "../entities/ProfileGovernment"; +import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; +import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; +import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; +import { ProfileEducation } from "../entities/ProfileEducation"; +import { ProfileDuty } from "../entities/ProfileDuty"; +import { ProfileDiscipline } from "../entities/ProfileDiscipline"; +import { ProfileDevelopment } from "../entities/ProfileDevelopment"; +import { ProfileChildren } from "../entities/ProfileChildren"; +import { ProfileChangeName } from "../entities/ProfileChangeName"; +import { ProfileCertificate } from "../entities/ProfileCertificate"; +import { ProfileAssessment } from "../entities/ProfileAssessment"; +import { ProfileAbility } from "../entities/ProfileAbility"; +import { + Controller, + Post, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Response, + Get, + Put, + Query, +} from "tsoa"; +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 { RequestWithUser } from "../middlewares/user"; +import { ApiName } from "../entities/ApiName"; +import { Profile } from "../entities/Profile"; + +@Route("api/v1/org/api-manage") +@Tags("ApiManage") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +export class ApiManageController extends Controller { + // private apiNameRepository = AppDataSource.getRepository(ApiName); + private profileRepository = AppDataSource.getRepository(Profile); + private profileEmployeeRepository = AppDataSource.getRepository(ProfileEmployee); + private profileGovernmentRepository = AppDataSource.getRepository(ProfileGovernment); + private profileProfileSalaryRepository = AppDataSource.getRepository(ProfileSalary); + private profileAbilityRepository = AppDataSource.getRepository(ProfileAbility); + private profileAssessmentRepository = AppDataSource.getRepository(ProfileAssessment); + private profileCertificateRepository = AppDataSource.getRepository(ProfileCertificate); + private profileHonorRepository = AppDataSource.getRepository(ProfileHonor); + private profileInsigniaRepository = AppDataSource.getRepository(ProfileInsignia); + private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave); + private profileChangeNameRepository = AppDataSource.getRepository(ProfileChangeName); + private profileDevelopmentRepository = AppDataSource.getRepository(ProfileDevelopment); + private profileDisciplineRepository = AppDataSource.getRepository(ProfileDiscipline); + private profileDutyRepository = AppDataSource.getRepository(ProfileDuty); + private profileEducationRepository = AppDataSource.getRepository(ProfileEducation); + private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple); + private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather); + private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother); + private profileChildrenRepository = AppDataSource.getRepository(ProfileChildren); + private profileNopaidRepository = AppDataSource.getRepository(ProfileNopaid); + private profileOtherRepository = AppDataSource.getRepository(ProfileOther); + private orgRootRepository = AppDataSource.getRepository(OrgRoot); + private orgChild1Repository = AppDataSource.getRepository(OrgChild1); + private orgChild2Repository = AppDataSource.getRepository(OrgChild2); + private orgChild3Repository = AppDataSource.getRepository(OrgChild3); + private orgChild4Repository = AppDataSource.getRepository(OrgChild4); + private posMasterRepository = AppDataSource.getRepository(PosMaster); + + private systems = [ + { + code: "registry", + name: "ข้อมูลทะเบียนประวัติข้าราชการ", + }, + { + code: "registry_emp", + name: "ข้อมูลทะเบียนประวัติลูกจ้างประจำ", + }, + { + code: "registry_temp", + name: "ข้อมูลทะเบียนประวัติลูกจ้างชั่วคราว", + }, + { + code: "organization", + name: "ข้อมูลโครงสร้างและอัตรากำลัง", + }, + ]; + /** + * list systems + * @summary รายการ systems + */ + @Get("/systems") + async listSystems() { + return new HttpSuccess(this.systems); + } + + /** + * list fields by systems + * @summary รายการ fields ตาม systems + */ + @Get("/:system/fields") + async listAttribute( + @Request() req: RequestWithUser, + @Path("system") system: "registry" | "registry_emp" | "registry_temp" | "organization", + ): Promise { + try { + if (!req.user.role.includes("SUPER_ADMIN")) { + throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้"); + } + const entities = [ + { + name: "Profile", + repository: this.profileRepository, + description: "ข้อมูลหลัก", + isMain: true, + system: ["registry"], + }, + { + name: "ProfileEmployee", + repository: this.profileEmployeeRepository, + description: "ข้อมูลหลัก", + isMain: true, + system: ["registry_emp", "registry_temp"], + }, + { + name: "ProfileGovernment", + repository: this.profileGovernmentRepository, + description: "ข้อมูลราชการ", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileSalary", + repository: this.profileProfileSalaryRepository, + description: "ข้อมูลตำแหน่ง/เงินเดือน", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileAbility", + repository: this.profileAbilityRepository, + description: "ข้อมูลความสามารถ", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileAssessment", + repository: this.profileAssessmentRepository, + description: "ข้อมูลการประเมิน", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileCertificate", + repository: this.profileCertificateRepository, + description: "ข้อมูลใบรับรอง", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileHonor", + repository: this.profileHonorRepository, + description: "ข้อมูลเกียรติบัตร", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileInsignia", + repository: this.profileInsigniaRepository, + description: "ข้อมูลเครื่องหมาย", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileLeave", + repository: this.profileLeaveRepository, + description: "ข้อมูลการลา", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileChangeName", + repository: this.profileChangeNameRepository, + description: "ข้อมูลการเปลี่ยนชื่อ", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileDevelopment", + repository: this.profileDevelopmentRepository, + description: "ข้อมูลการพัฒนา", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileDiscipline", + repository: this.profileDisciplineRepository, + description: "ข้อมูลวินัย", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileDuty", + repository: this.profileDutyRepository, + description: "ข้อมูลหน้าที่ปฏิบัติราชการ", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileEducation", + repository: this.profileEducationRepository, + description: "ข้อมูลการศึกษา", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileFamilyCouple", + repository: this.profileFamilyCoupleRepository, + description: "ข้อมูลคู่สมรส", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileFamilyFather", + repository: this.profileFamilyFatherRepository, + description: "ข้อมูลบิดา", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileFamilyMother", + repository: this.profileFamilyMotherRepository, + description: "ข้อมูลมารดา", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileChildren", + repository: this.profileChildrenRepository, + description: "ข้อมูลบุตร", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileNopaid", + repository: this.profileNopaidRepository, + description: "ข้อมูลการไม่จ่ายเงินเดือน", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "ProfileOther", + repository: this.profileOtherRepository, + description: "ข้อมูลอื่นๆ", + system: ["registry", "registry_emp", "registry_temp"], + }, + { + name: "OrgRoot", + repository: this.orgRootRepository, + description: "ข้อมูลหน่วยงาน", + isMain: true, + system: ["organization"], + }, + { + name: "OrgChild1", + repository: this.orgChild1Repository, + description: "ข้อมูลส่วนราชการ ระดับที่ 1", + system: ["organization"], + }, + { + name: "OrgChild2", + repository: this.orgChild2Repository, + description: "ข้อมูลส่วนราชการ ระดับที่ 2", + system: ["organization"], + }, + { + name: "OrgChild3", + repository: this.orgChild3Repository, + description: "ข้อมูลส่วนราชการ ระดับที่ 3", + system: ["organization"], + }, + { + name: "OrgChild4", + repository: this.orgChild4Repository, + description: "ข้อมูลส่วนราชการ ระดับที่ 4", + system: ["organization"], + }, + { + name: "PosMaster", + repository: this.posMasterRepository, + description: "ข้อมูลตำแหน่ง", + system: ["organization"], + }, + ]; + + const result = entities + .filter((s) => s.system.includes(system)) + .map(({ name, repository, description, isMain }) => ({ + tb: name, + description, + isMain: isMain || false, + propertys: repository.metadata.columns + .filter( + (column) => + !column.isPrimary && + column.propertyName !== "createdUserId" && + column.propertyName !== "lastUpdateUserId", + ) + .map((column) => ({ + propertyName: column.propertyName, + type: typeof column.type === "string" ? column.type : "string", + comment: column.comment, + key: column.propertyName, + })), + })); + + return new HttpSuccess(result); + } catch (error) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + (error instanceof Error ? error.message : String(error)) || + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", + ); + } + } + + /** + * list api + * @summary รายการ api + */ + @Get("/lists") + async listApi( + @Request() req: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() keyword: string = "", + @Query() system: "registry" | "registry_emp" | "registry_temp" | "organization" | "" = "", + ): Promise { + try { + if (!req.user.role.includes("SUPER_ADMIN")) { + throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้"); + } + const offset = (page - 1) * pageSize; + + const queryBuilder = AppDataSource.getRepository(ApiName) + .createQueryBuilder("apiName") + .select([ + "apiName.id", + "apiName.name", + "apiName.code", + "apiName.pathApi", + "apiName.methodApi", + "apiName.system", + "apiName.isActive", + "apiName.createdAt", + "apiName.lastUpdatedAt", + ]); + + if (keyword?.trim()) { + queryBuilder.where( + "(apiName.name LIKE :keyword OR apiName.code LIKE :keyword OR apiName.pathApi LIKE :keyword)", + { keyword: `%${keyword.trim()}%` }, + ); + } + + if (system) { + queryBuilder.andWhere("apiName.system = :system", { system }); + } + + const [apiNames, total] = await queryBuilder + .skip(offset) + .take(pageSize) + .orderBy("apiName.lastUpdatedAt", "DESC") + .addOrderBy("apiName.createdAt", "ASC") + .getManyAndCount(); + + return new HttpSuccess({ + data: apiNames, + total, + }); + } catch (error) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + (error instanceof Error ? error.message : String(error)) || + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", + ); + } + } + + /** + * สร้าง api + * @summary สร้าง api + */ + @Post("") + async createApi( + @Request() req: RequestWithUser, + @Body() apiData: CreateApi, + ): Promise { + try { + const queryRunner = AppDataSource.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + + try { + if (!req.user.role.includes("SUPER_ADMIN")) { + throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้"); + } + + const code = Math.random().toString(36).substring(2, 10).toUpperCase(); + const postData = { + name: apiData.name, + code, + pathApi: `/api/v2/org/api-service/${apiData.system}/${code}`, + methodApi: apiData.methodApi || "GET", + system: apiData.system || "registry", + isActive: apiData.isActive || false, + createdUserId: req.user?.sub || undefined, + createdFullName: req.user?.name || "", + }; + const apiName = await queryRunner.manager.getRepository(ApiName).save(postData); + + if (apiData.apiAttributes?.length) { + let orderingCounter = 0; + const attributesToSave = apiData.apiAttributes.flatMap((attr) => + attr.propertyKey.map((propertyKey) => ({ + apiNameId: apiName.id, + tbName: attr.tbName, + propertyKey, + ordering: orderingCounter++, + createdUserId: req.user?.sub || undefined, + createdFullName: req.user?.name || "", + })), + ); + + await queryRunner.manager.getRepository(ApiAttribute).save(attributesToSave); + } + + await queryRunner.commitTransaction(); + return new HttpSuccess(apiName.id); + } catch (transactionError) { + await queryRunner.rollbackTransaction(); + throw transactionError; + } finally { + await queryRunner.release(); + } + } catch (error) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + (error instanceof Error ? error.message : String(error)) || + "เกิดข้อผิดพลาด ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง", + ); + } + } + + /** + * รายละเอียด api ตามไอดี + * @summary รายละเอียด api ตามไอดี + */ + @Get("/{id}") + async getApiById( + @Request() req: RequestWithUser, + @Path("id") id: string, + ): Promise { + try { + if (!req.user.role.includes("SUPER_ADMIN")) { + throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้"); + } + + const apiName = await AppDataSource.getRepository(ApiName).findOne({ + select: { + id: true, + name: true, + code: true, + pathApi: true, + methodApi: true, + system: true, + isActive: true, + apiAttributes: true, + }, + where: { id }, + relations: ["apiAttributes"], + order: { + apiAttributes: { + ordering: "ASC", + }, + }, + }); + if (!apiName) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบ API ที่ต้องการแก้ไข"); + } + + const items = { + ...apiName, + apiAttributes: apiName.apiAttributes.map((attr) => ({ + tbName: attr.tbName, + propertyKey: attr.propertyKey, + })), + }; + return new HttpSuccess(items); + } catch (error) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + (error instanceof Error ? error.message : String(error)) || + "เกิดข้อผิดพลาด ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง", + ); + } + } + + /** + * แก้ไข api + * @summary แก้ไขข้อมูล api + */ + @Put("/{id}") + async editApi( + @Request() req: RequestWithUser, + @Path("id") id: string, + @Body() apiData: CreateApi, + ): Promise { + try { + const queryRunner = AppDataSource.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + + try { + if (!req.user.role.includes("SUPER_ADMIN")) { + throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้"); + } + + const apiName = await queryRunner.manager.getRepository(ApiName).findOneBy({ id }); + if (!apiName) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบ API ที่ต้องการแก้ไข"); + } + + const updateData = { + name: apiData.name, + pathApi: `/api/v2/org/api-service/${apiData.system}/${apiName.code}`, + methodApi: apiData.methodApi || "GET", + system: apiData.system || "registry", + isActive: apiData.isActive || false, + lastUpdateUserId: req.user?.sub || undefined, + lastUpdateFullName: req.user?.name || "", + }; + await queryRunner.manager.getRepository(ApiName).update(id, updateData); + + await queryRunner.manager.getRepository(ApiAttribute).delete({ apiNameId: id }); + if (apiData.apiAttributes?.length) { + let orderingCounter = 0; + const attributesToSave = apiData.apiAttributes.flatMap((attr) => + attr.propertyKey.map((propertyKey) => ({ + apiNameId: apiName.id, + tbName: attr.tbName, + propertyKey, + ordering: orderingCounter++, + lastUpdateUserId: req.user?.sub || undefined, + lastUpdateFullName: req.user?.name || "", + })), + ); + + await queryRunner.manager.getRepository(ApiAttribute).save(attributesToSave); + } + + await queryRunner.commitTransaction(); + return new HttpSuccess(); + } catch (transactionError) { + await queryRunner.rollbackTransaction(); + throw transactionError; + } finally { + await queryRunner.release(); + } + } catch (error) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + (error instanceof Error ? error.message : String(error)) || + "เกิดข้อผิดพลาด ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง", + ); + } + } + + /** + * ลบ api + * @summary ลบข้อมูล api + */ + @Delete("/{id}") + async deleteApi( + @Request() req: RequestWithUser, + @Path("id") id: string, + ): Promise { + try { + const queryRunner = AppDataSource.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + + try { + if (!req.user.role.includes("SUPER_ADMIN")) { + throw new HttpError(HttpStatusCode.FORBIDDEN, "คุณไม่มีสิทธิ์ในการเข้าถึงข้อมูลนี้"); + } + + const checkUsed = await AppDataSource.getRepository(ApiKey) + .createQueryBuilder("apiKey") + .innerJoin("apiKey.apiNames", "apiName") + .where("apiName.id = :id", { id }) + .getCount(); + + if (checkUsed > 0) { + throw new HttpError( + HttpStatusCode.BAD_REQUEST, + "ไม่สามารถลบ API นี้ได้ เนื่องจากมีการใช้งานอยู่", + ); + } + + await queryRunner.manager.getRepository(ApiAttribute).delete({ apiNameId: id }); + await queryRunner.manager.getRepository(ApiName).delete({ id }); + + await queryRunner.commitTransaction(); + return new HttpSuccess(); + } catch (transactionError) { + await queryRunner.rollbackTransaction(); + throw transactionError; + } finally { + await queryRunner.release(); + } + } catch (error) { + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + (error instanceof Error ? error.message : String(error)) || + "เกิดข้อผิดพลาด ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่ในภายหลัง", + ); + } + } + + /** + * list systems + * @summary รายการ systems + */ + @Get("/manual/swagger") + async getManualRequestWebService() { + const json: any = {}; + // create swagger documentation for manual request only ApiWebServiceController + json["openapi"] = "3.0.0"; + json["info"] = { + title: "Request Web Service", + version: "1.0.0", + description: "This is a manual request web service.", + }; + json["servers"] = [ + { + url: process.env.API_URL?.replace("/api/v1", "") || "http://localhost:13009", + }, + { + url: "http://localhost:13009", + description: "Local server", + }, + ]; + json["paths"] = { + "/api/v2/org/api-service/{system}/{code}": { + get: { + summary: "Get Registry Data", + parameters: [ + { + name: "system", + in: "path", + required: true, + schema: { + type: "string", + enum: ["registry", "registry_emp", "registry_temp", "organization"], + }, + }, + { + name: "code", + in: "path", + required: true, + schema: { + type: "string", + }, + }, + { + name: "page", + in: "query", + required: false, + schema: { + type: "integer", + default: 1, + }, + }, + { + name: "pageSize", + in: "query", + required: false, + schema: { + type: "integer", + default: 100, + }, + }, + ], + responses: { + 200: { + description: "Successful response", + }, + 400: { + description: "Bad request", + }, + 500: { + description: "Internal server error", + }, + }, + }, + }, + }; + + json["components"] = { + securitySchemes: { + ApiKeyAuth: { + type: "apiKey", + in: "header", + name: "X-API-Key", + }, + }, + }; + json["security"] = [ + { + ApiKeyAuth: [], + }, + ]; + return new HttpSuccess(json); + } +} diff --git a/src/controllers/ApiWebServiceController.ts b/src/controllers/ApiWebServiceController.ts new file mode 100644 index 00000000..be60fb37 --- /dev/null +++ b/src/controllers/ApiWebServiceController.ts @@ -0,0 +1,82 @@ +import { + Controller, + Post, + Route, + Security, + Tags, + Body, + Path, + Request, + Response, + Get, + Query, +} from "tsoa"; +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 { ApiName } from "../entities/ApiName"; +import { Profile } from "../entities/Profile"; +import { isPermissionRequest } from "../middlewares/authWebService"; +import { RequestWithUserWebService } from "../middlewares/user"; +@Route("api/v2/org/api-service") +@Tags("ApiKey") +@Security("webServiceAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +export class ApiWebServiceController extends Controller { + private apiNameRepository = AppDataSource.getRepository(ApiName); + + /** + * list fields by systems + * @summary รายการ fields ตาม systems + */ + @Get("/:system/:code") + async listAttribute( + @Request() request: RequestWithUserWebService, + @Path("system") system: "registry" | "registry_emp" | "registry_temp" | "organization", + @Path("code") code: string, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 100, + ): Promise { + // try { + const apiName = await this.apiNameRepository.findOne({ + where: { code }, + select: ["id", "code", "methodApi", "system", "isActive"], + relations: ["apiAttributes"], + order: { + apiAttributes: { + ordering: "ASC", + }, + }, + }); + + if (!apiName || apiName.system != system || !apiName.isActive || apiName.methodApi != "GET") { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบ API ที่ระบุ"); + } + await isPermissionRequest(request, apiName.id); + const offset = (page - 1) * pageSize; + + const propertyKey = apiName.apiAttributes.map((attr) => `${attr.tbName}.${attr.propertyKey}`); + const queryBuilder = AppDataSource.getRepository(Profile) + .createQueryBuilder("Profile") + .select(propertyKey); + + const [items, total] = await queryBuilder + .skip(offset) + .take(pageSize) + .orderBy("Profile.createdAt", "DESC") + .getManyAndCount(); + + return new HttpSuccess({ items, total }); + // } catch (error) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // (error instanceof Error ? error.message : String(error)) || + // "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", + // ); + // } + } +} diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 2f3facc8..a8fba726 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1696,7 +1696,7 @@ export class ProfileController extends Controller { } else { portfolios = portfolios.map((x:any) => ({ - name: x.name ? x.name : "-", + name: x.name ? Extension.ToThaiNumber(x.name) : "-", year: x.year ? Extension.ToThaiNumber(x.year.toString()) : "-" })) } diff --git a/src/database/data-source.ts b/src/database/data-source.ts index 9de306d7..655d6386 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -47,7 +47,9 @@ export const AppDataSource = new DataSource({ logging: true, // timezone: "Z", entities: - process.env.NODE_ENV !== "production" ? ["src/entities/*.ts"] : ["dist/entities/*{.ts,.js}"], + process.env.NODE_ENV !== "production" + ? ["src/entities/**/*.ts"] + : ["dist/entities/**/*{.ts,.js}"], migrations: process.env.NODE_ENV !== "production" ? ["src/migration/**/*.ts"] diff --git a/src/entities/ApiAttribute.ts b/src/entities/ApiAttribute.ts new file mode 100644 index 00000000..3c6a21d5 --- /dev/null +++ b/src/entities/ApiAttribute.ts @@ -0,0 +1,39 @@ +import { ApiName } from "./ApiName"; +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; + +@Entity("apiAttribute") +export class ApiAttribute extends EntityBase { + @Column({ + nullable: false, + comment: "ชื่อตาราง", + length: 50, + }) + tbName: string; + + @Column({ + nullable: false, + comment: "คีย์ของแอตทริบิวต์", + length: 255, + }) + propertyKey: string; + + @Column({ + nullable: false, + comment: "ลำดับการแสดงผล", + default: 0, + type: "int", + }) + ordering: number; + + @Column({ + nullable: false, + comment: "ไอดีของ API Name", + length: 36, // UUID length + }) + apiNameId: string; + + @ManyToOne(() => ApiName, (apiName) => apiName.apiAttributes) + @JoinColumn({ name: "apiNameId" }) + apiName: ApiName; +} diff --git a/src/entities/ApiName.ts b/src/entities/ApiName.ts index 510e51df..db9d5bf5 100644 --- a/src/entities/ApiName.ts +++ b/src/entities/ApiName.ts @@ -1,3 +1,4 @@ +import { ApiAttribute } from "./ApiAttribute"; import { Entity, Column, ManyToMany, JoinTable, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { ApiKey } from "./ApiKey"; @@ -29,10 +30,61 @@ export class ApiName extends EntityBase { }) methodApi: string; + @Column({ + nullable: false, + comment: "code สำหรับการเรียก API", + length: 8, + }) + code: string; + + @Column({ + nullable: false, + comment: "code ระบบสำหรับการเรียก API", + length: 50, + default: "registry", + }) + system: string; + + @Column({ + nullable: false, + comment: "สถานะการใช้งาน", + type: "boolean", + default: false, + }) + isActive: boolean; + @ManyToMany(() => ApiKey, (apiKey) => apiKey.apiNames) @JoinTable() apiKeys: ApiKey[]; @OneToMany(() => ApiHistory, (v) => v.apiName) apiHistorys: ApiHistory[]; + + @OneToMany(() => ApiAttribute, (v) => v.apiName) + apiAttributes: ApiAttribute[]; +} + +export class CreateApi { + @Column() + name: string; + + @Column() + methodApi: "GET" | "POST" | "PUT"; + + @Column() + system: string; + + @Column() + isActive: boolean; + + @Column() + apiAttributes: CreateApiAttribute[]; +} + +export class CreateApiAttribute { + @Column() + tbName: string; + + @Column() + propertyKey: string[]; } diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index bf62b28a..396ada4d 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -3,6 +3,7 @@ import { createDecoder, createVerifier } from "fast-jwt"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; +import { handleWebServiceAuth } from "./authWebService"; if (!process.env.AUTH_PUBLIC_KEY && !process.env.AUTH_REALM_URL) { throw new Error("Require keycloak AUTH_PUBLIC_KEY or AUTH_REALM_URL."); @@ -30,6 +31,11 @@ export async function expressAuthentication( return { preferred_username: "bypassed" }; } + // เพิ่มการจัดการสำหรับ Web Service Authentication + if (securityName === "webServiceAuth") { + return await handleWebServiceAuth(request); + } + if (securityName !== "bearerAuth") throw new Error("ไม่ทราบวิธีการยืนยันตัวตน"); const token = request.headers["authorization"]?.includes("Bearer ") diff --git a/src/middlewares/authWebService.ts b/src/middlewares/authWebService.ts new file mode 100644 index 00000000..fa50b3fe --- /dev/null +++ b/src/middlewares/authWebService.ts @@ -0,0 +1,56 @@ +import { RequestWithUserWebService } from "./user"; +import { AppDataSource } from "../database/data-source"; +import { ApiKey } from "../entities/ApiKey"; +import * as express from "express"; + +import HttpError from "../interfaces/http-error"; +import HttpStatus from "../interfaces/http-status"; + +// เพิ่มฟังก์ชันสำหรับจัดการ Web Service Authentication +export async function handleWebServiceAuth(request: express.Request) { + // ตัวอย่างการใช้ API Key + const apiKey = request.headers["x-api-key"] as string; + + if (!apiKey) { + throw new HttpError(HttpStatus.UNAUTHORIZED, "ไม่พบข้อมูลสำหรับยืนยันตัวตน"); + } + + // ตรวจสอบ API Key กับฐานข้อมูล + const apiKeyData = await AppDataSource.getRepository(ApiKey).findOne({ + select: { id: true, name: true, keyApi: true }, + where: { keyApi: apiKey }, + relations: ["apiNames"], + }); + if (!apiKeyData) { + throw new HttpError(HttpStatus.UNAUTHORIZED, "ไม่สามารถยืนยันตัวตนได้"); + } + + // บันทึก log data สำหรับ web service + if (!request.app.locals.logData) { + request.app.locals.logData = {}; + } + + request.app.locals.logData.id = apiKeyData.id; + request.app.locals.logData.name = apiKeyData.name; + request.app.locals.logData.accessApi = apiKeyData.apiNames.map((x) => x.id) ?? []; + + // ส่งคืนข้อมูลผู้ใช้ที่ยืนยันตัวตน + return { + id: apiKeyData.id, + name: apiKeyData.name, + type: "web-service", + accessApi: apiKeyData.apiNames.map((x) => x.id) ?? [], + }; +} + +export function isPermissionRequest( + request: RequestWithUserWebService, + apiId: string, +): Promise { + // ฟังก์ชันนี้ใช้เพื่อตรวจสอบสิทธิ์ของผู้ใช้ที่ร้องขอ API โดยตรวจสอบว่า user มีสิทธิ์เข้าถึง API ที่ร้องขอหรือไม่ + const hasPermission = request.user.accessApi.includes(apiId); + if (!hasPermission) { + throw new HttpError(HttpStatus.FORBIDDEN, "คุณไม่มีสิทธิ์เข้าถึง API นี้"); + } + return Promise.resolve(hasPermission); +} diff --git a/src/middlewares/user.ts b/src/middlewares/user.ts index a35cdc4a..e5c48d9a 100644 --- a/src/middlewares/user.ts +++ b/src/middlewares/user.ts @@ -11,3 +11,11 @@ export type RequestWithUser = Request & { role: string[]; }; }; + +export type RequestWithUserWebService = Request & { + user: { + id: string; + name: string; + accessApi: string[]; + }; +}; diff --git a/src/migration/1754549669635-update_api_name.ts b/src/migration/1754549669635-update_api_name.ts new file mode 100644 index 00000000..3fda0d81 --- /dev/null +++ b/src/migration/1754549669635-update_api_name.ts @@ -0,0 +1,1316 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateApiName1754549669635 implements MigrationInterface { + name = 'UpdateApiName1754549669635' + + public async up(queryRunner: QueryRunner): Promise { +// await queryRunner.query(`CREATE TABLE \`HR_CHANGENAME_EMPTEMP\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`NEW_RANK_NAME\` text NULL, \`NEW_FNAME\` text NULL, \`NEW_LNAME\` text NULL, \`LAST_RANK_NAME\` text NULL, \`LAST_FNAME\` text NULL, \`LAST_LNAME\` text NULL, \`EFFECT_DATE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); +// await queryRunner.query(`CREATE TABLE \`EMPLOYEE\` (\`id\` int NOT NULL AUTO_INCREMENT, \`ID\` text NULL, \`CIT\` text NULL, \`BORN\` text NULL, \`RANK_NAME\` text NULL, \`FNAME\` text NULL, \`LNAME\` text NULL, \`BEGIN_ENTRY_DATE\` text NULL, \`SEX\` text NULL, \`WORK_LINE_NAME\` text NULL, \`SALARY\` text NULL, \`DEPARTMENT_NAME\` text NULL, \`DEPARTMENT_CODE\` text NULL, \`DIVISION_NAME\` text NULL, \`DIVISION_CODE\` text NULL, \`SECTION_NAME\` text NULL, \`SECTION_CODE\` text NULL, \`JOB_NAME\` text NULL, \`JOB_CODE\` text NULL, \`POS_NUM_CODE\` text NULL, \`POS_NUM_NAME\` text NULL, \`CATEGORY_SAL_CODE\` text NULL, \`SALARY_LEVEL_CODE\` text NULL, \`LEVEL_NAME\` text NULL, \`WORK_LEVEL\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); +// await queryRunner.query(`CREATE TABLE \`EMPLOYEETEMP\` (\`id\` int NOT NULL AUTO_INCREMENT, \`ID\` text NULL, \`CIT\` text NULL, \`BORN\` text NULL, \`RANK_NAME\` text NULL, \`FNAME\` text NULL, \`LNAME\` text NULL, \`BEGIN_ENTRY_DATE\` text NULL, \`SEX\` text NULL, \`WORK_LINE_NAME\` text NULL, \`SALARY\` text NULL, \`DEPARTMENT_NAME\` text NULL, \`DEPARTMENT_CODE\` text NULL, \`DIVISION_NAME\` text NULL, \`DIVISION_CODE\` text NULL, \`SECTION_NAME\` text NULL, \`SECTION_CODE\` text NULL, \`JOB_NAME\` text NULL, \`JOB_CODE\` text NULL, \`POS_NUM_CODE\` text NULL, \`POS_NUM_NAME\` text NULL, \`CATEGORY_SAL_CODE\` text NULL, \`SALARY_LEVEL_CODE\` text NULL, \`LEVEL_NAME\` text NULL, \`WORK_LEVEL\` text NULL, \`POSITION_LEVEL\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`amount\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionSalaryAmount\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`mouthSalaryAmount\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`profileId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionExecutive\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionType\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionLevel\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`order\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`profileEmployeeId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`dateGovernment\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`isGovernment\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`amountSpecial\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgRoot\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild1\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild2\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild3\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild4\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandYear\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandDateSign\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandDateAffect\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandCode\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNoAbb\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionCee\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`remark\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandNo\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`IsActive\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryClass\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OcId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveSideId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLineId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionPathSideId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OrganizationShortNameId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeeGroupId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeeLevelId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeePositionId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeePositionSideId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoEmployee\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`RefCommandDate\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`RefCommandNo\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`CommandTypeName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryStatus\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`AgencyName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`CLevel\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OrgName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLineName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionPathSideName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionRef\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIALIST_NAME\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`USER_CREATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`USER_UPDATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FORCE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`JOB_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SECTION_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DIVISION_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`WORK_LINE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ADMIN_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_CODE_1\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME_1\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIALIST_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FILL_APP_FLAG\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_POS_STATUS\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`UP_C_FLAG\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG_CURRENT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`AUDIT_FLAG\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`AUDIT_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CREATE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`UPDATE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG_1\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COURSE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COURSE_NAME\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`PLACE_NAME\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`PROVINCE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COUNTRY_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POSITION_CATG\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`REC_STATUS\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MVMENT_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MVMENT_OF\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_EDIT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB_EDIT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE_EDIT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM_EDIT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR_EDIT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE_E\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_E\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE_EDIT\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_CEE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_LEVEL\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`GROUPWORK_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`GROUPWORK_NAME\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ACTIVE_STATUS\``); +// await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`ORDER\``); +// await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`HRMS_DEP_CODE\``); +// await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`HRMS_DIV_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RANK_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TYPE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETURN_OCCUPY_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FORCE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UPCLASS_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FUND_COURSE_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`EDUCATION_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MAJOR_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MAJOR_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UNIVER_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POSITION_CATG\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_2\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIALIST_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIALIST_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME_1\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_1\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_ADD\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_PERCENT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_AMT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`PAYMENT_AMT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`PAYMENT_PERCENT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_1\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`COST_LIVING_AMOUNT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_CUR_ST\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_POS_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_MP_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_CODE_1\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CUR_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CONTENT_NO\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_NUM_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CUR_YEAR_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_YEAR_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_DATE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_POS_DATE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_1_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_AMT_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_ADD_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_CODE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`GROUPWORK_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_CODE_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_NAME_O\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_RETIRE_STATUS\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MARRIAGE_STATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SUN_NO\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETIRE_TYPE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETIRE_POS_NO\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`DEXPIRE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`HELP_LIVING_AMOUNT\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_DEPARTMENT_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_DIVISION_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_SECTION_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_JOB_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CREATE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UPDATE_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MINOR_CODE\``); + await queryRunner.query(`ALTER TABLE \`apiName\` ADD \`code\` varchar(8) NOT NULL COMMENT 'code สำหรับการเรียก API'`); + await queryRunner.query(`ALTER TABLE \`apiName\` ADD \`system\` varchar(50) NOT NULL COMMENT 'code ระบบสำหรับการเรียก API' DEFAULT 'registry'`); + await queryRunner.query(`ALTER TABLE \`apiName\` ADD \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 0`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`Order\` int NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`Amount\` double NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionSalaryAmount\` double NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionName\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`ProfileId\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ID\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`FUND_COURSE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`MAJOR_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`FLAG_EDUCATION\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`entity_base\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`entity_base\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`entity_base\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`profileTraining\` CHANGE \`isEntry\` \`isEntry\` tinyint NOT NULL COMMENT 'ข้อมูลจาก Entry' DEFAULT 0`); +// await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`isEntry\` \`isEntry\` tinyint NOT NULL COMMENT 'ข้อมูลจาก Entry' DEFAULT 0`); +// await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`subDistrictImport\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD PRIMARY KEY (\`id\`)`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNo\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNo\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryRef\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryRef\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoName\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeName\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelName\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`mp_command_num\``); +// await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`mp_command_num\` int NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM\` int NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR\` int NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_POS_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_POS_DATE\` varchar(255) NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY\` int NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FUND_COURSE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FUND_COURSE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MAJOR_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MAJOR_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FLAG_EDUCATION\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FLAG_EDUCATION\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`educationMis\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD CONSTRAINT \`FK_f1ded3e1f83ab2437f739a14f38\` FOREIGN KEY (\`profileSalaryId\`) REFERENCES \`profileSalary\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`apiAttribute\` ADD CONSTRAINT \`FK_13856cc8b4244f6a6fc26c4e0ff\` FOREIGN KEY (\`apiNameId\`) REFERENCES \`apiName\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); +// await queryRunner.query(`CREATE VIEW \`view_registry_employee\` AS +// WITH Position AS ( +// SELECT +// pn.posMasterId, +// ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number +// FROM employeePosition pn +// WHERE pn.positionIsSelected IS TRUE +// ), +// PosMaster AS ( +// SELECT +// pm.current_holderId, +// pm.posMasterNo, +// pm.orgRootId, +// pm.orgChild1Id, +// pm.orgChild2Id, +// pm.orgChild3Id, +// pm.orgChild4Id, +// orgRoot.orgRootName, +// orgChild1.orgChild1Name, +// orgChild2.orgChild2Name, +// orgChild3.orgChild3Name, +// orgChild4.orgChild4Name, +// CASE +// WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, " ", pm.posMasterNo) +// WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, " ", pm.posMasterNo) +// WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, " ", pm.posMasterNo) +// WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, " ", pm.posMasterNo) +// ELSE CONCAT(orgChild4.orgChild4ShortName, " ", pm.posMasterNo) +// END AS searchShortName, +// ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number +// FROM employeePosMaster pm +// LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId +// LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId +// LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id +// LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id +// LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id +// LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id +// LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 +// WHERE orgRevision.orgRevisionIsCurrent IS TRUE +// AND orgRevision.orgRevisionIsDraft IS FALSE +// ), +// Educations AS ( +// SELECT +// eds.profileEmployeeId, +// JSON_ARRAYAGG( +// JSON_OBJECT( +// 'degree', eds.degree, +// 'field', eds.field, +// 'educationLevel', eds.educationLevel, +// 'isEducation', eds.isEducation, +// 'isHigh', eds.isHigh +// ) +// ) AS Educations +// FROM ( +// SELECT DISTINCT +// eds.degree, +// eds.field, +// eds.educationLevel, +// eds.isEducation, +// eds.isHigh, +// eds.profileEmployeeId, +// eds.level +// FROM profileEducation eds +// ) AS eds +// GROUP BY eds.profileEmployeeId +// ORDER BY eds.level DESC +// ), +// EducationLevels AS ( +// SELECT +// edls.profileEmployeeId, +// GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels +// FROM profileEducation edls +// WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != '' +// GROUP BY edls.profileEmployeeId +// ORDER BY edls.level DESC +// ), +// Degrees AS ( +// SELECT +// degs.profileEmployeeId, +// GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees +// FROM profileEducation degs +// WHERE degs.degree IS NOT NULL AND degs.degree != '' +// GROUP BY degs.profileEmployeeId +// ), +// Fields AS ( +// SELECT +// fies.profileEmployeeId, +// GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields +// FROM profileEducation fies +// WHERE fies.field IS NOT NULL AND fies.field != '' +// GROUP BY fies.profileEmployeeId +// ), +// PositionDate AS ( +// SELECT +// vcto.Years, +// vcto.Months, +// vcto.Days, +// vcto.profileEmployeeId +// FROM tenurePositionEmployee vcto +// ), +// PositionLevelDate AS ( +// SELECT +// vctlo.Years, +// vctlo.Months, +// vctlo.Days, +// vctlo.profileEmployeeId +// FROM tenureLevelEmployee vctlo +// ) +// SELECT +// p.id as profileEmployeeId, +// p.citizenId, +// p.rank, +// p.prefix, +// p.firstName, +// p.lastName, +// p.isProbation, +// p.isLeave, +// p.isRetirement, +// p.leaveType, +// p.employeeClass, +// pm.posMasterNo, +// pm.orgRootId, +// pm.orgChild1Id, +// pm.orgChild2Id, +// pm.orgChild3Id, +// pm.orgChild4Id, +// pm.orgRootName, +// pm.orgChild1Name, +// pm.orgChild2Name, +// pm.orgChild3Name, +// pm.orgChild4Name, +// CASE +// WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName +// WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) +// WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) +// WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) +// ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) +// END AS org, +// pm.searchShortName, +// p.position, +// posType.posTypeName, +// CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS "posLevelName", +// p.gender, +// p.relationship, +// p.dateAppoint, +// p.dateRetire, +// p.dateRetireLaw, +// p.birthdate, +// eds.Educations, +// edls.educationLevels, +// degs.degrees, +// fies.fields, +// TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age, +// vcto.Years, +// vcto.Months, +// vcto.Days, +// vctlo.Years AS levelYears, +// vctlo.Months AS levelMonths, +// vctlo.Days AS levelDays +// FROM profileEmployee p +// LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id +// LEFT JOIN employeePosType posType ON p.posTypeId = posType.id +// LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 +// LEFT JOIN Educations eds ON p.id = eds.profileEmployeeId +// LEFT JOIN EducationLevels edls ON p.id = edls.profileEmployeeId +// LEFT JOIN Degrees degs ON p.id = degs.profileEmployeeId +// LEFT JOIN Fields fies ON p.id = fies.profileEmployeeId +// LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId +// LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId +// `); +// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_registry_employee","WITH Position AS (\n SELECT \n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM employeePosition pn\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, \" \", pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, \" \", pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, \" \", pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, \" \", pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, \" \", pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM employeePosMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Educations AS (\n SELECT \n eds.profileEmployeeId,\n JSON_ARRAYAGG(\n JSON_OBJECT(\n 'degree', eds.degree,\n 'field', eds.field,\n 'educationLevel', eds.educationLevel,\n 'isEducation', eds.isEducation,\n 'isHigh', eds.isHigh\n )\n ) AS Educations\n FROM (\n SELECT DISTINCT \n eds.degree, \n eds.field, \n eds.educationLevel, \n eds.isEducation, \n eds.isHigh, \n eds.profileEmployeeId,\n\t\t\teds.level\n FROM profileEducation eds\n ) AS eds\n GROUP BY eds.profileEmployeeId\n ORDER BY eds.level DESC\n ),\n EducationLevels AS (\n SELECT \n\t\t edls.profileEmployeeId,\n GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels\n FROM profileEducation edls\n WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != ''\n GROUP BY edls.profileEmployeeId\n ORDER BY edls.level DESC\n ),\n Degrees AS (\n SELECT \n\t\t degs.profileEmployeeId,\n GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees\n FROM profileEducation degs\n WHERE degs.degree IS NOT NULL AND degs.degree != ''\n GROUP BY degs.profileEmployeeId\n ),\n Fields AS (\n SELECT \n\t\t fies.profileEmployeeId,\n GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields\n FROM profileEducation fies\n WHERE fies.field IS NOT NULL AND fies.field != ''\n GROUP BY fies.profileEmployeeId\n ),\n PositionDate AS (\n SELECT \n vcto.Years,\n vcto.Months,\n vcto.Days,\n vcto.profileEmployeeId\n FROM tenurePositionEmployee vcto\n ),\n PositionLevelDate AS (\n SELECT \n vctlo.Years,\n vctlo.Months,\n vctlo.Days,\n vctlo.profileEmployeeId\n FROM tenureLevelEmployee vctlo\n )\n SELECT \n p.id as profileEmployeeId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n p.employeeClass,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n p.position,\n posType.posTypeName,\n CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS \"posLevelName\",\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n eds.Educations,\n edls.educationLevels,\n degs.degrees,\n fies.fields,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,\n vcto.Years,\n vcto.Months,\n vcto.Days,\n vctlo.Years AS levelYears,\n vctlo.Months AS levelMonths,\n vctlo.Days AS levelDays\n FROM profileEmployee p\n LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN employeePosType posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Educations eds ON p.id = eds.profileEmployeeId\n LEFT JOIN EducationLevels edls ON p.id = edls.profileEmployeeId\n LEFT JOIN Degrees degs ON p.id = degs.profileEmployeeId\n LEFT JOIN Fields fies ON p.id = fies.profileEmployeeId\n LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId\n LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId"]); +// await queryRunner.query(`CREATE VIEW \`view_employee_pos_master\` AS SELECT +// employeePosMaster.id, +// employeePosMaster.posMasterNoPrefix, +// employeePosMaster.posMasterNo, +// employeePosMaster.posMasterNoSuffix, +// employeePosMaster.orgRevisionId, +// employeePosMaster.orgRootId, +// employeePosMaster.orgChild1Id, +// employeePosMaster.orgChild2Id, +// employeePosMaster.orgChild3Id, +// employeePosMaster.orgChild4Id, +// employeePosMaster.current_holderId, +// profileEmployee.id as profileId, +// profileEmployee.prefix, +// profileEmployee.firstName, +// profileEmployee.lastName, +// profileEmployee.citizenId, +// profileEmployee.position, +// profileEmployee.amount, +// profileEmployee.dateRetire, +// profileEmployee.birthDate, +// profileEmployee.salaryLevel, +// profileEmployee.group, +// orgRoot.id as rootId, +// orgRoot.orgRootShortName, +// orgRoot.orgRootOrder, +// orgRoot.orgRootName, +// orgChild1.id as child1Id, +// orgChild1.orgChild1ShortName, +// orgChild1.orgChild1Order, +// orgChild1.orgChild1Name, +// orgChild2.id as child2Id, +// orgChild2.orgChild2ShortName, +// orgChild2.orgChild2Order, +// orgChild2.orgChild2Name, +// orgChild3.id as child3Id, +// orgChild3.orgChild3ShortName, +// orgChild3.orgChild3Order, +// orgChild3.orgChild3Name, +// orgChild4.id as child4Id, +// orgChild4.orgChild4ShortName, +// orgChild4.orgChild4Order, +// orgChild4.orgChild4Name, +// position.id as positionId, +// position.positionIsSelected, +// position.posExecutiveId as positionPosExecutiveId, +// position.isSpecial, +// posExecutive.id as posExecutiveId, +// posExecutive.posExecutiveName, +// profileDiscipline.id as profileDisciplineId, +// profileDiscipline.date as disCriplineDate, +// profileLeave.id as profileLeaveId, +// profileAssessment.id as profileAssessmentId, +// profileAssessment.pointSum, +// employeePosLevel.id as posLevelId, +// employeePosLevel.posLevelName, +// employeePosType.id as posTypeId, +// employeePosType.posTypeName, +// employeePosType.posTypeShortName +// FROM +// employeePosMaster +// LEFT JOIN +// profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id +// LEFT JOIN +// orgRoot ON employeePosMaster.orgRootId = orgRoot.id +// LEFT JOIN +// orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id +// LEFT JOIN +// orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id +// LEFT JOIN +// orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id +// LEFT JOIN +// orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id +// LEFT JOIN +// position ON employeePosMaster.id = position.posMasterId +// LEFT JOIN +// posExecutive ON position.posExecutiveId = posExecutive.id +// LEFT JOIN ( +// SELECT * +// FROM profileDisciplineEmployee pd1 +// WHERE pd1.date = ( +// SELECT MAX(pd2.date) +// FROM profileDisciplineEmployee pd2 +// WHERE pd2.profileId = pd1.profileId +// ) +// ) AS profileDiscipline ON profileDiscipline.profileId = profileEmployee.id +// LEFT JOIN ( +// SELECT pl1.* +// FROM profileLeave pl1 +// INNER JOIN ( +// SELECT profileId, MAX(createdAt) AS maxDate +// FROM profileLeave +// GROUP BY profileId +// ) pl2 ON pl1.profileId = pl2.profileId +// AND pl1.createdAt = pl2.maxDate +// ) AS profileLeave ON profileLeave.profileId = employeePosMaster.current_holderId +// LEFT JOIN ( +// SELECT pa1.* +// FROM profileAssessment pa1 +// INNER JOIN ( +// SELECT profileId, MAX(createdAt) AS maxDate +// FROM profileAssessment +// GROUP BY profileId +// ) pa2 ON pa1.profileId = pa2.profileId +// AND pa1.createdAt = pa2.maxDate +// ) AS profileAssessment +// ON profileAssessment.profileId = profileEmployee.id +// LEFT JOIN +// employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id +// LEFT JOIN +// employeePosType ON profileEmployee.posTypeId = employeePosType.id +// WHERE +// employeePosMaster.current_holderId IS NOT NULL +// ORDER BY +// profileEmployee.citizenId ASC +// `); +// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_employee_pos_master","SELECT \n employeePosMaster.id,\n employeePosMaster.posMasterNoPrefix,\n employeePosMaster.posMasterNo,\n employeePosMaster.posMasterNoSuffix,\n employeePosMaster.orgRevisionId,\n employeePosMaster.orgRootId,\n employeePosMaster.orgChild1Id,\n employeePosMaster.orgChild2Id,\n employeePosMaster.orgChild3Id,\n employeePosMaster.orgChild4Id,\n employeePosMaster.current_holderId,\n profileEmployee.id as profileId,\n profileEmployee.prefix,\n profileEmployee.firstName,\n profileEmployee.lastName,\n profileEmployee.citizenId,\n profileEmployee.position,\n profileEmployee.amount,\n profileEmployee.dateRetire,\n profileEmployee.birthDate,\n profileEmployee.salaryLevel,\n profileEmployee.group,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n employeePosLevel.id as posLevelId,\n employeePosLevel.posLevelName,\n\temployeePosType.id as posTypeId,\n employeePosType.posTypeName,\n employeePosType.posTypeShortName\n FROM \n employeePosMaster\n LEFT JOIN \n profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id \n LEFT JOIN \n orgRoot ON employeePosMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON employeePosMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN (\n SELECT *\n FROM profileDisciplineEmployee pd1\n WHERE pd1.date = (\n SELECT MAX(pd2.date)\n FROM profileDisciplineEmployee pd2\n WHERE pd2.profileId = pd1.profileId\n )\n ) AS profileDiscipline ON profileDiscipline.profileId = profileEmployee.id\n LEFT JOIN (\n SELECT pl1.*\n FROM profileLeave pl1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileLeave\n GROUP BY profileId\n ) pl2 ON pl1.profileId = pl2.profileId\n AND pl1.createdAt = pl2.maxDate\n ) AS profileLeave ON profileLeave.profileId = employeePosMaster.current_holderId\n LEFT JOIN (\n SELECT pa1.*\n FROM profileAssessment pa1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileAssessment\n GROUP BY profileId\n ) pa2 ON pa1.profileId = pa2.profileId\n AND pa1.createdAt = pa2.maxDate\n ) AS profileAssessment \n ON profileAssessment.profileId = profileEmployee.id\n LEFT JOIN \n employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id\n LEFT JOIN \n employeePosType ON profileEmployee.posTypeId = employeePosType.id\n WHERE \t\n employeePosMaster.current_holderId IS NOT NULL\n ORDER BY \n profileEmployee.citizenId ASC"]); +// await queryRunner.query(`CREATE VIEW \`view_pos_master\` AS SELECT +// posMaster.id, +// posMaster.posMasterNoPrefix, +// posMaster.posMasterNo, +// posMaster.posMasterNoSuffix, +// posMaster.orgRevisionId, +// posMaster.orgRootId, +// posMaster.orgChild1Id, +// posMaster.orgChild2Id, +// posMaster.orgChild3Id, +// posMaster.orgChild4Id, +// posMaster.current_holderId, +// profile.id as profileId, +// profile.prefix, +// profile.firstName, +// profile.lastName, +// profile.citizenId, +// profile.position, +// profile.amount, +// profile.dateRetire, +// profile.birthDate, +// orgRoot.id as rootId, +// orgRoot.orgRootShortName, +// orgRoot.orgRootOrder, +// orgRoot.orgRootName, +// orgChild1.id as child1Id, +// orgChild1.orgChild1ShortName, +// orgChild1.orgChild1Order, +// orgChild1.orgChild1Name, +// orgChild2.id as child2Id, +// orgChild2.orgChild2ShortName, +// orgChild2.orgChild2Order, +// orgChild2.orgChild2Name, +// orgChild3.id as child3Id, +// orgChild3.orgChild3ShortName, +// orgChild3.orgChild3Order, +// orgChild3.orgChild3Name, +// orgChild4.id as child4Id, +// orgChild4.orgChild4ShortName, +// orgChild4.orgChild4Order, +// orgChild4.orgChild4Name, +// position.id as positionId, +// position.positionIsSelected, +// position.posExecutiveId as positionPosExecutiveId, +// position.isSpecial, +// position.positionExecutiveField, +// position.positionArea, +// posExecutive.id as posExecutiveId, +// posExecutive.posExecutiveName, +// profileDiscipline.id as profileDisciplineId, +// profileDiscipline.date as disCriplineDate, +// profileLeave.id as profileLeaveId, +// profileAssessment.id as profileAssessmentId, +// profileAssessment.pointSum, +// posLevel.id as posLevelId, +// posLevel.posLevelName, +// posType.id as posTypeId, +// posType.posTypeName +// FROM +// posMaster +// LEFT JOIN +// profile ON posMaster.current_holderId = profile.id +// LEFT JOIN +// orgRoot ON posMaster.orgRootId = orgRoot.id +// LEFT JOIN +// orgChild1 ON posMaster.orgChild1Id = orgChild1.id +// LEFT JOIN +// orgChild2 ON posMaster.orgChild2Id = orgChild2.id +// LEFT JOIN +// orgChild3 ON posMaster.orgChild3Id = orgChild3.id +// LEFT JOIN +// orgChild4 ON posMaster.orgChild4Id = orgChild4.id +// LEFT JOIN +// position ON posMaster.id = position.posMasterId +// LEFT JOIN +// posExecutive ON position.posExecutiveId = posExecutive.id +// LEFT JOIN ( +// SELECT * +// FROM profileDiscipline pd1 +// WHERE pd1.date = ( +// SELECT MAX(pd2.date) +// FROM profileDiscipline pd2 +// WHERE pd2.profileId = pd1.profileId +// ) +// ) AS profileDiscipline ON profileDiscipline.profileId = profile.id +// LEFT JOIN ( +// SELECT pl1.* +// FROM profileLeave pl1 +// INNER JOIN ( +// SELECT profileId, MAX(createdAt) AS maxDate +// FROM profileLeave +// GROUP BY profileId +// ) pl2 ON pl1.profileId = pl2.profileId +// AND pl1.createdAt = pl2.maxDate +// ) AS profileLeave +// ON profileLeave.profileId = posMaster.current_holderId +// LEFT JOIN ( +// SELECT pa1.* +// FROM profileAssessment pa1 +// INNER JOIN ( +// SELECT profileId, MAX(createdAt) AS maxDate +// FROM profileAssessment +// GROUP BY profileId +// ) pa2 ON pa1.profileId = pa2.profileId +// AND pa1.createdAt = pa2.maxDate +// ) AS profileAssessment +// ON profileAssessment.profileId = profile.id +// LEFT JOIN +// posLevel ON profile.posLevelId = posLevel.id +// LEFT JOIN +// posType ON profile.posTypeId = posType.id +// WHERE +// posMaster.current_holderId IS NOT NULL +// ORDER BY +// profile.citizenId ASC +// `); +// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_pos_master","SELECT \n posMaster.id,\n posMaster.posMasterNoPrefix,\n posMaster.posMasterNo,\n posMaster.posMasterNoSuffix,\n posMaster.orgRevisionId,\n posMaster.orgRootId,\n posMaster.orgChild1Id,\n posMaster.orgChild2Id,\n posMaster.orgChild3Id,\n posMaster.orgChild4Id,\n posMaster.current_holderId,\n profile.id as profileId,\n profile.prefix,\n profile.firstName,\n profile.lastName,\n profile.citizenId,\n profile.position,\n profile.amount,\n profile.dateRetire,\n profile.birthDate,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n position.positionExecutiveField,\n position.positionArea,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n posLevel.id as posLevelId,\n posLevel.posLevelName,\n\t posType.id as posTypeId,\n posType.posTypeName\n FROM \n posMaster\n LEFT JOIN \n profile ON posMaster.current_holderId = profile.id\n LEFT JOIN \n orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON posMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN (\n SELECT *\n FROM profileDiscipline pd1\n WHERE pd1.date = (\n SELECT MAX(pd2.date)\n FROM profileDiscipline pd2\n WHERE pd2.profileId = pd1.profileId\n )\n ) AS profileDiscipline ON profileDiscipline.profileId = profile.id\n LEFT JOIN (\n SELECT pl1.*\n FROM profileLeave pl1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileLeave\n GROUP BY profileId\n ) pl2 ON pl1.profileId = pl2.profileId\n AND pl1.createdAt = pl2.maxDate\n ) AS profileLeave \n ON profileLeave.profileId = posMaster.current_holderId\n LEFT JOIN (\n SELECT pa1.*\n FROM profileAssessment pa1\n INNER JOIN (\n SELECT profileId, MAX(createdAt) AS maxDate\n FROM profileAssessment\n GROUP BY profileId\n ) pa2 ON pa1.profileId = pa2.profileId\n AND pa1.createdAt = pa2.maxDate\n ) AS profileAssessment \n ON profileAssessment.profileId = profile.id\n LEFT JOIN \n posLevel ON profile.posLevelId = posLevel.id\n LEFT JOIN \n posType ON profile.posTypeId = posType.id\n WHERE \t\n posMaster.current_holderId IS NOT NULL\n ORDER BY \n profile.citizenId ASC"]); +// await queryRunner.query(`CREATE VIEW \`view_current_tenure_employee\` AS +// WITH resultData AS ( +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileEmployeeId, +// ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber +// FROM ( +// SELECT +// commandDateAffect, +// commandDateSign, +// positionName, +// positionCee, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileEmployeeId, +// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, +// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - +// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId +// FROM +// profileSalary +// WHERE +// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) +// ORDER BY +// commandDateAffect ASC, commandDateSign ASC +// ) AS groupedPosition +// WHERE +// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign +// GROUP BY +// profileEmployeeId, groupedId, positionName +// ) +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// days_diff, +// Years, +// Months, +// Days, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileEmployeeId, +// orderNumber +// FROM resultData + +// UNION ALL + +// SELECT +// CURDATE() AS commandDateAffect, +// NULL AS positionName, +// NULL AS positionCee, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', +// NULL AS posNo, +// NULL AS positionExecutive, +// NULL AS positionType, +// NULL AS positionLevel, +// NULL AS OrgRoot, +// NULL AS orgChild1, +// NULL AS orgChild2, +// NULL AS orgChild3, +// NULL AS orgChild4, +// NULL AS commandCode, +// NULL AS commandName, +// NULL AS commandNo, +// NULL AS commandYear, +// NULL AS remark, +// profileEmployeeId, +// NULL AS orderNumber +// FROM resultData +// `); +// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_employee","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]); +// await queryRunner.query(`CREATE VIEW \`view_current_tenure_exc_officer\` AS +// WITH resultData AS ( +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// orgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber +// FROM ( +// SELECT +// commandDateAffect, +// commandDateSign, +// positionName, +// positionCee, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// orgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - +// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId +// FROM +// profileSalary +// WHERE +// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND +// positionExecutive <> '' +// ORDER BY +// commandDateAffect ASC, commandDateSign ASC +// ) AS groupedPositionExe +// GROUP BY +// groupedId, positionExecutive +// ) +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// days_diff, +// Years, +// Months, +// Days, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// orgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// orderNumber +// FROM resultData + +// UNION ALL + +// SELECT +// CURDATE() AS commandDateAffect, +// NULL AS positionName, +// NULL AS positionCee, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', +// NULL AS posNo, +// NULL AS positionExecutive, +// NULL AS positionType, +// NULL AS positionLevel, +// NULL AS orgRoot, +// NULL AS orgChild1, +// NULL AS orgChild2, +// NULL AS orgChild3, +// NULL AS orgChild4, +// NULL AS commandCode, +// NULL AS commandName, +// NULL AS commandNo, +// NULL AS commandYear, +// NULL AS remark, +// profileId, +// NULL AS orderNumber +// FROM resultData +// `); +// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_exc_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND\n positionExecutive <> ''\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPositionExe\n GROUP BY\n groupedId, positionExecutive\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff, \n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS orgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); +// await queryRunner.query(`CREATE VIEW \`view_current_tenure_officer\` AS +// WITH resultData AS ( +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber +// FROM ( +// SELECT +// commandDateAffect, +// commandDateSign, +// positionName, +// positionCee, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, +// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - +// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId +// FROM +// profileSalary +// WHERE +// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) +// ORDER BY +// commandDateAffect ASC, commandDateSign ASC +// ) AS groupedPosition +// WHERE +// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign +// GROUP BY +// profileId, groupedId, positionName +// ) +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// days_diff, +// Years, +// Months, +// Days, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// orderNumber +// FROM resultData + +// UNION ALL + +// SELECT +// CURDATE() AS commandDateAffect, +// NULL AS positionName, +// NULL AS positionCee, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', +// NULL AS posNo, +// NULL AS positionExecutive, +// NULL AS positionType, +// NULL AS positionLevel, +// NULL AS OrgRoot, +// NULL AS orgChild1, +// NULL AS orgChild2, +// NULL AS orgChild3, +// NULL AS orgChild4, +// NULL AS commandCode, +// NULL AS commandName, +// NULL AS commandNo, +// NULL AS commandYear, +// NULL AS remark, +// profileId, +// NULL AS orderNumber +// FROM resultData +// `); +// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); + } + + public async down(queryRunner: QueryRunner): Promise { +// await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_officer","hrms_organization"]); +// await queryRunner.query(`DROP VIEW \`view_current_tenure_officer\``); +// await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_exc_officer","hrms_organization"]); +// await queryRunner.query(`DROP VIEW \`view_current_tenure_exc_officer\``); +// await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_employee","hrms_organization"]); +// await queryRunner.query(`DROP VIEW \`view_current_tenure_employee\``); +// await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_pos_master","hrms_organization"]); +// await queryRunner.query(`DROP VIEW \`view_pos_master\``); +// await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_employee_pos_master","hrms_organization"]); +// await queryRunner.query(`DROP VIEW \`view_employee_pos_master\``); +// await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","hrms_organization"]); +// await queryRunner.query(`DROP VIEW \`view_registry_employee\``); + await queryRunner.query(`ALTER TABLE \`apiAttribute\` DROP FOREIGN KEY \`FK_13856cc8b4244f6a6fc26c4e0ff\``); +// await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP FOREIGN KEY \`FK_f1ded3e1f83ab2437f739a14f38\``); +// await queryRunner.query(`ALTER TABLE \`educationMis\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FLAG_EDUCATION\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FLAG_EDUCATION\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MAJOR_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MAJOR_CODE\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FUND_COURSE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FUND_COURSE_CODE\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_POS_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_POS_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`mp_command_num\``); +// await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`mp_command_num\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryRef\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryRef\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNo\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNo\` varchar(40) NULL COMMENT 'เลขที่ตำแหน่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP PRIMARY KEY`); +// await queryRunner.query(`ALTER TABLE \`subDistrictImport\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`metaWorkflow\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`metaState\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`metaStateOperator\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`isEntry\` \`isEntry\` tinyint NULL COMMENT 'ข้อมูลจาก Entry'`); +// await queryRunner.query(`ALTER TABLE \`profileTraining\` CHANGE \`isEntry\` \`isEntry\` tinyint NULL COMMENT 'ข้อมูลจาก Entry' DEFAULT '0'`); +// await queryRunner.query(`ALTER TABLE \`entity_base\` CHANGE \`lastUpdateFullName\` \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`entity_base\` CHANGE \`createdFullName\` \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string'`); +// await queryRunner.query(`ALTER TABLE \`entity_base\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`FLAG_EDUCATION\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`MAJOR_CODE\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`FUND_COURSE_CODE\``); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ID\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`ProfileId\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionName\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionSalaryAmount\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`Amount\``); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`Order\``); + await queryRunner.query(`ALTER TABLE \`apiName\` DROP COLUMN \`isActive\``); + await queryRunner.query(`ALTER TABLE \`apiName\` DROP COLUMN \`system\``); + await queryRunner.query(`ALTER TABLE \`apiName\` DROP COLUMN \`code\``); +// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MINOR_CODE\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UPDATE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CREATE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_JOB_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_SECTION_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_DIVISION_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_DEPARTMENT_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`HELP_LIVING_AMOUNT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`DEXPIRE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETIRE_POS_NO\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETIRE_TYPE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SUN_NO\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MARRIAGE_STATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_RETIRE_STATUS\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_NAME_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_CODE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`GROUPWORK_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_CODE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_ADD_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_AMT_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_CODE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_1_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_POS_DATE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_DATE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME_CODE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_YEAR_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CUR_YEAR_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_NUM_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_O\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CONTENT_NO\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CUR_YEAR\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_CODE_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_MP_YEAR\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_YEAR\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_POS_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_NUM\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_CUR_ST\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`COST_LIVING_AMOUNT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`PAYMENT_PERCENT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`PAYMENT_AMT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_AMT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_PERCENT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_ADD\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SAL_POS_AMOUNT_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_ABB_NAME_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIALIST_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIALIST_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SAL_POS_AMOUNT_2\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_ABB_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POSITION_CATG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UNIVER_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MAJOR_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MAJOR_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`EDUCATION_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FUND_COURSE_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UPCLASS_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FORCE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETURN_OCCUPY_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_YEAR\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TYPE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RANK_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`HRMS_DIV_CODE\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`HRMS_DEP_CODE\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`ORDER\` mediumtext NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ACTIVE_STATUS\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`GROUPWORK_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`GROUPWORK_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_LEVEL\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_CEE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE_EDIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_E\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_CODE_E\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR_EDIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM_EDIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE_EDIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB_EDIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_EDIT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MVMENT_OF\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MVMENT_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`REC_STATUS\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POSITION_CATG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COUNTRY_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`PROVINCE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`PLACE_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COURSE_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COURSE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`UPDATE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CREATE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`AUDIT_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`AUDIT_FLAG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG_CURRENT\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`UP_C_FLAG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_POS_STATUS\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FILL_APP_FLAG\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIALIST_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_ABB_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_ABB_NAME_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_CODE_1\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ADMIN_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_LEVEL_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`WORK_LINE_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DIVISION_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SECTION_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`JOB_CODE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FORCE_DATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_YEAR\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`USER_UPDATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`USER_CREATE\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIALIST_NAME\` text NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionRef\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionPathSideName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLineName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OrgName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`CLevel\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`AgencyName\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryStatus\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`CommandTypeName\` longtext NOT NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`RefCommandNo\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`RefCommandDate\` datetime(6) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoEmployee\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeePositionSideId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeePositionId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeeLevelId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeeGroupId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OrganizationShortNameId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionPathSideId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLineId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveSideId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OcId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoId\` char(36) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryClass\` longtext NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`IsActive\` tinyint(1) NULL`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandNo\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionCee\` varchar(255) NULL COMMENT 'ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionName\` text NULL COMMENT 'ตำแหน่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNoAbb\` varchar(40) NULL COMMENT 'ตัวย่อเลขที่ตำแหน่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandDateAffect\` datetime NULL COMMENT 'คำสั่งมีผลวันที่'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandDateSign\` datetime NULL COMMENT 'คำสั่งวันที่'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandYear\` int NULL COMMENT 'ปีที่ออกคำสั่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild4\` varchar(255) NULL COMMENT 'child4 name'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild3\` varchar(255) NULL COMMENT 'child3 name'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild2\` varchar(255) NULL COMMENT 'child2 name'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild1\` varchar(255) NULL COMMENT 'child1 name'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgRoot\` varchar(255) NULL COMMENT 'root name'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง command'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`isGovernment\` tinyint NULL COMMENT 'เข้ารับราชการ'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`dateGovernment\` datetime NULL COMMENT 'วันที่'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`order\` int NULL COMMENT 'เรียงลำดับใหมาตามการนำเข้า'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionLevel\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionType\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionExecutive\` varchar(255) NULL COMMENT 'ตำแหน่งทางการบริหาร'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`mouthSalaryAmount\` double NULL COMMENT 'เงินค่าตอบแทนรายเดือน' DEFAULT '0'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionSalaryAmount\` double NULL COMMENT 'เงินประจำตำแหน่ง' DEFAULT '0'`); +// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`amount\` double NULL COMMENT 'เงินเดือนฐาน' DEFAULT '0'`); +// await queryRunner.query(`DROP TABLE \`EMPLOYEETEMP\``); +// await queryRunner.query(`DROP TABLE \`EMPLOYEE\``); +// await queryRunner.query(`DROP TABLE \`HR_CHANGENAME_EMPTEMP\``); + } + +} diff --git a/tsoa.json b/tsoa.json index 6cb0cf0d..492907b8 100644 --- a/tsoa.json +++ b/tsoa.json @@ -23,6 +23,12 @@ "name": "Authorization", "description": "Keycloak Bearer Token", "in": "header" + }, + "webServiceAuth": { + "type": "apiKey", + "name": "X-API-Key", + "description": "API KEY สำหรับ Web Service", + "in": "header" } }, "tags": [