ปรับ children
This commit is contained in:
parent
1a017dcd76
commit
4fa11d2aea
5 changed files with 75 additions and 29 deletions
|
|
@ -27,7 +27,7 @@ import {
|
|||
} from "../entities/ProfileChildren";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
|
||||
@Route("api/v1/org/profile-employee/children")
|
||||
@Route("api/v1/org/profile-employee/family/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileChildrenEmployeeController extends Controller {
|
||||
|
|
@ -35,10 +35,10 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getChildren(@Path() profileId: string) {
|
||||
@Get("{profileEmployeeId}")
|
||||
public async getChildren(@Path() profileEmployeeId: string) {
|
||||
const lists = await this.childrenRepository.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
|
@ -73,8 +73,23 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.childrenRepository.save(data);
|
||||
if(data){
|
||||
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
|
||||
profileChildrenId: data.id,
|
||||
childrenCareer: data.childrenCareer,
|
||||
childrenFirstName: data.childrenFirstName,
|
||||
childrenLastName: data.childrenLastName,
|
||||
childrenPrefix: data.childrenPrefix,
|
||||
childrenLive: data.childrenLive,
|
||||
childrenCitizenId: data.childrenCitizenId,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.childrenHistoryRepository.save(history);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -86,15 +101,21 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
@Path() childrenId: string,
|
||||
) {
|
||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileChildrenId = childrenId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.profileChildrenId = record.id;
|
||||
history.childrenCareer = record.childrenCareer;
|
||||
history.childrenFirstName = record.childrenFirstName;
|
||||
history.childrenLastName = record.childrenLastName;
|
||||
history.childrenPrefix = record.childrenPrefix;
|
||||
history.childrenLive = record.childrenLive;
|
||||
history.childrenCitizenId = record.childrenCitizenId;
|
||||
history.lastUpdateUserId = req.user.sub,
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
|
|
@ -113,7 +134,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
|
||||
const result = await this.childrenRepository.delete({ id: childrenId });
|
||||
|
||||
if (result.affected && result.affected <= 0) {
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue