sort profilesalary edit

This commit is contained in:
mamoss 2025-05-21 14:14:13 +07:00
parent 083a482b3a
commit 3f90f6cad9

View file

@ -5,6 +5,7 @@ import {
Patch,
Path,
Post,
Put,
Query,
Request,
Route,
@ -1460,4 +1461,51 @@ export class ProfileSalaryTempController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถดําเนินการได้");
}
}
/**
* API
*
* @summary API
*
*/
@Get("change/sort/{profileId}")
public async changeSortEdit(@Path() profileId: string) {
try {
let salaryOld = await this.salaryRepo.find({
where: { profileId: profileId },
order: { commandDateAffect: "ASC", order: "ASC" },
});
salaryOld.forEach((item: any, i) => {
item.order = i + 1;
});
await this.salaryRepo.save(salaryOld);
return new HttpSuccess();
} catch {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถดําเนินการได้");
}
}
/**
* API
*
* @summary API
*
*/
@Put("change/sort/{profileId}")
async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) {
const salary = await this.salaryRepo.find({
where: { profileId: profileId },
});
const sortLevel = salary.map((data) => ({
...data,
id: data.id,
order: requestBody.id.indexOf(data.id) + 1,
}));
await this.salaryRepo.save(sortLevel);
return new HttpSuccess();
}
}