ปรับ children
This commit is contained in:
parent
1a017dcd76
commit
4fa11d2aea
5 changed files with 75 additions and 29 deletions
|
|
@ -25,7 +25,7 @@ import {
|
|||
UpdateProfileChildren,
|
||||
} from "../entities/ProfileChildren";
|
||||
|
||||
@Route("api/v1/org/profile/children")
|
||||
@Route("api/v1/org/profile/family/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileChildrenController extends Controller {
|
||||
|
|
@ -59,7 +59,6 @@ export class ProfileChildrenController extends Controller {
|
|||
}
|
||||
|
||||
const data = new ProfileChildren();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
|
|
@ -68,9 +67,23 @@ export class ProfileChildrenController 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();
|
||||
}
|
||||
|
||||
|
|
@ -81,17 +94,22 @@ export class ProfileChildrenController 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([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
|
|
@ -108,7 +126,7 @@ export class ProfileChildrenController 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, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: {
|
||||
result: [{
|
||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
|
|
@ -45,7 +45,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
coupleLive: true,
|
||||
relationship: "string",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
},
|
||||
}],
|
||||
})
|
||||
public async getFamilyCouple(@Path() profileId: string) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
|
|
@ -55,7 +55,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const familyCouple = await this.ProfileFamilyCouple.findOne({
|
||||
const familyCouple = await this.ProfileFamilyCouple.find({
|
||||
select: [
|
||||
"id", "couple", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld",
|
||||
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId",
|
||||
|
|
|
|||
|
|
@ -74,11 +74,14 @@ export class ProfileChildren extends EntityBase {
|
|||
@JoinColumn({ name: "profileEmployeeId" })
|
||||
profileEmployee: ProfileEmployee;
|
||||
|
||||
@OneToMany(
|
||||
() => ProfileChildrenHistory,
|
||||
(profileChildrenHistory) => profileChildrenHistory.histories,
|
||||
)
|
||||
profileChildrenHistories: ProfileChildrenHistory[];
|
||||
// @OneToMany(
|
||||
// () => ProfileChildrenHistory,
|
||||
// (profileChildrenHistory) => profileChildrenHistory.histories,
|
||||
// )
|
||||
// profileChildrenHistories: ProfileChildrenHistory[];
|
||||
|
||||
@OneToMany(() => ProfileChildrenHistory, (v) => v.profileChildrenHistories)
|
||||
histories: ProfileChildrenHistory[];
|
||||
}
|
||||
|
||||
export type CreateProfileChildren = {
|
||||
|
|
@ -102,7 +105,7 @@ export type CreateProfileChildrenEmployee = {
|
|||
};
|
||||
|
||||
export type UpdateProfileChildren = {
|
||||
id: string;
|
||||
// id: string;
|
||||
childrenCareer?: string | null;
|
||||
childrenFirstName?: string | null;
|
||||
childrenLastName?: string | null;
|
||||
|
|
|
|||
|
|
@ -57,9 +57,13 @@ export class ProfileChildrenHistory extends EntityBase {
|
|||
})
|
||||
profileChildrenId: string;
|
||||
|
||||
@ManyToOne(() => ProfileChildren, (profileChildren) => profileChildren.profileChildrenHistories)
|
||||
// @ManyToOne(() => ProfileChildren, (profileChildren) => profileChildren.profileChildrenHistories)
|
||||
// @JoinColumn({ name: "profileChildrenId" })
|
||||
// histories: ProfileChildren;
|
||||
|
||||
@ManyToOne(() => ProfileChildren, (v) => v.histories)
|
||||
@JoinColumn({ name: "profileChildrenId" })
|
||||
histories: ProfileChildren;
|
||||
profileChildrenHistories: ProfileChildren;
|
||||
}
|
||||
|
||||
export type CreateChildren = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue