From 4cccf6f685c474ffa848a67083315939e8913b79 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Jun 2024 13:00:33 +0700 Subject: [PATCH 1/4] =?UTF-8?q?api=20=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=A2=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=AA=E0=B8=B1=E0=B8=9A=E0=B9=80=E0=B8=9B?= =?UTF-8?q?=E0=B8=A5=E0=B8=B5=E0=B9=88=E0=B8=A2=E0=B8=99=E0=B8=95=E0=B8=B3?= =?UTF-8?q?=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ChangePositionController.ts | 74 ++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/controllers/ChangePositionController.ts b/src/controllers/ChangePositionController.ts index 9ce7281a..516c0dde 100644 --- a/src/controllers/ChangePositionController.ts +++ b/src/controllers/ChangePositionController.ts @@ -38,7 +38,7 @@ import { OrgChild1 } from "../entities/OrgChild1"; import { OrgChild2 } from "../entities/OrgChild2"; import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; - +import CallAPI from "../interfaces/call-api"; @Route("api/v1/org/placement/change-position") @Tags("Placement") @Security("bearerAuth") @@ -163,6 +163,7 @@ export class ChangePositionController extends Controller { ) { const [changePosition, total] = await AppDataSource.getRepository(ChangePosition) .createQueryBuilder("changePosition") + .leftJoinAndSelect("changePosition.profileChangePosition", "profileChangePosition") .where( searchKeyword ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" @@ -187,7 +188,10 @@ export class ChangePositionController extends Controller { @Get("{id}") async GetChangePositionById( @Path() id: string ) { - const data = await this.changePositionRepository.findOne({ where: { id: id }}); + const data = await this.changePositionRepository.findOne({ + relations: ["profileChangePosition"], + where: { id: id }} + ); if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); return new HttpSuccess(data); } @@ -338,6 +342,7 @@ export class ChangePositionController extends Controller { profileChangePos.positionNumberOld = body.positionNumberOld; profileChangePos.amountOld = body.amountOld; profileChangePos.reason = body.reason? String(body.reason) : ""; + profileChangePos.dateCurrent = body.dateCurrent; await this.profileChangePositionRepository.save(profileChangePos); return new HttpSuccess(); } @@ -465,5 +470,70 @@ export class ChangePositionController extends Controller { return new HttpSuccess(); } + /** + * API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง REPORT + * + * @summary API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง REPORT (ADMIN) + * + */ + @Post("report") + async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) { + const profilechangePositions = await this.changePositionRepository.find({ + relations: ["profileChangePosition"], + where: { id: In(requestBody.id) } + }); + for (const item of profilechangePositions) { + item.status = "REPORT"; + item.lastUpdateUserId = request.user.sub; + item.lastUpdateFullName = request.user.name; + if (item.profileChangePosition) { + for (const profile of item.profileChangePosition) { + profile.status = "REPORT"; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + await this.profileChangePositionRepository.save(profile); + } + } + await this.changePositionRepository.save(item); + } + return new HttpSuccess(); + } + + /** + * API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง DONE + * + * @summary API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง DONE (ADMIN) + * + */ + @Post("report/resume") + async doneReport( + @Body() + body: { + result: { + id: string; + }[]; + }, + @Request() request: { user: Record }, + ) { + await Promise.all( + body.result.map(async (v) => { + const profile = await this.profileChangePositionRepository.findOne({ + where: { id: v.id } + }); + if (profile != null) { + await new CallAPI() + .PostData(request, "org/profile/salary", { + profileId: profile.id, + date: new Date(), + }) + .then(async (x) => { + profile.status = "DONE"; + await this.profileChangePositionRepository.save(profile); + }); + } + }), + ); + return new HttpSuccess(); + } } From 693afa4e5fc4bfb18de7d7b55186286167f3644a Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Jun 2024 14:18:20 +0700 Subject: [PATCH 2/4] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ChangePositionController.ts | 2 +- src/entities/AuthRole.ts | 6 +++++- src/entities/PosMaster.ts | 11 +++++++++++ src/entities/ProfileChangePosition.ts | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/controllers/ChangePositionController.ts b/src/controllers/ChangePositionController.ts index 516c0dde..9cffa825 100644 --- a/src/controllers/ChangePositionController.ts +++ b/src/controllers/ChangePositionController.ts @@ -339,7 +339,7 @@ export class ChangePositionController extends Controller { profileChangePos.posMasterNoOld = body.posMasterNoOld; profileChangePos.positionTypeOld = body.positionTypeOld; profileChangePos.positionLevelOld = body.positionLevelOld; - profileChangePos.positionNumberOld = body.positionNumberOld; + profileChangePos.organizationPositionOld = body.organizationPositionOld; profileChangePos.amountOld = body.amountOld; profileChangePos.reason = body.reason? String(body.reason) : ""; profileChangePos.dateCurrent = body.dateCurrent; diff --git a/src/entities/AuthRole.ts b/src/entities/AuthRole.ts index 9f197cd9..1cc3cbe7 100644 --- a/src/entities/AuthRole.ts +++ b/src/entities/AuthRole.ts @@ -1,6 +1,7 @@ -import { Entity, Column, OneToMany } from "typeorm"; +import { Entity, Column, OneToMany, OneToOne } from "typeorm"; import { EntityBase } from "./base/Base"; import { AuthRoleAttr } from "./AuthRoleAttr"; +import { PosMaster } from "./PosMaster"; @Entity("authRole") export class AuthRole extends EntityBase { @@ -22,6 +23,9 @@ export class AuthRole extends EntityBase { @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForRole) authRoles: AuthRoleAttr[]; + + @OneToOne(() => PosMaster, (posMaster) => posMaster.authRole) + posMaster: PosMaster; } export class CreateAuthRole { diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index 5fc8d032..f181deb2 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -9,6 +9,7 @@ import { OrgChild2 } from "./OrgChild2"; import { OrgChild3 } from "./OrgChild3"; import { OrgChild4 } from "./OrgChild4"; import { Profile } from "./Profile"; +import { AuthRole } from "./AuthRole"; enum PosMasterLine { MAIN = "MAIN", @@ -170,6 +171,16 @@ export class PosMaster extends EntityBase { }) orgRevisionId: string; //fk + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง authRole", + }) + authRoleId: string; + + @OneToOne(() => AuthRole, (authRole) => authRole.posMaster) + @JoinColumn({ name: "authRoleId" }) + authRole: AuthRole; + @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.posMasters) @JoinColumn({ name: "orgRevisionId" }) orgRevision: OrgRevision; diff --git a/src/entities/ProfileChangePosition.ts b/src/entities/ProfileChangePosition.ts index f7f40f06..38ea5dfb 100644 --- a/src/entities/ProfileChangePosition.ts +++ b/src/entities/ProfileChangePosition.ts @@ -255,7 +255,7 @@ export type UpdateProfileChangePosition = { posMasterNoOld: number; positionTypeOld: string; positionLevelOld: string; - positionNumberOld: string; + organizationPositionOld: string; amountOld: number; dateCurrent : Date; reason: string | null; From a7d13ac00b14f9fae4d893ec79e0d68885cc425b Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Thu, 13 Jun 2024 14:31:37 +0700 Subject: [PATCH 3/4] Create 1718263333866-update_table_posmaster_add_role.ts --- ...3333866-update_table_posmaster_add_role.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/migration/1718263333866-update_table_posmaster_add_role.ts diff --git a/src/migration/1718263333866-update_table_posmaster_add_role.ts b/src/migration/1718263333866-update_table_posmaster_add_role.ts new file mode 100644 index 00000000..f6853014 --- /dev/null +++ b/src/migration/1718263333866-update_table_posmaster_add_role.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTablePosmasterAddRole1718263333866 implements MigrationInterface { + name = 'UpdateTablePosmasterAddRole1718263333866' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`authRoleId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD UNIQUE INDEX \`IDX_a059796d095e79ba5b20407859\` (\`authRoleId\`)`); + await queryRunner.query(`CREATE UNIQUE INDEX \`REL_a059796d095e79ba5b20407859\` ON \`posMaster\` (\`authRoleId\`)`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_a059796d095e79ba5b20407859f\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_a059796d095e79ba5b20407859f\``); + await queryRunner.query(`DROP INDEX \`REL_a059796d095e79ba5b20407859\` ON \`posMaster\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP INDEX \`IDX_a059796d095e79ba5b20407859\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`authRoleId\``); + } + +} From 18510b1419009c79c6b9e7a90e1cce352b4ed450 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Jun 2024 14:41:47 +0700 Subject: [PATCH 4/4] relation --- src/controllers/AuthRoleController.ts | 10 +++++++++- src/entities/AuthRole.ts | 12 ++++++++++++ src/entities/EmployeePosMaster.ts | 11 +++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 94c7012c..0c83d910 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -17,8 +17,10 @@ import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; -import { AuthRole, CreateAuthRole, UpdateAuthRole } from "../entities/AuthRole"; +import { AuthRole, CreateAuthRole, UpdateAuthRole, CreateAddAuthRole } from "../entities/AuthRole"; import { AuthRoleAttr } from "../entities/AuthRoleAttr"; +import { PosMaster } from "../entities/PosMaster"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; @Route("api/v1/org/auth/authRole") @Tags("AuthRole") @@ -72,6 +74,12 @@ export class AuthRoleController extends Controller { return new HttpSuccess(data.id); } + @Post("assign") + public async AddAuthRole(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) { + // console pasMater = await this + return new HttpSuccess(); + } + @Patch("{roleId}") public async editAuthRole( @Request() req: RequestWithUser, diff --git a/src/entities/AuthRole.ts b/src/entities/AuthRole.ts index 1cc3cbe7..cb688bd4 100644 --- a/src/entities/AuthRole.ts +++ b/src/entities/AuthRole.ts @@ -2,6 +2,7 @@ import { Entity, Column, OneToMany, OneToOne } from "typeorm"; import { EntityBase } from "./base/Base"; import { AuthRoleAttr } from "./AuthRoleAttr"; import { PosMaster } from "./PosMaster"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; @Entity("authRole") export class AuthRole extends EntityBase { @@ -26,6 +27,9 @@ export class AuthRole extends EntityBase { @OneToOne(() => PosMaster, (posMaster) => posMaster.authRole) posMaster: PosMaster; + + @OneToOne(() => EmployeePosMaster, (posMasters) => posMasters.authRole) + posMasters: EmployeePosMaster; } export class CreateAuthRole { @@ -37,3 +41,11 @@ export class CreateAuthRole { } export type UpdateAuthRole = Partial; + +export class CreateAddAuthRole { + @Column() + authRoleId: string; + + @Column() + posMasterId: string; +} \ No newline at end of file diff --git a/src/entities/EmployeePosMaster.ts b/src/entities/EmployeePosMaster.ts index 6c47e067..c1c6e0a8 100644 --- a/src/entities/EmployeePosMaster.ts +++ b/src/entities/EmployeePosMaster.ts @@ -10,6 +10,7 @@ import { OrgChild3 } from "./OrgChild3"; import { OrgChild4 } from "./OrgChild4"; import { Profile } from "./Profile"; import { ProfileEmployee } from "./ProfileEmployee"; +import { AuthRole } from "./AuthRole"; enum EmployeePosMasterLine { MAIN = "MAIN", @@ -171,6 +172,16 @@ export class EmployeePosMaster extends EntityBase { }) orgRevisionId: string; //fk + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง authRole", + }) + authRoleId: string; + + @OneToOne(() => AuthRole, (authRole) => authRole.posMasters) + @JoinColumn({ name: "authRoleId" }) + authRole: AuthRole; + @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.posMasters) @JoinColumn({ name: "orgRevisionId" }) orgRevision: OrgRevision;