sort education profile
This commit is contained in:
parent
f1fb0665c7
commit
c7d7732fb6
6 changed files with 214 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,6 +169,14 @@ export class ProfileEducation extends EntityBase {
|
|||
})
|
||||
profileEmployeeId: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment:
|
||||
"ลำดับชั้นของเครื่องราช เอาไว้ตรวจสอบเวลาขอว่าต้องได้ชั้นที่สูงกว่าที่เคยได้รับแล้วเท่านั้น",
|
||||
default: null,
|
||||
})
|
||||
level: number;
|
||||
|
||||
@OneToMany(
|
||||
() => ProfileEducationHistory,
|
||||
(profileEducationHistory) => profileEducationHistory.histories,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableProfileEduAddLevel1736158197838 implements MigrationInterface {
|
||||
name = 'UpdateTableProfileEduAddLevel1736158197838'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profileEducation\` ADD \`level\` int NULL COMMENT 'ลำดับชั้นของเครื่องราช เอาไว้ตรวจสอบเวลาขอว่าต้องได้ชั้นที่สูงกว่าที่เคยได้รับแล้วเท่านั้น'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profileEducation\` DROP COLUMN \`level\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue