แก้ api เก็บประวัติแก้ทะเบียน

This commit is contained in:
kittapath 2024-08-13 17:43:30 +07:00
parent 576f6bcc0d
commit fd3f1fa515
62 changed files with 855 additions and 1471 deletions

View file

@ -248,35 +248,6 @@ export class ProfileGovernmentEmployeeController extends Controller {
return new HttpSuccess(record);
}
// /**
// *
// * @summary เพิ่มข้อมูลราชการ
// *
// */
// @Post()
// public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeGovernment) {
// if (!body.profileEmployeeId) {
// throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
// }
// const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
// if (!profile) {
// throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
// }
// const data = new ProfileGovernment();
// const meta = {
// createdUserId: req.user.sub,
// createdFullName: req.user.name,
// lastUpdateUserId: req.user.sub,
// lastUpdateFullName: req.user.name,
// };
// Object.assign(data, { ...body, ...meta });
// await this.govRepo.save(data);
// return new HttpSuccess();
// }
/**
*
* @summary
@ -294,30 +265,20 @@ export class ProfileGovernmentEmployeeController extends Controller {
});
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const historyData = new ProfileGovernment();
const history = new ProfileGovernment();
Object.assign(historyData, { ...record, ...body, id: undefined });
Object.assign(record, body);
Object.assign(history, body);
history.profileEmployeeId = profileEmployeeId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdateFullName = req.user.name;
historyData.profileEmployeeId = profileEmployeeId;
historyData.lastUpdateFullName = req.user.name;
historyData.lastUpdateFullName = req.user.name;
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(historyData)]);
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(history)]);
return new HttpSuccess();
}
// /**
// *
// * @summary ลบข้อมูลราชการ
// *
// */
// @Delete("{profileEmployeeId}")
// public async deleteGov(@Path() profileEmployeeId: string) {
// const result = await this.govRepo.delete({ profileEmployeeId: profileEmployeeId });
// if (result.affected == undefined || result.affected <= 0) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// }
// return new HttpSuccess();
// }
}