diff --git a/src/controllers/InsigniaController.ts b/src/controllers/InsigniaController.ts index aaa0c88d..48b8bd2f 100644 --- a/src/controllers/InsigniaController.ts +++ b/src/controllers/InsigniaController.ts @@ -287,9 +287,6 @@ export class InsigniaController extends Controller { select: ["id", "level"], where: { insigniaTypeId: insigniaTypeId }, }); - if (!insignia) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้"); - } const sortLevel = insignia.map((data) => ({ id: data.id, diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index a1618bb9..bf6ee4a9 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -10,6 +10,7 @@ import { Request, Get, Patch, + Put, } from "tsoa"; import HttpSuccess from "../interfaces/http-success"; @@ -138,6 +139,17 @@ export class ProfileEducationsController extends Controller { await this.profileEducationHistoryRepo.save(history, { data: req }); //setLogDataDiff(req, { before, after: history }); + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileId: body.profileId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + return new HttpSuccess(); } @@ -175,6 +187,17 @@ export class ProfileEducationsController extends Controller { // setLogDataDiff(req, { before: before_null, after: history }), ]); + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileId: record.profileId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + return new HttpSuccess(); } @@ -196,6 +219,46 @@ export class ProfileEducationsController extends Controller { if (result.affected == undefined || result.affected <= 0) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileId: record?.profileId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + + return new HttpSuccess(); + } + + /** + * API จัดลำดับแสดงประวัติการศึกษา + * + * @summary ORG_038 - จัดลำดับแสดงประวัติการศึกษา (ADMIN) # + * + */ + @Put("sort/{profileId}") + async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) { + const profile = await this.profileRepo.findOne({ + where: { id: profileId }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบ profile ดังกล่าว"); + } + + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileId: profileId }, + }); + + const sortLevel = education.map((data) => ({ + id: data.id, + level: requestBody.id.indexOf(data.id) + 1, + })); + + await this.profileEducationRepo.save(sortLevel); return new HttpSuccess(); } } diff --git a/src/controllers/ProfileEducationsEmployeeController.ts b/src/controllers/ProfileEducationsEmployeeController.ts index 5f3c8795..9019c87e 100644 --- a/src/controllers/ProfileEducationsEmployeeController.ts +++ b/src/controllers/ProfileEducationsEmployeeController.ts @@ -10,6 +10,7 @@ import { Request, Get, Patch, + Put, } from "tsoa"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; @@ -41,7 +42,7 @@ export class ProfileEducationsEmployeeController extends Controller { } const getProfileEducation = await this.profileEducationRepo.find({ where: { profileEmployeeId: profile.id }, - order: { createdAt: "ASC" }, + order: { level: "ASC" }, }); if (!getProfileEducation) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -59,7 +60,7 @@ export class ProfileEducationsEmployeeController extends Controller { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); const getProfileEducation = await this.profileEducationRepo.find({ where: { profileEmployeeId: profileEmployeeId }, - order: { createdAt: "ASC" }, + order: { level: "ASC" }, }); if (!getProfileEducation) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -144,6 +145,17 @@ export class ProfileEducationsEmployeeController extends Controller { await this.profileEducationHistoryRepo.save(history, { data: req }); //setLogDataDiff(req, { before, after: history }); + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: body.profileEmployeeId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + return new HttpSuccess(); } @@ -185,6 +197,17 @@ export class ProfileEducationsEmployeeController extends Controller { setLogDataDiff(req, { before, after: history }), ]); + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: record.profileEmployeeId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + return new HttpSuccess(); } @@ -212,6 +235,46 @@ export class ProfileEducationsEmployeeController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: _record?.profileEmployeeId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + + return new HttpSuccess(); + } + + /** + * API จัดลำดับแสดงประวัติการศึกษา + * + * @summary ORG_038 - จัดลำดับแสดงประวัติการศึกษา (ADMIN) # + * + */ + @Put("sort/{profileId}") + async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) { + const profile = await this.profileEmployeeRepo.findOne({ + where: { id: profileId }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบ profile ดังกล่าว"); + } + + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: profileId }, + }); + + const sortLevel = education.map((data) => ({ + id: data.id, + level: requestBody.id.indexOf(data.id) + 1, + })); + + await this.profileEducationRepo.save(sortLevel); return new HttpSuccess(); } } diff --git a/src/controllers/ProfileEducationsEmployeeTempController.ts b/src/controllers/ProfileEducationsEmployeeTempController.ts index 53519a39..7ccc663b 100644 --- a/src/controllers/ProfileEducationsEmployeeTempController.ts +++ b/src/controllers/ProfileEducationsEmployeeTempController.ts @@ -10,6 +10,7 @@ import { Request, Get, Patch, + Put, } from "tsoa"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; @@ -133,6 +134,17 @@ export class ProfileEducationsEmployeeTempController extends Controller { history.profileEducationId = data.id; await this.profileEducationHistoryRepo.save(history, { data: req }); //setLogDataDiff(req, { before, after: history }); + + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: body.profileEmployeeId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); return new HttpSuccess(); } @@ -170,6 +182,17 @@ export class ProfileEducationsEmployeeTempController extends Controller { // setLogDataDiff(req, { before: before_null, after: history }), ]); + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: record.profileEmployeeId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + return new HttpSuccess(); } @@ -178,6 +201,7 @@ export class ProfileEducationsEmployeeTempController extends Controller { @Path() educationId: string, @Request() req: RequestWithUser, ) { + const _record = await this.profileEducationRepo.findOneBy({ id: educationId }); await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); await this.profileEducationHistoryRepo.delete({ profileEducationId: educationId, @@ -189,6 +213,46 @@ export class ProfileEducationsEmployeeTempController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: _record?.profileEmployeeId }, + }); + + const sortLevel = education.map((data, i) => ({ + id: data.id, + level: i + 1, + })); + await this.profileEducationRepo.save(sortLevel); + + return new HttpSuccess(); + } + + /** + * API จัดลำดับแสดงประวัติการศึกษา + * + * @summary ORG_038 - จัดลำดับแสดงประวัติการศึกษา (ADMIN) # + * + */ + @Put("sort/{profileId}") + async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) { + const profile = await this.profileEmployeeRepo.findOne({ + where: { id: profileId }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบ profile ดังกล่าว"); + } + + const education = await this.profileEducationRepo.find({ + select: ["id", "level"], + where: { profileEmployeeId: profileId }, + }); + + const sortLevel = education.map((data) => ({ + id: data.id, + level: requestBody.id.indexOf(data.id) + 1, + })); + + await this.profileEducationRepo.save(sortLevel); return new HttpSuccess(); } } diff --git a/src/entities/ProfileEducation.ts b/src/entities/ProfileEducation.ts index cb8fb542..99e23c63 100644 --- a/src/entities/ProfileEducation.ts +++ b/src/entities/ProfileEducation.ts @@ -169,6 +169,14 @@ export class ProfileEducation extends EntityBase { }) profileEmployeeId: string; + @Column({ + nullable: true, + comment: + "ลำดับชั้นของเครื่องราช เอาไว้ตรวจสอบเวลาขอว่าต้องได้ชั้นที่สูงกว่าที่เคยได้รับแล้วเท่านั้น", + default: null, + }) + level: number; + @OneToMany( () => ProfileEducationHistory, (profileEducationHistory) => profileEducationHistory.histories, diff --git a/src/migration/1736158197838-update_table_profile_edu_add_level.ts b/src/migration/1736158197838-update_table_profile_edu_add_level.ts new file mode 100644 index 00000000..4825d210 --- /dev/null +++ b/src/migration/1736158197838-update_table_profile_edu_add_level.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfileEduAddLevel1736158197838 implements MigrationInterface { + name = 'UpdateTableProfileEduAddLevel1736158197838' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEducation\` ADD \`level\` int NULL COMMENT 'ลำดับชั้นของเครื่องราช เอาไว้ตรวจสอบเวลาขอว่าต้องได้ชั้นที่สูงกว่าที่เคยได้รับแล้วเท่านั้น'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEducation\` DROP COLUMN \`level\``); + } + +}