ปรับ 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,
|
UpdateProfileChildren,
|
||||||
} from "../entities/ProfileChildren";
|
} from "../entities/ProfileChildren";
|
||||||
|
|
||||||
@Route("api/v1/org/profile/children")
|
@Route("api/v1/org/profile/family/children")
|
||||||
@Tags("ProfileChildren")
|
@Tags("ProfileChildren")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class ProfileChildrenController extends Controller {
|
export class ProfileChildrenController extends Controller {
|
||||||
|
|
@ -59,7 +59,6 @@ export class ProfileChildrenController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = new ProfileChildren();
|
const data = new ProfileChildren();
|
||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
createdUserId: req.user.sub,
|
createdUserId: req.user.sub,
|
||||||
createdFullName: req.user.name,
|
createdFullName: req.user.name,
|
||||||
|
|
@ -68,9 +67,23 @@ export class ProfileChildrenController extends Controller {
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(data, { ...body, ...meta });
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
|
||||||
await this.childrenRepository.save(data);
|
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();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,17 +94,22 @@ export class ProfileChildrenController extends Controller {
|
||||||
@Path() childrenId: string,
|
@Path() childrenId: string,
|
||||||
) {
|
) {
|
||||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||||
|
|
||||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const history = new ProfileChildrenHistory();
|
const history = new ProfileChildrenHistory();
|
||||||
|
|
||||||
Object.assign(history, { ...record, id: undefined });
|
Object.assign(history, { ...record, id: undefined });
|
||||||
Object.assign(record, body);
|
Object.assign(record, body);
|
||||||
history.profileChildrenId = childrenId;
|
record.lastUpdateUserId = req.user.sub;
|
||||||
record.lastUpdateFullName = req.user.name;
|
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;
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.childrenRepository.save(record),
|
this.childrenRepository.save(record),
|
||||||
this.childrenHistoryRepository.save(history),
|
this.childrenHistoryRepository.save(history),
|
||||||
|
|
@ -108,7 +126,7 @@ export class ProfileChildrenController extends Controller {
|
||||||
|
|
||||||
const result = await this.childrenRepository.delete({ id: childrenId });
|
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, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import {
|
||||||
} from "../entities/ProfileChildren";
|
} from "../entities/ProfileChildren";
|
||||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
|
||||||
@Route("api/v1/org/profile-employee/children")
|
@Route("api/v1/org/profile-employee/family/children")
|
||||||
@Tags("ProfileChildren")
|
@Tags("ProfileChildren")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class ProfileChildrenEmployeeController extends Controller {
|
export class ProfileChildrenEmployeeController extends Controller {
|
||||||
|
|
@ -35,10 +35,10 @@ export class ProfileChildrenEmployeeController extends Controller {
|
||||||
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
|
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
|
||||||
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
|
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||||
|
|
||||||
@Get("{profileId}")
|
@Get("{profileEmployeeId}")
|
||||||
public async getChildren(@Path() profileId: string) {
|
public async getChildren(@Path() profileEmployeeId: string) {
|
||||||
const lists = await this.childrenRepository.find({
|
const lists = await this.childrenRepository.find({
|
||||||
where: { profileEmployeeId: profileId },
|
where: { profileEmployeeId: profileEmployeeId },
|
||||||
});
|
});
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
@ -73,8 +73,23 @@ export class ProfileChildrenEmployeeController extends Controller {
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(data, { ...body, ...meta });
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
|
||||||
await this.childrenRepository.save(data);
|
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();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
@ -86,15 +101,21 @@ export class ProfileChildrenEmployeeController extends Controller {
|
||||||
@Path() childrenId: string,
|
@Path() childrenId: string,
|
||||||
) {
|
) {
|
||||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||||
|
|
||||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const history = new ProfileChildrenHistory();
|
const history = new ProfileChildrenHistory();
|
||||||
|
|
||||||
Object.assign(history, { ...record, id: undefined });
|
Object.assign(history, { ...record, id: undefined });
|
||||||
Object.assign(record, body);
|
Object.assign(record, body);
|
||||||
history.profileChildrenId = childrenId;
|
record.lastUpdateUserId = req.user.sub;
|
||||||
record.lastUpdateFullName = req.user.name;
|
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;
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
|
@ -113,7 +134,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
||||||
|
|
||||||
const result = await this.childrenRepository.delete({ id: childrenId });
|
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, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
||||||
@Example({
|
@Example({
|
||||||
status: 200,
|
status: 200,
|
||||||
message: "สำเร็จ",
|
message: "สำเร็จ",
|
||||||
result: {
|
result: [{
|
||||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||||
couple: true,
|
couple: true,
|
||||||
couplePrefix: "string",
|
couplePrefix: "string",
|
||||||
|
|
@ -45,7 +45,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
||||||
coupleLive: true,
|
coupleLive: true,
|
||||||
relationship: "string",
|
relationship: "string",
|
||||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
},
|
}],
|
||||||
})
|
})
|
||||||
public async getFamilyCouple(@Path() profileId: string) {
|
public async getFamilyCouple(@Path() profileId: string) {
|
||||||
const profile = await this.profileRepo.findOne({
|
const profile = await this.profileRepo.findOne({
|
||||||
|
|
@ -55,7 +55,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
}
|
}
|
||||||
const familyCouple = await this.ProfileFamilyCouple.findOne({
|
const familyCouple = await this.ProfileFamilyCouple.find({
|
||||||
select: [
|
select: [
|
||||||
"id", "couple", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld",
|
"id", "couple", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld",
|
||||||
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId",
|
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId",
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,14 @@ export class ProfileChildren extends EntityBase {
|
||||||
@JoinColumn({ name: "profileEmployeeId" })
|
@JoinColumn({ name: "profileEmployeeId" })
|
||||||
profileEmployee: ProfileEmployee;
|
profileEmployee: ProfileEmployee;
|
||||||
|
|
||||||
@OneToMany(
|
// @OneToMany(
|
||||||
() => ProfileChildrenHistory,
|
// () => ProfileChildrenHistory,
|
||||||
(profileChildrenHistory) => profileChildrenHistory.histories,
|
// (profileChildrenHistory) => profileChildrenHistory.histories,
|
||||||
)
|
// )
|
||||||
profileChildrenHistories: ProfileChildrenHistory[];
|
// profileChildrenHistories: ProfileChildrenHistory[];
|
||||||
|
|
||||||
|
@OneToMany(() => ProfileChildrenHistory, (v) => v.profileChildrenHistories)
|
||||||
|
histories: ProfileChildrenHistory[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CreateProfileChildren = {
|
export type CreateProfileChildren = {
|
||||||
|
|
@ -102,7 +105,7 @@ export type CreateProfileChildrenEmployee = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpdateProfileChildren = {
|
export type UpdateProfileChildren = {
|
||||||
id: string;
|
// id: string;
|
||||||
childrenCareer?: string | null;
|
childrenCareer?: string | null;
|
||||||
childrenFirstName?: string | null;
|
childrenFirstName?: string | null;
|
||||||
childrenLastName?: string | null;
|
childrenLastName?: string | null;
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,13 @@ export class ProfileChildrenHistory extends EntityBase {
|
||||||
})
|
})
|
||||||
profileChildrenId: string;
|
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" })
|
@JoinColumn({ name: "profileChildrenId" })
|
||||||
histories: ProfileChildren;
|
profileChildrenHistories: ProfileChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CreateChildren = {
|
export type CreateChildren = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue