ข้อมูลราชการ (ลูกจ้าง)
This commit is contained in:
parent
03ba1cda5e
commit
d2c8a3b741
1 changed files with 32 additions and 35 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Body, Controller, Example, Get, Patch, Path, Delete, Request, Route, Security, Tags } from "tsoa";
|
||||
import { Body, Controller, Example, Get, Patch, Path, Delete, Post, Request, Route, Security, Tags } from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
|
|
@ -96,7 +96,6 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท
|
||||
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ
|
||||
};
|
||||
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
|
|
@ -112,39 +111,37 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
});
|
||||
|
||||
// record.pop();
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
// @Post()
|
||||
// public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileGovernment) {
|
||||
// if (!body.profileEmployeeId) {
|
||||
// throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
// }
|
||||
/**
|
||||
*
|
||||
* @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 });
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
// 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,
|
||||
};
|
||||
|
||||
// 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();
|
||||
// }
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
await this.govRepo.save(data);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -162,7 +159,6 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const historyData = new ProfileGovernment();
|
||||
|
||||
Object.assign(historyData, { ...record, ...body, id: undefined });
|
||||
|
|
@ -172,20 +168,21 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
historyData.profileEmployeeId = profileEmployeeId;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(historyData)]);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue