diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 394a76f7..86601526 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -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(); + } }