diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 2634d406..b2714b4b 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -1056,7 +1056,7 @@ export class EmployeePositionController extends Controller { }); const authRoleName = await this.authRoleRepo.findOne({ - where: { id: String(posMaster.authRoleId) } + where: { id: String(posMaster.authRoleId) }, }); let profile: any; @@ -1149,7 +1149,8 @@ export class EmployeePositionController extends Controller { profilePoslevel: level == null || type == null ? null : `${type.posTypeShortName} ${level.posLevelName}`, authRoleId: posMaster.authRoleId, - authRoleName: authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, + authRoleName: + authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName, positions: positions.map((position) => ({ id: position.id, positionName: position.positionName, @@ -2150,4 +2151,46 @@ export class EmployeePositionController extends Controller { return new HttpSuccess(); } + + /** + * API บันทึกตำแหน่งใหม่ + * + * @summary บันทึกตำแหน่งใหม่ + * + */ + @Post("report/current") + async reportApproveCurrent( + @Body() + body: { + posmasterId: string; + positionId: string; + profileId: string; + }, + ) { + const posMaster = await this.employeePosMasterRepository.findOne({ + where: { id: body.posmasterId }, + }); + if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); + + const posMasterOld = await this.employeePosMasterRepository.findOne({ + where: { + current_holderId: body.profileId, + orgRevisionId: posMaster.orgRevisionId, + }, + }); + if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) posMasterOld.next_holderId = null; + + const profile = await this.profileRepository.findOne({ + where: { id: body.profileId }, + }); + if (profile == null) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); + + posMaster.current_holderId = body.profileId; + posMaster.next_holderId = body.profileId; + if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld); + await this.employeePosMasterRepository.save(posMaster); + return new HttpSuccess(); + } } diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index c05fcad0..af7831fa 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -3353,4 +3353,32 @@ export class OrganizationController extends Controller { return new HttpSuccess(formattedData); } + + /** + * API + * + * @summary (ADMIN) + * + * @param {string} id + */ + @Get("approver/{id}") + async getUserRootOrg(@Path() id: string, @Request() request: { user: Record }) { + const root = await this.orgRootRepository.findOne({ + where: { id: id }, + }); + if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root"); + const posMaster = await this.posMasterRepository.find({ + where: { orgRootId: root.id, orgChild1Id: IsNull() }, + relations: ["current_holder"], + }); + if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); + + const maps = posMaster.map((posMaster) => ({ + Id: posMaster.current_holder.id, + Name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`, + PositionName: posMaster.current_holder.position, + })); + + return new HttpSuccess(maps); + } } diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index d921b77a..0d823a0a 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -117,8 +117,8 @@ export class OrganizationDotnetController extends Controller { }), ); } - const profileEmp = await queryBuilder.getMany(); - return new HttpSuccess(profileEmp); + const profileEmp = await queryBuilder.getMany(); + return new HttpSuccess(profileEmp); } /** @@ -154,7 +154,7 @@ export class OrganizationDotnetController extends Controller { if (!orgRoot) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); return new HttpSuccess(orgRoot); } - + /** * 3. API Get Profile จาก keycloak id * @@ -168,14 +168,14 @@ export class OrganizationDotnetController extends Controller { relations: { posLevel: true, posType: true, - profileSalary: true + profileSalary: true, }, where: { keycloak: keycloakId }, - order:{ - profileSalary:{ - date: "DESC" - } - } + order: { + profileSalary: { + date: "DESC", + }, + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -184,26 +184,26 @@ export class OrganizationDotnetController extends Controller { avatar: profile.avatar, avatarName: profile.avatarName, rank: profile.rank, - prefix: profile.prefix, - firstName: profile.firstName, - lastName: profile.lastName, - citizenId: profile.citizenId, - position: profile.position, - posLevelId: profile.posLevelId, - email: profile.email, - phone: profile.phone, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posLevelId: profile.posLevelId, + email: profile.email, + phone: profile.phone, keycloak: profile.keycloak, isProbation: profile.isProbation, isLeave: profile.isLeave, - leaveReason: profile.leaveReason, - dateRetire: profile.dateRetire, + leaveReason: profile.leaveReason, + dateRetire: profile.dateRetire, dateAppoint: profile.dateAppoint, dateRetireLaw: profile.dateRetireLaw, - dateStart: profile.dateStart, - govAgeAbsent: profile.govAgeAbsent, - govAgePlus: profile.govAgePlus, - birthDate: profile.birthDate, - reasonSameDate: profile.reasonSameDate, + dateStart: profile.dateStart, + govAgeAbsent: profile.govAgeAbsent, + govAgePlus: profile.govAgePlus, + birthDate: profile.birthDate, + reasonSameDate: profile.reasonSameDate, telephoneNumber: profile.telephoneNumber, nationality: profile.nationality, gender: profile.gender, @@ -215,18 +215,16 @@ export class OrganizationDotnetController extends Controller { registrationDistrictId: profile.registrationDistrictId, registrationSubDistrictId: profile.registrationSubDistrictId, registrationZipCode: profile.registrationZipCode, - currentAddress: profile.currentAddress, - currentProvinceId: profile.currentProvinceId, - currentSubDistrictId: profile.currentSubDistrictId, - currentZipCode: profile.currentZipCode, - dutyTimeId: profile.dutyTimeId, + currentAddress: profile.currentAddress, + currentProvinceId: profile.currentProvinceId, + currentSubDistrictId: profile.currentSubDistrictId, + currentZipCode: profile.currentZipCode, + dutyTimeId: profile.dutyTimeId, dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate, - posLevel: profile.posLevel? profile.posLevel : null, - posType: profile.posType? profile.posType : null, - profileSalary: profile.profileSalary.length > 0 - ? profile.profileSalary[0] - : null - } + posLevel: profile.posLevel ? profile.posLevel : null, + posType: profile.posType ? profile.posType : null, + profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null, + }; return new HttpSuccess(mapProfile); } @@ -242,10 +240,10 @@ export class OrganizationDotnetController extends Controller { async GetUserFullName(@Path() keycloakId: string) { const profile = await this.profileRepo.findOne({ where: { keycloak: keycloakId }, - select: ["prefix", "firstName", "lastName"] + select: ["prefix", "firstName", "lastName"], }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - const fullName = profile? `${profile.prefix}${profile.firstName} ${profile.lastName}` : "-"; + const fullName = profile ? `${profile.prefix}${profile.firstName} ${profile.lastName}` : "-"; return new HttpSuccess(fullName); } @@ -296,7 +294,7 @@ export class OrganizationDotnetController extends Controller { root: root == null ? null : root.orgRootName, rootShortName: root == null ? null : root.orgRootShortName, }; - return new HttpSuccess(profile); + return new HttpSuccess(_profile); } /** @@ -380,7 +378,7 @@ export class OrganizationDotnetController extends Controller { where: { posMasterId: posMaster?.id, }, - }); + }); const _profile: any = { profileId: profile.id, @@ -462,7 +460,7 @@ export class OrganizationDotnetController extends Controller { where: { id: ocId }, }); if (!orgRoot) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - const root = orgRoot? orgRoot.id : ""; + const root = orgRoot ? orgRoot.id : ""; return new HttpSuccess(root); } @@ -475,25 +473,26 @@ export class OrganizationDotnetController extends Controller { @Get("keycloak") async GetProfileWithKeycloak() { const profile = await this.profileRepo.find({ - where: { keycloak: Not(IsNull()) || Not(""), }, + where: { keycloak: Not(IsNull()) || Not("") }, }); return new HttpSuccess(profile); } /** - * 4. API Update รอบการลงเวลา ในตาราง profile + * 4. API Update รอบการลงเวลา ในตาราง profile * - * @summary 4. API Update รอบการลงเวลา ในตาราง profile + * @summary 4. API Update รอบการลงเวลา ในตาราง profile * */ @Put("update-dutytime") async UpdateDutyTimeAsync( @Request() req: RequestWithUser, - @Body() body: { + @Body() + body: { profileId: string; roundId: string; effectiveDate: Date; - } + }, ) { const profile = await this.profileRepo.findOne({ where: { id: body.profileId }, @@ -507,5 +506,4 @@ export class OrganizationDotnetController extends Controller { await this.profileRepo.save(profile); return new HttpSuccess(); } - } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 24505bac..d3bc9e3f 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3267,4 +3267,44 @@ export class PositionController extends Controller { ); return new HttpSuccess(data); } + + /** + * API บันทึกตำแหน่งใหม่ + * + * @summary บันทึกตำแหน่งใหม่ + * + */ + @Post("report/current") + async reportApproveCurrent( + @Body() + body: { + posmasterId: string; + positionId: string; + profileId: string; + }, + ) { + const posMaster = await this.posMasterRepository.findOne({ + where: { id: body.posmasterId }, + }); + if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); + + const posMasterOld = await this.posMasterRepository.findOne({ + where: { + current_holderId: body.profileId, + orgRevisionId: posMaster.orgRevisionId, + }, + }); + if (posMasterOld != null) posMasterOld.current_holderId = null; + + const profile = await this.profileRepository.findOne({ + where: { id: body.profileId }, + }); + if (profile == null) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); + + posMaster.current_holderId = body.profileId; + if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); + await this.posMasterRepository.save(posMaster); + return new HttpSuccess(); + } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index c42e6f81..acfed8de 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -4266,17 +4266,25 @@ export class ProfileController extends Controller { async updateLeaveUser( @Path() id: string, @Body() - requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date }, + requestBody: { isLeave: boolean; leaveReason?: any; dateLeave?: any }, @Request() request: { user: Record }, ) { const profile = await this.profileRepo.findOne({ where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + const _null: any = null; profile.isLeave = requestBody.isLeave; - profile.leaveReason = requestBody.leaveReason; - profile.dateLeave = requestBody.dateLeave; + if (profile.leaveReason != undefined && profile.leaveReason != null) { + profile.leaveReason = requestBody.leaveReason; + } else { + profile.leaveReason = _null; + } + if (profile.dateLeave != undefined && profile.dateLeave != null) { + profile.dateLeave = requestBody.dateLeave; + } else { + profile.dateLeave = _null; + } await this.profileRepo.save(profile); const profileSalary = await this.salaryRepository.findOne({ @@ -4488,7 +4496,7 @@ export class ProfileController extends Controller { return new HttpSuccess(profile); } - /** + /** * API สร้างทะเบียนประวัติใหม่ * * @summary ORG_065 - สร้างทะเบียนประวัติใหม่ (ADMIN) #XXX @@ -4499,11 +4507,16 @@ export class ProfileController extends Controller { @Request() request: RequestWithUser, @Body() body: CreateProfileAllFields, ) { + const citizen = await this.profileRepo.findOne({ + where: { citizenId: body.citizenId }, + select: ["id"], + }); + if (citizen) return new HttpSuccess(citizen.id); const profile: Profile = Object.assign(new Profile(), body); if (body && body.posLevelId) { const findPosLevel = await this.posLevelRepo.findOne({ where: { posLevelName: body.posLevelId }, - select:['id','posLevelName'] + select: ["id", "posLevelName"], }); if (findPosLevel) { profile.posLevelId = findPosLevel.id; @@ -4512,7 +4525,7 @@ export class ProfileController extends Controller { if (body && body.posTypeId) { const findPosType = await this.posTypeRepo.findOne({ where: { posTypeName: body.posTypeId }, - select:['id','posTypeName'] + select: ["id", "posTypeName"], }); if (findPosType) { profile.posTypeId = findPosType.id; @@ -4521,7 +4534,7 @@ export class ProfileController extends Controller { if (body && body.prefix) { const findPrefix = await this.prefixRepo.findOne({ where: { name: body.prefix }, - select:['id','name'] + select: ["id", "name"], }); if (findPrefix) { profile.prefix = findPrefix.id; @@ -4531,25 +4544,25 @@ export class ProfileController extends Controller { if (body && body.currentProvinceId) { const findProvince = await this.provinceRepo.findOne({ where: { name: body.currentProvinceId }, - select:['id','name'] + select: ["id", "name"], }); - if (findProvince) { - profile.currentProvinceId = findProvince.id; - } + if (findProvince) { + profile.currentProvinceId = findProvince.id; + } } if (body && body.currentDistrictId) { const findDistrict = await this.districtRepo.findOne({ where: { name: body.currentDistrictId }, - select:['id','name'] + select: ["id", "name"], }); - if (findDistrict) { - profile.currentDistrictId = findDistrict.id; - } + if (findDistrict) { + profile.currentDistrictId = findDistrict.id; + } } if (body && body.currentSubDistrictId) { const findSubDistrict = await this.subDistrictRepo.findOne({ where: { name: body.currentSubDistrictId }, - select:['id','name'] + select: ["id", "name"], }); if (findSubDistrict) { profile.currentSubDistrictId = findSubDistrict.id; @@ -4559,7 +4572,7 @@ export class ProfileController extends Controller { if (body && body.registrationProvinceId) { const findProvince_regis = await this.provinceRepo.findOne({ where: { name: body.registrationProvinceId }, - select:['id','name'] + select: ["id", "name"], }); if (findProvince_regis) { profile.registrationProvinceId = findProvince_regis.id; @@ -4568,7 +4581,7 @@ export class ProfileController extends Controller { if (body && body.registrationDistrictId) { const findDistrict_regis = await this.districtRepo.findOne({ where: { name: body.registrationDistrictId }, - select:['id','name'] + select: ["id", "name"], }); if (findDistrict_regis) { profile.registrationDistrictId = findDistrict_regis.id; @@ -4577,13 +4590,13 @@ export class ProfileController extends Controller { if (body && body.registrationSubDistrictId) { const findSubDistrict_regis = await this.subDistrictRepo.findOne({ where: { name: body.registrationSubDistrictId }, - select:['id','name'] + select: ["id", "name"], }); - if (findSubDistrict_regis) { - profile.registrationSubDistrictId = findSubDistrict_regis.id; - } + if (findSubDistrict_regis) { + profile.registrationSubDistrictId = findSubDistrict_regis.id; + } } - + profile.createdUserId = request.user.sub; profile.createdFullName = request.user.name; profile.lastUpdateUserId = request.user.sub; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 71f6d4db..c2741e34 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2705,7 +2705,6 @@ export class ProfileEmployeeController extends Controller { refCommandNo: null, templateDoc: requestBody.leaveReason, }); - return new HttpSuccess(); } @@ -3032,6 +3031,13 @@ export class ProfileEmployeeController extends Controller { profile.employeeClass = "PERM"; await this.profileRepo.save(profile); }); + await new CallAPI() + .PostData(request, "org/employee/pos/report/current", { + posmasterId: profile.posmasterIdTemp, + positionId: profile.positionIdTemp, + profileId: profile.id, + }) + .then(async (x) => {}); } }), ); diff --git a/src/migration/1718866177977-update_table_org2006.ts b/src/migration/1718866177977-update_table_org2006.ts deleted file mode 100644 index a8471cfc..00000000 --- a/src/migration/1718866177977-update_table_org2006.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableOrg20061718866177977 implements MigrationInterface { - name = 'UpdateTableOrg20061718866177977' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE \`authRoleAttr\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`attrOwnership\` varchar(255) NULL, \`attrIsCreate\` tinyint NOT NULL DEFAULT 0, \`attrIsList\` tinyint NOT NULL DEFAULT 0, \`attrIsGet\` tinyint NOT NULL DEFAULT 0, \`attrIsUpdate\` tinyint NOT NULL DEFAULT 0, \`attrIsDelete\` tinyint NOT NULL DEFAULT 0, \`attrPrivilege\` varchar(255) NULL, \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง AuthRole', \`authSysId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง AuthSys', \`parentNode\` varchar(255) NULL COMMENT 'Root', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`authRole\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`roleName\` varchar(255) NULL COMMENT 'ชื่อบทบาท', \`roleDescription\` varchar(255) NULL COMMENT 'รายละเอียด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`posMasterAct\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`posMasterOrder\` int NULL COMMENT 'ลำดับที่แสดงผล', \`posMasterId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง posMaster', \`posMasterChildId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง posMasterChild', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`changePosition\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` text NULL COMMENT 'ชื่อรอบการย้ายสับเปลี่ยนตำแหน่ง', \`date\` datetime NULL COMMENT 'วันที่ดำเนินการ', \`status\` text NULL COMMENT 'สถานะ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`profileChangePosition\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`reason\` text NULL COMMENT 'เหตุผลที่รับโอนราชการ', \`educationOld\` varchar(255) NULL COMMENT 'วุฒิ/สาขาเดิม', \`organizationPositionOld\` varchar(255) NULL COMMENT 'สังกัดเดิม ตำแหน่ง', \`organizationOld\` varchar(255) NULL COMMENT 'สังกัดเดิม', \`positionOld\` varchar(255) NULL COMMENT 'ตำแหน่งเดิม', \`positionTypeOld\` varchar(255) NULL COMMENT 'ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท', \`positionLevelOld\` varchar(255) NULL COMMENT 'ข้อมูลหน่วยงานเดิม ระดับ', \`positionNumberOld\` varchar(255) NULL COMMENT 'ข้อมูลหน่วยงานเดิม เลขที่', \`amountOld\` double NULL COMMENT 'ข้อมูลหน่วยงานเดิม เงินเดือน', \`dateCurrent\` datetime NULL COMMENT 'ดำรงตำแหน่งในระดับปัจจุบันเมื่อ', \`profileId\` varchar(255) NULL COMMENT 'profile Id', \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'นามสกุล', \`citizenId\` varchar(255) NULL COMMENT 'เลขบัตรประชาชน', \`birthDate\` datetime NULL COMMENT 'วันเกิด', \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน root', \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน root', \`rootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน root', \`child1\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1', \`child1Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child1', \`child1ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1', \`child2\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2', \`child2Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child2', \`child2ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2', \`child3\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3', \`child3Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child3', \`child3ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3', \`child4\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4', \`child4Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child4', \`child4ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4', \`node\` int NULL COMMENT 'ระดับโครงสร้าง', \`nodeId\` varchar(255) NULL COMMENT 'id โครงสร้าง', \`posmasterId\` varchar(255) NULL COMMENT 'id อัตรากำลัง', \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision', \`positionId\` varchar(255) NULL COMMENT 'id ตำแหน่ง', \`positionField\` varchar(255) NULL COMMENT 'สายงาน', \`posMasterNo\` int NULL COMMENT 'เลขที่ตำแหน่ง', \`position\` varchar(255) NULL COMMENT 'ชื่อตำแหน่งในสายงาน', \`posTypeId\` varchar(255) NULL COMMENT 'id ประเภทตำแหน่ง', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง', \`posLevelId\` varchar(255) NULL COMMENT 'id ระดับตำแหน่ง', \`posLevelName\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', \`rootOld\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน root old', \`rootOldId\` varchar(255) NULL COMMENT 'id หน่วยงาน root old', \`rootShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน root old', \`child1Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1 old', \`child1OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child1 old', \`child1ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1 old', \`child2Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2 old', \`child2OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child2 old', \`child2ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2 old', \`child3Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3 old', \`child3OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child3 old', \`child3ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3 old', \`child4Old\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4 old', \`child4OldId\` varchar(255) NULL COMMENT 'id หน่วยงาน child4 old', \`child4ShortNameOld\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4 old', \`posMasterNoOld\` int NULL COMMENT 'เลขที่ตำแหน่ง old', \`posTypeOldId\` varchar(255) NULL COMMENT 'id ประเภทตำแหน่ง old', \`posTypeNameOld\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง old', \`posLevelOldId\` varchar(255) NULL COMMENT 'id ระดับตำแหน่ง old', \`posLevelNameOld\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง old', \`status\` text NULL COMMENT 'สถานะ', \`changePositionId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ChangePosition', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`authSys\` (\`id\` varchar(255) NOT NULL COMMENT 'ไอดีหลักของตาราง', \`parentId\` varchar(255) NULL COMMENT 'Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null', \`icon\` varchar(100) NULL COMMENT 'ชื่อ icon', \`path\` varchar(255) NULL COMMENT 'path url ของระบบ', \`order\` int NOT NULL COMMENT 'ลำดับการแสดงผล' DEFAULT '0', \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`sysName\` varchar(255) NULL COMMENT 'ชื่อระบบ', \`sysDescription\` varchar(255) NULL COMMENT 'รายละเอียด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`isDirector\` tinyint NOT NULL COMMENT 'เป็นผู้อำนวยการ' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นเจ้าหน้าที่' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`isDirector\` tinyint NOT NULL COMMENT 'เป็นผู้อำนวยการ' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`isOfficer\` tinyint NOT NULL COMMENT 'เป็นเจ้าหน้าที่' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`authRoleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` ADD CONSTRAINT \`FK_229d969d15790aae298399f9303\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`authRoleAttr\` ADD CONSTRAINT \`FK_c50907c64fce7ed8f2fb68a3d50\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - 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 \`posMasterAct\` ADD CONSTRAINT \`FK_ef186d66137edc512471eaef51b\` FOREIGN KEY (\`posMasterId\`) REFERENCES \`posMaster\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` ADD CONSTRAINT \`FK_0f07f317c0771dadcdac1f71a6d\` FOREIGN KEY (\`posMasterChildId\`) REFERENCES \`posMaster\`(\`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`); - await queryRunner.query(`ALTER TABLE \`profileChangePosition\` ADD CONSTRAINT \`FK_91b13ee34e6af4bee74771d17e8\` FOREIGN KEY (\`changePositionId\`) REFERENCES \`changePosition\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`profileChangePosition\` DROP FOREIGN KEY \`FK_91b13ee34e6af4bee74771d17e8\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_a059796d095e79ba5b20407859f\``); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` DROP FOREIGN KEY \`FK_0f07f317c0771dadcdac1f71a6d\``); - await queryRunner.query(`ALTER TABLE \`posMasterAct\` DROP FOREIGN KEY \`FK_ef186d66137edc512471eaef51b\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP FOREIGN KEY \`FK_388ecc9f2a9f5b5ff1e08fd6d0e\``); - await queryRunner.query(`ALTER TABLE \`authRoleAttr\` DROP FOREIGN KEY \`FK_c50907c64fce7ed8f2fb68a3d50\``); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` DROP FOREIGN KEY \`FK_229d969d15790aae298399f9303\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`authRoleId\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`isOfficer\``); - await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`isDirector\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`authRoleId\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`isOfficer\``); - await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`isDirector\``); - await queryRunner.query(`ALTER TABLE \`profileEmployeeEmployment\` DROP COLUMN \`profileEmployeeId\``); - await queryRunner.query(`DROP TABLE \`authSys\``); - await queryRunner.query(`DROP TABLE \`profileChangePosition\``); - await queryRunner.query(`DROP TABLE \`changePosition\``); - await queryRunner.query(`DROP TABLE \`posMasterAct\``); - await queryRunner.query(`DROP TABLE \`authRole\``); - await queryRunner.query(`DROP TABLE \`authRoleAttr\``); - } - -}