บันทึกข้อมูลราชการ
This commit is contained in:
parent
250897ac91
commit
474630a7ba
4 changed files with 159 additions and 220 deletions
|
|
@ -25,6 +25,7 @@ import {
|
|||
} from "../entities/ProfileGovernment";
|
||||
import { Position } from "../entities/Position";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { calculateAge, calculateRetireDate } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/org/profile/government")
|
||||
@Tags("ProfileGovernment")
|
||||
|
|
@ -40,7 +41,6 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
public async getGovHistory(@Path() profileId: string) {
|
||||
const record = await this.profileRepo.findOne({
|
||||
where: { id: profileId },
|
||||
order: { createdAt: "DESC" },
|
||||
relations: {
|
||||
posType: true,
|
||||
posLevel: true,
|
||||
|
|
@ -116,6 +116,12 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
: position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร
|
||||
positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา
|
||||
positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร
|
||||
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
|
||||
govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
|
||||
dateAppoint: record.dateAppoint,
|
||||
dateStart: record.dateStart,
|
||||
govAgeAbsent: record.govAgeAbsent,
|
||||
govAgePlus: record.govAgePlus,
|
||||
};
|
||||
|
||||
return new HttpSuccess(data);
|
||||
|
|
@ -134,33 +140,33 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileGovernment) {
|
||||
if (!body.profileId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
// @Post()
|
||||
// public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileGovernment) {
|
||||
// if (!body.profileId) {
|
||||
// throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
// }
|
||||
|
||||
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
|
||||
// const profile = await this.profileRepo.findOneBy({ id: body.profileId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
// if (!profile) {
|
||||
// throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
// }
|
||||
|
||||
const data = new ProfileGovernment();
|
||||
// const data = new ProfileGovernment();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
// const meta = {
|
||||
// createdUserId: req.user.sub,
|
||||
// createdFullName: req.user.name,
|
||||
// lastUpdateUserId: req.user.sub,
|
||||
// lastUpdateFullName: req.user.name,
|
||||
// };
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
// Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.govRepo.save(data);
|
||||
// await this.govRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
@Patch("{profileId}")
|
||||
public async editGov(
|
||||
|
|
@ -168,35 +174,34 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
@Body() body: UpdateProfileGovernment,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
const record = (
|
||||
await this.govRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileId },
|
||||
})
|
||||
)[0];
|
||||
const record = await this.profileRepo.findOne({
|
||||
where: { id: profileId },
|
||||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const historyData = new ProfileGovernment();
|
||||
|
||||
Object.assign(historyData, { ...record, ...body, id: undefined });
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
|
||||
await this.govRepo.save(historyData);
|
||||
await Promise.all([this.profileRepo.save(record)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{profileId}")
|
||||
public async deleteGov(@Path() profileId: string) {
|
||||
const result = await this.govRepo.delete({ profileId: profileId });
|
||||
// @Delete("{profileId}")
|
||||
// public async deleteGov(@Path() profileId: string) {
|
||||
// const result = await this.govRepo.delete({ profileId: profileId });
|
||||
|
||||
if (result.affected && result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
// if (result.affected && result.affected <= 0) {
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue