sort profile send report

This commit is contained in:
kittapath 2024-09-25 16:17:06 +07:00
parent e2939cae3a
commit 7697d6d46a
7 changed files with 169 additions and 14 deletions

View file

@ -79,7 +79,7 @@ export class ProfileSalaryController extends Controller {
}
@Get("history/{salaryId}")
public async salaryHistory(@Path() salaryId: string,) {
public async salaryHistory(@Path() salaryId: string) {
const record = await this.salaryHistoryRepo.find({
where: {
profileSalaryId: salaryId,
@ -170,12 +170,25 @@ export class ProfileSalaryController extends Controller {
_record.profileId,
);
}
const data = await this.salaryRepo.findOneBy({ id: salaryId });
if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (data == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profileId = data.profileId;
await this.salaryHistoryRepo.delete({
profileSalaryId: salaryId,
});
const result = await this.salaryRepo.delete({ id: salaryId });
const salaryList = await this.salaryRepo.find({
where: {
profileId: profileId,
},
});
salaryList.forEach(async (p, i) => {
p.order = i + 1;
await this.salaryRepo.save(p);
});
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}