sort education profile

This commit is contained in:
kittapath 2025-01-06 17:19:14 +07:00
parent f1fb0665c7
commit c7d7732fb6
6 changed files with 214 additions and 5 deletions

View file

@ -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();
}
}