sort edu by level

This commit is contained in:
kittapath 2025-01-06 23:58:24 +07:00
parent 4b05629c29
commit 587fe5d5b6
11 changed files with 229 additions and 266 deletions

View file

@ -42,7 +42,7 @@ export class ProfileEducationsEmployeeTempController 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 +59,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -129,22 +129,18 @@ export class ProfileEducationsEmployeeTempController extends Controller {
const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined });
const education = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: body.profileEmployeeId },
order: { level: "DESC" },
});
data.level = education == null ? 1 : education.level + 1;
await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
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();
}
@ -182,17 +178,6 @@ 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();
}
@ -214,8 +199,9 @@ export class ProfileEducationsEmployeeTempController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: _record?.profileEmployeeId },
order: { level: "ASC" },
});
const sortLevel = education.map((data, i) => ({
@ -234,7 +220,10 @@ export class ProfileEducationsEmployeeTempController extends Controller {
*
*/
@Put("sort/{profileId}")
async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) {
async Sort(
@Path() profileId: string,
@Body() requestBody: { data: { id: string; isUse: boolean }[] },
) {
const profile = await this.profileEmployeeRepo.findOne({
where: { id: profileId },
});
@ -243,13 +232,14 @@ export class ProfileEducationsEmployeeTempController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: profileId },
});
const sortLevel = education.map((data) => ({
id: data.id,
level: requestBody.id.indexOf(data.id) + 1,
level: requestBody.data.findIndex((x) => x.id == data.id) + 1,
isUse: requestBody.data.find((x) => x.id == data.id)?.isUse ?? false,
}));
await this.profileEducationRepo.save(sortLevel);