diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 2e2148c1..36be10f1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -30,6 +30,7 @@ import { UpdateProfileFather, UpdateProfileMother, UpdateProfileCouple, + UpdatePrivacyDto } from "../entities/Profile"; import { Brackets, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; @@ -5176,6 +5177,67 @@ export class ProfileController extends Controller { return new HttpSuccess(lastestData.id); } + /** + * API อัพเดทสถานะ privacy + * + * @summary API อัพเดทสถานะ privacy + * + */ + @Put("privacy") + async updatePrivacy( + @Request() request: { user: Record }, + @Body() body: UpdatePrivacyDto + ) { + let isEmployee = false; + let profile: any = null; + profile = await this.profileRepo.findOneBy({ + keycloak: request.user.sub, + }); + + if (!profile) { + profile = await this.profileEmpRepo.findOne({ + where: { keycloak: request.user.sub }, + }); + isEmployee = true; + } + + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const system = body.system.trim().toUpperCase(); + switch (system) { + case "CHECKIN": + profile.privacyCheckin = body.accept; + break; + + case "USER": + profile.privacyUser = body.accept; + break; + + case "MGT": + profile.privacyMgt = body.accept; + break; + + default: + throw new HttpError( + HttpStatus.BAD_REQUEST, + "system ไม่ถูกต้อง" + ); + } + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + profile.lastUpdatedAt = new Date(); + + if (isEmployee) { + await this.profileEmpRepo.save(profile, { data: request }); + } else { + await this.profileRepo.save(profile, { data: request }); + } + + return new HttpSuccess(); + } + /** * API แก้ไขทะเบียนประวัติ * @@ -7354,6 +7416,9 @@ export class ProfileController extends Controller { type: profile.employeeClass, salary: profile.amount, posNo: null, + privacyCheckin: profile.privacyCheckin, + privacyUser: profile.privacyUser, + privacyMgt : profile.privacyMgt // root?.orgRootShortName && posMaster?.posMasterNo // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` // : "", @@ -7523,6 +7588,9 @@ export class ProfileController extends Controller { salary: profile ? profile.amount : null, amountSpecial: profile ? profile.amountSpecial : null, posNo: null, + privacyCheckin: profile.privacyCheckin, + privacyUser: profile.privacyUser, + privacyMgt : profile.privacyMgt // root?.orgRootShortName && posMaster?.posMasterNo // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` // : "", diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index f82bd7d2..994fcfbe 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -421,6 +421,24 @@ export class Profile extends EntityBase { }) statusCheckEdit: string; + @Column({ + comment: "สถานะยืนยัน privacyCheckin", + default: false, + }) + privacyCheckin: boolean; + + @Column({ + comment: "สถานะยืนยัน privacyUser", + default: false, + }) + privacyUser: boolean; + + @Column({ + comment: "สถานะยืนยัน privacyMgt", + default: false, + }) + privacyMgt: boolean; + @OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder) current_holders: PosMaster[]; @@ -957,3 +975,8 @@ export type UpdateProfileAddress = { currentSubDistrictId?: string | null; currentZipCode?: string | null; }; + +export class UpdatePrivacyDto { + system: string; + accept: boolean; +} diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index e98065e5..04f7923f 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -688,6 +688,24 @@ export class ProfileEmployee extends EntityBase { }) statusCheckEdit: string; + @Column({ + comment: "สถานะยืนยัน privacyCheckin", + default: false, + }) + privacyCheckin: boolean; + + @Column({ + comment: "สถานะยืนยัน privacyUser", + default: false, + }) + privacyUser: boolean; + + @Column({ + comment: "สถานะยืนยัน privacyMgt", + default: false, + }) + privacyMgt: boolean; + @OneToMany(() => ProfileEmployeeInformationHistory, (v) => v.profileEmployeeInformation) information_histories: ProfileEmployeeInformationHistory[]; diff --git a/src/migration/1768555527430-add_fields_privacy.ts b/src/migration/1768555527430-add_fields_privacy.ts new file mode 100644 index 00000000..52f38e54 --- /dev/null +++ b/src/migration/1768555527430-add_fields_privacy.ts @@ -0,0 +1,37 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddFieldsPrivacy1768555527430 implements MigrationInterface { + name = 'AddFieldsPrivacy1768555527430' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`privacyCheckin\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyCheckin' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`privacyUser\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyUser' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`privacyMgt\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyMgt' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`privacyCheckin\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyCheckin' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`privacyUser\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyUser' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`privacyMgt\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyMgt' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`privacyCheckin\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyCheckin' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`privacyUser\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyUser' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`privacyMgt\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyMgt' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`privacyCheckin\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyCheckin' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`privacyUser\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyUser' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`privacyMgt\` tinyint NOT NULL COMMENT 'สถานะยืนยัน privacyMgt' DEFAULT 0`); +} + + public async down(queryRunner: QueryRunner): Promise { + + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`privacyMgt\``); + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`privacyUser\``); + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`privacyCheckin\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`privacyMgt\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`privacyUser\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`privacyCheckin\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`privacyMgt\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`privacyUser\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`privacyCheckin\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`privacyMgt\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`privacyUser\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`privacyCheckin\``); + } + +}