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..9bec1b67 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,18 @@ export class EmployeePosMaster extends EntityBase { }) orgRevisionId: string; //fk + @Column({ + nullable: true, + default: null, + 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; diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index f181deb2..521bec87 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -172,6 +172,8 @@ export class PosMaster extends EntityBase { orgRevisionId: string; //fk @Column({ + nullable: true, + default: null, length: 40, comment: "คีย์นอก(FK)ของตาราง authRole", }) diff --git a/src/migration/1718264530424-update_table_posmaster_add_roleๅ.ts b/src/migration/1718264530424-update_table_posmaster_add_roleๅ.ts deleted file mode 100644 index 1a0651b1..00000000 --- a/src/migration/1718264530424-update_table_posmaster_add_roleๅ.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTablePosmasterAddRoleๅ1718264530424 implements MigrationInterface { - name = 'UpdateTablePosmasterAddRoleๅ1718264530424' - - public async up(queryRunner: QueryRunner): Promise { - 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\``); - } - -} diff --git a/src/migration/1718266321698-update_table_posmaster_add_role1.ts b/src/migration/1718266321698-update_table_posmaster_add_role1.ts new file mode 100644 index 00000000..a6c96634 --- /dev/null +++ b/src/migration/1718266321698-update_table_posmaster_add_role1.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTablePosmasterAddRole11718266321698 implements MigrationInterface { + name = 'UpdateTablePosmasterAddRole11718266321698' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`employeePosMaster\` CHANGE \`authRoleId\` \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); + await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD UNIQUE INDEX \`IDX_388ecc9f2a9f5b5ff1e08fd6d0\` (\`authRoleId\`)`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`authRoleId\` \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD UNIQUE INDEX \`IDX_a059796d095e79ba5b20407859\` (\`authRoleId\`)`); + await queryRunner.query(`CREATE UNIQUE INDEX \`REL_388ecc9f2a9f5b5ff1e08fd6d0\` ON \`employeePosMaster\` (\`authRoleId\`)`); + await queryRunner.query(`CREATE UNIQUE INDEX \`REL_a059796d095e79ba5b20407859\` ON \`posMaster\` (\`authRoleId\`)`); + await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD CONSTRAINT \`FK_388ecc9f2a9f5b5ff1e08fd6d0e\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + 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(`ALTER TABLE \`employeePosMaster\` DROP FOREIGN KEY \`FK_388ecc9f2a9f5b5ff1e08fd6d0e\``); + await queryRunner.query(`DROP INDEX \`REL_a059796d095e79ba5b20407859\` ON \`posMaster\``); + await queryRunner.query(`DROP INDEX \`REL_388ecc9f2a9f5b5ff1e08fd6d0\` ON \`employeePosMaster\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP INDEX \`IDX_a059796d095e79ba5b20407859\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`authRoleId\` \`authRoleId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); + await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP INDEX \`IDX_388ecc9f2a9f5b5ff1e08fd6d0\``); + await queryRunner.query(`ALTER TABLE \`employeePosMaster\` CHANGE \`authRoleId\` \`authRoleId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); + } + +}