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

@ -139,23 +139,18 @@ export class ProfileEducationsEmployeeController 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();
}
@ -197,17 +192,6 @@ 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();
}
@ -236,8 +220,9 @@ export class ProfileEducationsEmployeeController 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) => ({
@ -256,7 +241,10 @@ export class ProfileEducationsEmployeeController 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 },
});
@ -265,13 +253,14 @@ export class ProfileEducationsEmployeeController 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);