แก้ api เก็บประวัติแก้ทะเบียน
This commit is contained in:
parent
576f6bcc0d
commit
fd3f1fa515
62 changed files with 855 additions and 1471 deletions
|
|
@ -152,15 +152,21 @@ export class ProfileAbilityController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileAbilityHistory();
|
||||
history.profileAbilityId = data.id;
|
||||
|
||||
await this.profileAbilityRepo.save(data);
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(data),
|
||||
(history.profileAbilityId = data.id),
|
||||
this.profileAbilityHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{abilityId}")
|
||||
public async editProfileAbility(
|
||||
@Body() requestBody: UpdateProfileAbility,
|
||||
@Body() body: UpdateProfileAbility,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
|
|
@ -170,12 +176,16 @@ export class ProfileAbilityController extends Controller {
|
|||
|
||||
const history = new ProfileAbilityHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileAbilityId = abilityId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -154,15 +154,21 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileAbilityHistory();
|
||||
history.profileAbilityId = data.id;
|
||||
|
||||
await this.profileAbilityRepo.save(data);
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(data),
|
||||
(history.profileAbilityId = data.id),
|
||||
this.profileAbilityHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{abilityId}")
|
||||
public async editProfileAbility(
|
||||
@Body() requestBody: UpdateProfileAbility,
|
||||
@Body() body: UpdateProfileAbility,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
|
|
@ -172,12 +178,16 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileAbilityHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileAbilityId = abilityId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -154,15 +154,21 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileAbilityHistory();
|
||||
history.profileAbilityId = data.id;
|
||||
|
||||
await this.profileAbilityRepo.save(data);
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(data),
|
||||
(history.profileAbilityId = data.id),
|
||||
this.profileAbilityHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{abilityId}")
|
||||
public async editProfileAbility(
|
||||
@Body() requestBody: UpdateProfileAbility,
|
||||
@Body() body: UpdateProfileAbility,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
|
|
@ -172,12 +178,16 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileAbilityHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileAbilityId = abilityId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ export class ProfileAddressController extends Controller {
|
|||
*/
|
||||
@Patch("{profileId}")
|
||||
public async editProfileAddress(
|
||||
@Body() requestBody: UpdateProfileAddress,
|
||||
@Body() body: UpdateProfileAddress,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
|
|
@ -188,12 +188,16 @@ export class ProfileAddressController extends Controller {
|
|||
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileId = profileId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ export class ProfileAddressEmployeeController extends Controller {
|
|||
*/
|
||||
@Patch("{profileId}")
|
||||
public async editProfileAddress(
|
||||
@Body() requestBody: UpdateProfileAddressEmployee,
|
||||
@Body() body: UpdateProfileAddressEmployee,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
|
|
@ -189,12 +189,16 @@ export class ProfileAddressEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEmployeeId = profileId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEmployeeRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ export class ProfileAddressEmployeeTempController extends Controller {
|
|||
*/
|
||||
@Patch("{profileId}")
|
||||
public async editProfileAddress(
|
||||
@Body() requestBody: UpdateProfileAddressEmployee,
|
||||
@Body() body: UpdateProfileAddressEmployee,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
|
|
@ -189,12 +189,16 @@ export class ProfileAddressEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEmployeeId = profileId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEmployeeRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -164,15 +164,21 @@ export class ProfileAssessmentsController extends Controller {
|
|||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileAssessmentHistory();
|
||||
history.profileAssessmentId = data.id;
|
||||
|
||||
await this.profileAssessmentsRepository.save(data);
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(data),
|
||||
(history.profileAssessmentId = data.id),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{assessmentId}")
|
||||
public async editProfileAssessment(
|
||||
@Body() requestBody: UpdateProfileAssessment,
|
||||
@Body() body: UpdateProfileAssessment,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
|
|
@ -182,17 +188,22 @@ export class ProfileAssessmentsController extends Controller {
|
|||
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileAssessmentId = assessmentId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,15 +166,21 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileAssessmentHistory();
|
||||
history.profileAssessmentId = data.id;
|
||||
|
||||
await this.profileAssessmentsRepository.save(data);
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(data),
|
||||
(history.profileAssessmentId = data.id),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{assessmentId}")
|
||||
public async editProfileAssessment(
|
||||
@Body() requestBody: UpdateProfileAssessment,
|
||||
@Body() body: UpdateProfileAssessment,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
|
|
@ -184,17 +190,22 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileAssessmentId = assessmentId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,15 +166,21 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileAssessmentHistory();
|
||||
history.profileAssessmentId = data.id;
|
||||
|
||||
await this.profileAssessmentsRepository.save(data);
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(data),
|
||||
(history.profileAssessmentId = data.id),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{assessmentId}")
|
||||
public async editProfileAssessment(
|
||||
@Body() requestBody: UpdateProfileAssessment,
|
||||
@Body() body: UpdateProfileAssessment,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
|
|
@ -184,17 +190,22 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileAssessmentId = assessmentId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,8 +142,14 @@ export class ProfileCertificateController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileCertificateHistory();
|
||||
history.profileCertificateId = data.id;
|
||||
|
||||
await this.certificateRepo.save(data);
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(data),
|
||||
(history.profileCertificateId = data.id),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -161,11 +167,16 @@ export class ProfileCertificateController extends Controller {
|
|||
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileCertificateId = certificateId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -142,8 +142,14 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileCertificateHistory();
|
||||
history.profileCertificateId = data.id;
|
||||
|
||||
await this.certificateRepo.save(data);
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(data),
|
||||
(history.profileCertificateId = data.id),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -161,11 +167,16 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileCertificateId = certificateId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -142,8 +142,14 @@ export class ProfileCertificateEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileCertificateHistory();
|
||||
history.profileCertificateId = data.id;
|
||||
|
||||
await this.certificateRepo.save(data);
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(data),
|
||||
(history.profileCertificateId = data.id),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -161,11 +167,16 @@ export class ProfileCertificateEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileCertificateId = certificateId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -140,15 +140,20 @@ export class ProfileChangeNameController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileChangeNameHistory();
|
||||
history.profileChangeNameId = data.id;
|
||||
|
||||
await this.changeNameRepository.save(data);
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(data),
|
||||
(history.profileChangeNameId = data.id),
|
||||
this.changeNameHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileRepository.save(profile);
|
||||
|
||||
// ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update //update 17/07
|
||||
if (profile != null && profile.keycloak != null) {
|
||||
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
|
||||
if (!result) {
|
||||
|
|
@ -172,11 +177,16 @@ export class ProfileChangeNameController extends Controller {
|
|||
|
||||
const history = new ProfileChangeNameHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileChangeNameId = changeNameId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from "../entities/ProfileChangeName";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { updateName } from "../keycloak";
|
||||
@Route("api/v1/org/profile-employee/changeName")
|
||||
@Tags("ProfileChangeNameEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -140,14 +141,27 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileChangeNameHistory();
|
||||
history.profileChangeNameId = data.id;
|
||||
|
||||
await this.changeNameRepository.save(data);
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(data),
|
||||
(history.profileChangeNameId = data.id),
|
||||
this.changeNameHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileEmployeeRepo.save(profile);
|
||||
|
||||
if (profile != null && profile.keycloak != null) {
|
||||
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
|
||||
if (!result) {
|
||||
throw new Error(result.errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
|
|
@ -164,11 +178,16 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileChangeNameHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileChangeNameId = changeNameId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from "../entities/ProfileChangeName";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { updateName } from "../keycloak";
|
||||
@Route("api/v1/org/profile-temp/changeName")
|
||||
@Tags("ProfileChangeNameEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -140,14 +141,27 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileChangeNameHistory();
|
||||
history.profileChangeNameId = data.id;
|
||||
|
||||
await this.changeNameRepository.save(data);
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(data),
|
||||
(history.profileChangeNameId = data.id),
|
||||
this.changeNameHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileEmployeeRepo.save(profile);
|
||||
|
||||
if (profile != null && profile.keycloak != null) {
|
||||
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
|
||||
if (!result) {
|
||||
throw new Error(result.errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
|
|
@ -164,11 +178,16 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileChangeNameHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileChangeNameId = changeNameId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -82,23 +82,16 @@ export class ProfileChildrenController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
|
||||
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);
|
||||
}
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
history.profileChildrenId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(data),
|
||||
(history.profileChildrenId = data.id),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -113,19 +106,17 @@ export class ProfileChildrenController extends Controller {
|
|||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
Object.assign(history, body);
|
||||
|
||||
record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId));
|
||||
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);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
|
|
|
|||
|
|
@ -88,23 +88,15 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
|
||||
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);
|
||||
}
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
history.profileChildrenId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(data),
|
||||
(history.profileChildrenId = data.id),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -120,19 +112,17 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
Object.assign(history, body);
|
||||
|
||||
record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId));
|
||||
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);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -88,23 +88,15 @@ export class ProfileChildrenEmployeeTempController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
|
||||
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);
|
||||
}
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
history.profileChildrenId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(data),
|
||||
(history.profileChildrenId = data.id),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -120,19 +112,17 @@ export class ProfileChildrenEmployeeTempController extends Controller {
|
|||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
Object.assign(history, body);
|
||||
|
||||
record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId));
|
||||
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);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -146,7 +146,14 @@ export class ProfileDisciplineController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.disciplineRepository.save(data);
|
||||
const history = new ProfileDisciplineHistory();
|
||||
history.profileDisciplineId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(data),
|
||||
(history.profileDisciplineId = data.id),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -164,11 +171,16 @@ export class ProfileDisciplineController extends Controller {
|
|||
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileDisciplineId = disciplineId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -137,7 +137,14 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.disciplineRepository.save(data);
|
||||
const history = new ProfileDisciplineHistory();
|
||||
history.profileDisciplineId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(data),
|
||||
(history.profileDisciplineId = data.id),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -155,11 +162,16 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileDisciplineId = disciplineId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -137,7 +137,14 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.disciplineRepository.save(data);
|
||||
const history = new ProfileDisciplineHistory();
|
||||
history.profileDisciplineId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(data),
|
||||
(history.profileDisciplineId = data.id),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -155,11 +162,16 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileDisciplineId = disciplineId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -149,8 +149,14 @@ export class ProfileDutyController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileDutyHistory();
|
||||
history.profileDutyId = data.id;
|
||||
|
||||
await this.dutyRepository.save(data);
|
||||
await Promise.all([
|
||||
this.dutyRepository.save(data),
|
||||
(history.profileDutyId = data.id),
|
||||
this.dutyHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -168,11 +174,16 @@ export class ProfileDutyController extends Controller {
|
|||
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileDutyId = dutyId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -110,8 +110,14 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileDutyHistory();
|
||||
history.profileDutyId = data.id;
|
||||
|
||||
await this.dutyRepository.save(data);
|
||||
await Promise.all([
|
||||
this.dutyRepository.save(data),
|
||||
(history.profileDutyId = data.id),
|
||||
this.dutyHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -129,11 +135,16 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileDutyId = dutyId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -110,8 +110,14 @@ export class ProfileDutyEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileDutyHistory();
|
||||
history.profileDutyId = data.id;
|
||||
|
||||
await this.dutyRepository.save(data);
|
||||
await Promise.all([
|
||||
this.dutyRepository.save(data),
|
||||
(history.profileDutyId = data.id),
|
||||
this.dutyHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -129,11 +135,16 @@ export class ProfileDutyEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileDutyId = dutyId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -201,14 +201,21 @@ export class ProfileEducationsController extends Controller {
|
|||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.profileEducationRepo.save(data);
|
||||
const history = new ProfileEducationHistory();
|
||||
history.profileEducationId = data.id;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(data),
|
||||
(history.profileEducationId = data.id),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{educationId}")
|
||||
public async editProfileEducation(
|
||||
@Body() requestBody: UpdateProfileEducation,
|
||||
@Body() body: UpdateProfileEducation,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
|
|
@ -218,12 +225,16 @@ export class ProfileEducationsController extends Controller {
|
|||
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEducationId = educationId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -202,15 +202,21 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileEducationHistory();
|
||||
history.profileEducationId = data.id;
|
||||
|
||||
await this.profileEducationRepo.save(data);
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(data),
|
||||
(history.profileEducationId = data.id),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{educationId}")
|
||||
public async editProfileEducation(
|
||||
@Body() requestBody: UpdateProfileEducation,
|
||||
@Body() body: UpdateProfileEducation,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
|
|
@ -220,12 +226,16 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEducationId = educationId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -202,15 +202,21 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileEducationHistory();
|
||||
history.profileEducationId = data.id;
|
||||
|
||||
await this.profileEducationRepo.save(data);
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(data),
|
||||
(history.profileEducationId = data.id),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{educationId}")
|
||||
public async editProfileEducation(
|
||||
@Body() requestBody: UpdateProfileEducation,
|
||||
@Body() body: UpdateProfileEducation,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
|
|
@ -220,12 +226,16 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEducationId = educationId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
|
|
|
|||
|
|
@ -234,30 +234,18 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
familyCouple.createdFullName = req.user.name;
|
||||
familyCouple.lastUpdateUserId = req.user.sub;
|
||||
familyCouple.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyCouple.save(familyCouple);
|
||||
|
||||
if (familyCouple) {
|
||||
profile.relationship = familyCouple.relationship; //update profile.relationship
|
||||
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
|
||||
profileFamilyCoupleId: familyCouple.id,
|
||||
couplePrefix: familyCouple.couplePrefix,
|
||||
coupleFirstName: familyCouple.coupleFirstName,
|
||||
coupleLastName: familyCouple.coupleLastName,
|
||||
coupleLastNameOld: familyCouple.coupleLastNameOld,
|
||||
coupleCareer: familyCouple.coupleCareer,
|
||||
coupleCitizenId: familyCouple.coupleCitizenId,
|
||||
coupleLive: familyCouple.coupleLive,
|
||||
relationship: familyCouple.relationship,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
}
|
||||
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
(history.profileFamilyCoupleId = familyCouple.id),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyCouple.id);
|
||||
}
|
||||
|
||||
|
|
@ -272,22 +260,17 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
Object.assign(familyCouple, body);
|
||||
(familyCouple.lastUpdateUserId = req.user.sub),
|
||||
(familyCouple.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
||||
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
(history.couplePrefix = familyCouple.couplePrefix),
|
||||
(history.coupleFirstName = familyCouple.coupleFirstName),
|
||||
(history.coupleLastName = familyCouple.coupleLastName),
|
||||
(history.coupleLastNameOld = familyCouple.coupleLastNameOld),
|
||||
(history.coupleCareer = familyCouple.coupleCareer),
|
||||
(history.coupleCitizenId = familyCouple.coupleCitizenId),
|
||||
(history.coupleLive = familyCouple.coupleLive),
|
||||
(history.relationship = familyCouple.relationship),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyCouple.lastUpdateUserId = req.user.sub;
|
||||
familyCouple.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
|
|
|
|||
|
|
@ -234,30 +234,18 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
familyCouple.createdFullName = req.user.name;
|
||||
familyCouple.lastUpdateUserId = req.user.sub;
|
||||
familyCouple.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyCouple.save(familyCouple);
|
||||
|
||||
if (familyCouple) {
|
||||
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
|
||||
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
|
||||
profileFamilyCoupleId: familyCouple.id,
|
||||
couplePrefix: familyCouple.couplePrefix,
|
||||
coupleFirstName: familyCouple.coupleFirstName,
|
||||
coupleLastName: familyCouple.coupleLastName,
|
||||
coupleLastNameOld: familyCouple.coupleLastNameOld,
|
||||
coupleCareer: familyCouple.coupleCareer,
|
||||
coupleCitizenId: familyCouple.coupleCitizenId,
|
||||
coupleLive: familyCouple.coupleLive,
|
||||
relationship: familyCouple.relationship,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
}
|
||||
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
(history.profileFamilyCoupleId = familyCouple.id),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyCouple.id);
|
||||
}
|
||||
|
||||
|
|
@ -274,22 +262,17 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
Object.assign(familyCouple, body);
|
||||
(familyCouple.lastUpdateUserId = req.user.sub),
|
||||
(familyCouple.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
||||
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
(history.couplePrefix = familyCouple.couplePrefix),
|
||||
(history.coupleFirstName = familyCouple.coupleFirstName),
|
||||
(history.coupleLastName = familyCouple.coupleLastName),
|
||||
(history.coupleLastNameOld = familyCouple.coupleLastNameOld),
|
||||
(history.coupleCareer = familyCouple.coupleCareer),
|
||||
(history.coupleCitizenId = familyCouple.coupleCitizenId),
|
||||
(history.coupleLive = familyCouple.coupleLive),
|
||||
(history.relationship = familyCouple.relationship),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyCouple.lastUpdateUserId = req.user.sub;
|
||||
familyCouple.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
|
|
|
|||
|
|
@ -236,28 +236,17 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
|
|||
familyCouple.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyCouple.save(familyCouple);
|
||||
|
||||
if (familyCouple) {
|
||||
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
|
||||
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
|
||||
profileFamilyCoupleId: familyCouple.id,
|
||||
couplePrefix: familyCouple.couplePrefix,
|
||||
coupleFirstName: familyCouple.coupleFirstName,
|
||||
coupleLastName: familyCouple.coupleLastName,
|
||||
coupleLastNameOld: familyCouple.coupleLastNameOld,
|
||||
coupleCareer: familyCouple.coupleCareer,
|
||||
coupleCitizenId: familyCouple.coupleCitizenId,
|
||||
coupleLive: familyCouple.coupleLive,
|
||||
relationship: familyCouple.relationship,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
}
|
||||
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
(history.profileFamilyCoupleId = familyCouple.id),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyCouple.id);
|
||||
}
|
||||
|
||||
|
|
@ -274,22 +263,17 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
|
|||
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
Object.assign(familyCouple, body);
|
||||
(familyCouple.lastUpdateUserId = req.user.sub),
|
||||
(familyCouple.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
||||
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
(history.couplePrefix = familyCouple.couplePrefix),
|
||||
(history.coupleFirstName = familyCouple.coupleFirstName),
|
||||
(history.coupleLastName = familyCouple.coupleLastName),
|
||||
(history.coupleLastNameOld = familyCouple.coupleLastNameOld),
|
||||
(history.coupleCareer = familyCouple.coupleCareer),
|
||||
(history.coupleCitizenId = familyCouple.coupleCitizenId),
|
||||
(history.coupleLive = familyCouple.coupleLive),
|
||||
(history.relationship = familyCouple.relationship),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyCouple.lastUpdateUserId = req.user.sub;
|
||||
familyCouple.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
|
|
|
|||
|
|
@ -220,24 +220,16 @@ export class ProfileFamilyFatherController extends Controller {
|
|||
familyFather.createdFullName = req.user.name;
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
familyFather.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyFather.save(familyFather);
|
||||
|
||||
if (familyFather) {
|
||||
const history: ProfileFamilyFatherHistory = Object.assign(new ProfileFamilyFatherHistory(), {
|
||||
profileFamilyFatherId: familyFather.id,
|
||||
fatherPrefix: familyFather.fatherPrefix,
|
||||
fatherFirstName: familyFather.fatherFirstName,
|
||||
fatherLastName: familyFather.fatherLastName,
|
||||
fatherCareer: familyFather.fatherCareer,
|
||||
fatherCitizenId: familyFather.fatherCitizenId,
|
||||
fatherLive: familyFather.fatherLive,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.ProfileFamilyFatherHistory.save(history);
|
||||
}
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
history.profileFamilyFatherId = familyFather.id;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
(history.profileFamilyFatherId = familyFather.id),
|
||||
this.ProfileFamilyFatherHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyFather.id);
|
||||
}
|
||||
|
||||
|
|
@ -252,20 +244,17 @@ export class ProfileFamilyFatherController extends Controller {
|
|||
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
Object.assign(familyFather, body);
|
||||
(familyFather.lastUpdateUserId = req.user.sub),
|
||||
(familyFather.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
history.profileFamilyFatherId = familyFather.id; //profileFamilyFatherId
|
||||
(history.fatherPrefix = familyFather.fatherPrefix),
|
||||
(history.fatherFirstName = familyFather.fatherFirstName),
|
||||
(history.fatherLastName = familyFather.fatherLastName),
|
||||
(history.fatherCareer = familyFather.fatherCareer),
|
||||
(history.fatherCitizenId = familyFather.fatherCitizenId),
|
||||
(history.fatherLive = familyFather.fatherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
familyFather.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
|
|
|
|||
|
|
@ -220,24 +220,16 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
familyFather.createdFullName = req.user.name;
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
familyFather.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyFather.save(familyFather);
|
||||
|
||||
if (familyFather) {
|
||||
const history: ProfileFamilyFatherHistory = Object.assign(new ProfileFamilyFatherHistory(), {
|
||||
profileFamilyFatherId: familyFather.id,
|
||||
fatherPrefix: familyFather.fatherPrefix,
|
||||
fatherFirstName: familyFather.fatherFirstName,
|
||||
fatherLastName: familyFather.fatherLastName,
|
||||
fatherCareer: familyFather.fatherCareer,
|
||||
fatherCitizenId: familyFather.fatherCitizenId,
|
||||
fatherLive: familyFather.fatherLive,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.ProfileFamilyFatherHistory.save(history);
|
||||
}
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
history.profileFamilyFatherId = familyFather.id;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
(history.profileFamilyFatherId = familyFather.id),
|
||||
this.ProfileFamilyFatherHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyFather.id);
|
||||
}
|
||||
|
||||
|
|
@ -254,20 +246,17 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
Object.assign(familyFather, body);
|
||||
(familyFather.lastUpdateUserId = req.user.sub),
|
||||
(familyFather.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
history.profileFamilyFatherId = familyFather.id;
|
||||
(history.fatherPrefix = familyFather.fatherPrefix),
|
||||
(history.fatherFirstName = familyFather.fatherFirstName),
|
||||
(history.fatherLastName = familyFather.fatherLastName),
|
||||
(history.fatherCareer = familyFather.fatherCareer),
|
||||
(history.fatherCitizenId = familyFather.fatherCitizenId),
|
||||
(history.fatherLive = familyFather.fatherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
familyFather.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
|
|
|
|||
|
|
@ -220,24 +220,16 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
|
|||
familyFather.createdFullName = req.user.name;
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
familyFather.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyFather.save(familyFather);
|
||||
|
||||
if (familyFather) {
|
||||
const history: ProfileFamilyFatherHistory = Object.assign(new ProfileFamilyFatherHistory(), {
|
||||
profileFamilyFatherId: familyFather.id,
|
||||
fatherPrefix: familyFather.fatherPrefix,
|
||||
fatherFirstName: familyFather.fatherFirstName,
|
||||
fatherLastName: familyFather.fatherLastName,
|
||||
fatherCareer: familyFather.fatherCareer,
|
||||
fatherCitizenId: familyFather.fatherCitizenId,
|
||||
fatherLive: familyFather.fatherLive,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.ProfileFamilyFatherHistory.save(history);
|
||||
}
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
history.profileFamilyFatherId = familyFather.id;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
(history.profileFamilyFatherId = familyFather.id),
|
||||
this.ProfileFamilyFatherHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyFather.id);
|
||||
}
|
||||
|
||||
|
|
@ -254,20 +246,17 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
|
|||
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
Object.assign(familyFather, body);
|
||||
(familyFather.lastUpdateUserId = req.user.sub),
|
||||
(familyFather.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
history.profileFamilyFatherId = familyFather.id;
|
||||
(history.fatherPrefix = familyFather.fatherPrefix),
|
||||
(history.fatherFirstName = familyFather.fatherFirstName),
|
||||
(history.fatherLastName = familyFather.fatherLastName),
|
||||
(history.fatherCareer = familyFather.fatherCareer),
|
||||
(history.fatherCitizenId = familyFather.fatherCitizenId),
|
||||
(history.fatherLive = familyFather.fatherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
familyFather.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
|
|
|
|||
|
|
@ -1,422 +0,0 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateChildren,
|
||||
CreateProfileFamily,
|
||||
ProfileFamilyHistory,
|
||||
UpdateProfileFamily,
|
||||
} from "../entities/ProfileFamily";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { ProfileChildren } from "../entities/ProfileChildren";
|
||||
import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
|
||||
@Route("api/v1/org/profile/family")
|
||||
@Tags("ProfileFamilyHistory")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileFamilyHistoryController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private familyHistoryRepo = AppDataSource.getRepository(ProfileFamilyHistory);
|
||||
private childrenRepo = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getFamilyHistoryUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileId: profile.id },
|
||||
});
|
||||
const children = await this.childrenRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(
|
||||
family.length > 0
|
||||
? {
|
||||
...family[0],
|
||||
children,
|
||||
}
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: {
|
||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
createdAt: "2024-03-19T11:00:29.769Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
coupleFirstName: "string",
|
||||
coupleLastName: "string",
|
||||
coupleLastNameOld: "string",
|
||||
coupleCareer: "string",
|
||||
coupleCitizenId: "string",
|
||||
coupleLive: true,
|
||||
fatherPrefix: "string",
|
||||
fatherFirstName: "string",
|
||||
fatherLastName: "string",
|
||||
fatherCareer: "string",
|
||||
fatherCitizenId: "string",
|
||||
fatherLive: true,
|
||||
motherPrefix: "string",
|
||||
motherFirstName: "string",
|
||||
motherLastName: "string",
|
||||
motherCareer: "string",
|
||||
motherCitizenId: "string",
|
||||
motherLive: true,
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
children: [
|
||||
{
|
||||
id: "9717f95a-cd20-4edb-a8b9-443c1dd99f90",
|
||||
createdAt: "2024-03-19T11:00:29.785Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.785Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
childrenCareer: "string",
|
||||
childrenFirstName: "string",
|
||||
childrenLastName: "string",
|
||||
childrenPrefix: "string",
|
||||
childrenLive: "string",
|
||||
childrenCitizenId: "string",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
public async getFamilyHistory(@Path() profileId: string) {
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileId },
|
||||
});
|
||||
const children = await this.childrenRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileId },
|
||||
});
|
||||
return new HttpSuccess(
|
||||
family.length > 0
|
||||
? {
|
||||
...family[0],
|
||||
children,
|
||||
}
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขครอบครัว by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async familyHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: {
|
||||
profileId: profile.id,
|
||||
},
|
||||
});
|
||||
|
||||
family.shift();
|
||||
|
||||
const record = await Promise.all(
|
||||
family.map(async (v) => ({
|
||||
...v,
|
||||
children: await this.childrenHistoryRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
createdAt: "2024-03-19T11:00:29.769Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
coupleFirstName: "string",
|
||||
coupleLastName: "string",
|
||||
coupleLastNameOld: "string",
|
||||
coupleCareer: "string",
|
||||
coupleCitizenId: "string",
|
||||
coupleLive: true,
|
||||
fatherPrefix: "string",
|
||||
fatherFirstName: "string",
|
||||
fatherLastName: "string",
|
||||
fatherCareer: "string",
|
||||
fatherCitizenId: "string",
|
||||
fatherLive: true,
|
||||
motherPrefix: "string",
|
||||
motherFirstName: "string",
|
||||
motherLastName: "string",
|
||||
motherCareer: "string",
|
||||
motherCitizenId: "string",
|
||||
motherLive: true,
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
children: [
|
||||
{
|
||||
id: "980835f8-d766-4b6b-b7dc-1726db889352",
|
||||
createdAt: "2024-03-19T12:42:11.437Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T12:42:11.437Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
childrenCareer: "hey",
|
||||
childrenFirstName: "hey",
|
||||
childrenLastName: "hey",
|
||||
childrenPrefix: "hey",
|
||||
childrenLive: "hey",
|
||||
childrenCitizenId: "hey",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
profileFamilyHistoryId: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
profileChildrenId: "222db098-3f08-4d0b-ac58-7914fa41032b",
|
||||
},
|
||||
{
|
||||
id: "cd539e67-3f34-4b8c-a9da-b7eb193fa0b4",
|
||||
createdAt: "2024-03-19T12:42:11.438Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T12:42:11.438Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
childrenCareer: "ay",
|
||||
childrenFirstName: "ay",
|
||||
childrenLastName: "ay",
|
||||
childrenPrefix: "ay",
|
||||
childrenLive: "ay",
|
||||
childrenCitizenId: "ay",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
profileFamilyHistoryId: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
profileChildrenId: "d0495491-9e9f-4d2e-bc3b-c2833955fa12",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "60bbf8d1-f674-4d88-b3fb-b5603e408319",
|
||||
createdAt: "2024-03-19T11:00:29.769Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
coupleFirstName: "string",
|
||||
coupleLastName: "string",
|
||||
coupleLastNameOld: "string",
|
||||
coupleCareer: "yeah",
|
||||
coupleCitizenId: "yeah",
|
||||
coupleLive: true,
|
||||
fatherPrefix: "yeah",
|
||||
fatherFirstName: "haaa",
|
||||
fatherLastName: "yeah",
|
||||
fatherCareer: "haaa",
|
||||
fatherCitizenId: "yeah",
|
||||
fatherLive: true,
|
||||
motherPrefix: "string",
|
||||
motherFirstName: "string",
|
||||
motherLastName: "string",
|
||||
motherCareer: "string",
|
||||
motherCitizenId: "string",
|
||||
motherLive: true,
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
})
|
||||
public async familyHistory(@Path() profileId: string) {
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileId },
|
||||
});
|
||||
|
||||
family.shift();
|
||||
|
||||
const record = await Promise.all(
|
||||
family.map(async (v) => ({
|
||||
...v,
|
||||
children: await this.childrenHistoryRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
// where: { profileFamilyHistoryId: v.id },
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newFamilyHistory(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileFamily,
|
||||
) {
|
||||
if (!body.profileId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const dataFamily = new ProfileFamilyHistory();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
const { children, ...family } = body;
|
||||
|
||||
Object.assign(dataFamily, { ...family, ...meta });
|
||||
|
||||
await this.familyHistoryRepo.save(dataFamily);
|
||||
|
||||
const profileId = dataFamily.profileId;
|
||||
|
||||
await Promise.all(
|
||||
children.map(async (v) => {
|
||||
const dataChildren = new ProfileChildrenHistory();
|
||||
|
||||
Object.assign(dataChildren, { ...v, profileId, ...meta });
|
||||
|
||||
await this.childrenRepo.save(dataChildren);
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{profileId}")
|
||||
public async editFamilyHistory(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileFamily,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
const familyRecord = (
|
||||
await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileId },
|
||||
})
|
||||
)[0];
|
||||
|
||||
if (!familyRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const childrenRecord = await this.childrenRepo.findBy({
|
||||
profileId: familyRecord.profileId,
|
||||
});
|
||||
|
||||
const historyData = new ProfileFamilyHistory();
|
||||
|
||||
const { children, ...family } = body;
|
||||
|
||||
Object.assign(historyData, { ...familyRecord, ...family, id: undefined });
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
|
||||
const newChild: CreateChildren[] = [];
|
||||
|
||||
for (let child of children) {
|
||||
newChild.push(
|
||||
Object.assign(new ProfileChildren(), {
|
||||
...child,
|
||||
profileId,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
id: !childrenRecord.find((v) => v.id === child.id) ? undefined : child.id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this.familyHistoryRepo.save({ ...historyData, lastUpdatedAt: undefined }),
|
||||
...newChild.map(async (v) => {
|
||||
return await this.childrenRepo.save(v);
|
||||
}),
|
||||
...childrenRecord.map(async (v) => {
|
||||
if (!children.find((x) => x.id === v.id)) {
|
||||
return await this.childrenRepo.delete({ id: v.id });
|
||||
}
|
||||
}),
|
||||
...childrenRecord.map(async (v) => {
|
||||
if (children.find((x) => x.id === v.id)) {
|
||||
return await this.childrenHistoryRepo.save(
|
||||
this.childrenHistoryRepo.create({
|
||||
...v,
|
||||
// profileFamilyHistoryId: familyRecord.id,
|
||||
profileChildrenId: v.id,
|
||||
id: undefined,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{profileId}")
|
||||
public async deleteFamilyHistory(@Path() profileId: string) {
|
||||
const result = await this.familyHistoryRepo.delete({ id: profileId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,422 +0,0 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateChildren,
|
||||
CreateProfileFamilyEmployee,
|
||||
ProfileFamilyHistory,
|
||||
UpdateProfileFamily,
|
||||
} from "../entities/ProfileFamily";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { ProfileChildren } from "../entities/ProfileChildren";
|
||||
import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
|
||||
@Route("api/v1/org/profile-employee/family")
|
||||
@Tags("ProfileFamilyHistoryEmployee")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileFamilyHistoryEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private familyHistoryRepo = AppDataSource.getRepository(ProfileFamilyHistory);
|
||||
private childrenRepo = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getFamilyHistoryUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
const children = await this.childrenRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(
|
||||
family.length > 0
|
||||
? {
|
||||
...family[0],
|
||||
children,
|
||||
}
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: {
|
||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
createdAt: "2024-03-19T11:00:29.769Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
coupleFirstName: "string",
|
||||
coupleLastName: "string",
|
||||
coupleLastNameOld: "string",
|
||||
coupleCareer: "string",
|
||||
coupleCitizenId: "string",
|
||||
coupleLive: true,
|
||||
fatherPrefix: "string",
|
||||
fatherFirstName: "string",
|
||||
fatherLastName: "string",
|
||||
fatherCareer: "string",
|
||||
fatherCitizenId: "string",
|
||||
fatherLive: true,
|
||||
motherPrefix: "string",
|
||||
motherFirstName: "string",
|
||||
motherLastName: "string",
|
||||
motherCareer: "string",
|
||||
motherCitizenId: "string",
|
||||
motherLive: true,
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
children: [
|
||||
{
|
||||
id: "9717f95a-cd20-4edb-a8b9-443c1dd99f90",
|
||||
createdAt: "2024-03-19T11:00:29.785Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.785Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
childrenCareer: "string",
|
||||
childrenFirstName: "string",
|
||||
childrenLastName: "string",
|
||||
childrenPrefix: "string",
|
||||
childrenLive: "string",
|
||||
childrenCitizenId: "string",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
public async getFamilyHistory(@Path() profileEmployeeId: string) {
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId },
|
||||
});
|
||||
const children = await this.childrenRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileEmployeeId },
|
||||
});
|
||||
return new HttpSuccess(
|
||||
family.length > 0
|
||||
? {
|
||||
...family[0],
|
||||
children,
|
||||
}
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขครอบครัว by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async familyHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: {
|
||||
profileEmployeeId: profile.id,
|
||||
},
|
||||
});
|
||||
|
||||
family.shift();
|
||||
|
||||
const record = await Promise.all(
|
||||
family.map(async (v) => ({
|
||||
...v,
|
||||
children: await this.childrenHistoryRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
createdAt: "2024-03-19T11:00:29.769Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
coupleFirstName: "string",
|
||||
coupleLastName: "string",
|
||||
coupleLastNameOld: "string",
|
||||
coupleCareer: "string",
|
||||
coupleCitizenId: "string",
|
||||
coupleLive: true,
|
||||
fatherPrefix: "string",
|
||||
fatherFirstName: "string",
|
||||
fatherLastName: "string",
|
||||
fatherCareer: "string",
|
||||
fatherCitizenId: "string",
|
||||
fatherLive: true,
|
||||
motherPrefix: "string",
|
||||
motherFirstName: "string",
|
||||
motherLastName: "string",
|
||||
motherCareer: "string",
|
||||
motherCitizenId: "string",
|
||||
motherLive: true,
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
children: [
|
||||
{
|
||||
id: "980835f8-d766-4b6b-b7dc-1726db889352",
|
||||
createdAt: "2024-03-19T12:42:11.437Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T12:42:11.437Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
childrenCareer: "hey",
|
||||
childrenFirstName: "hey",
|
||||
childrenLastName: "hey",
|
||||
childrenPrefix: "hey",
|
||||
childrenLive: "hey",
|
||||
childrenCitizenId: "hey",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
profileFamilyHistoryId: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
profileChildrenId: "222db098-3f08-4d0b-ac58-7914fa41032b",
|
||||
},
|
||||
{
|
||||
id: "cd539e67-3f34-4b8c-a9da-b7eb193fa0b4",
|
||||
createdAt: "2024-03-19T12:42:11.438Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T12:42:11.438Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
childrenCareer: "ay",
|
||||
childrenFirstName: "ay",
|
||||
childrenLastName: "ay",
|
||||
childrenPrefix: "ay",
|
||||
childrenLive: "ay",
|
||||
childrenCitizenId: "ay",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
profileFamilyHistoryId: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
profileChildrenId: "d0495491-9e9f-4d2e-bc3b-c2833955fa12",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "60bbf8d1-f674-4d88-b3fb-b5603e408319",
|
||||
createdAt: "2024-03-19T11:00:29.769Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
couple: true,
|
||||
couplePrefix: "string",
|
||||
coupleFirstName: "string",
|
||||
coupleLastName: "string",
|
||||
coupleLastNameOld: "string",
|
||||
coupleCareer: "yeah",
|
||||
coupleCitizenId: "yeah",
|
||||
coupleLive: true,
|
||||
fatherPrefix: "yeah",
|
||||
fatherFirstName: "haaa",
|
||||
fatherLastName: "yeah",
|
||||
fatherCareer: "haaa",
|
||||
fatherCitizenId: "yeah",
|
||||
fatherLive: true,
|
||||
motherPrefix: "string",
|
||||
motherFirstName: "string",
|
||||
motherLastName: "string",
|
||||
motherCareer: "string",
|
||||
motherCitizenId: "string",
|
||||
motherLive: true,
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
})
|
||||
public async familyHistory(@Path() profileEmployeeId: string) {
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId },
|
||||
});
|
||||
|
||||
family.shift();
|
||||
|
||||
const record = await Promise.all(
|
||||
family.map(async (v) => ({
|
||||
...v,
|
||||
children: await this.childrenHistoryRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
// where: { profileFamilyHistoryId: v.id },
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newFamilyHistory(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileFamilyEmployee,
|
||||
) {
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const dataFamily = new ProfileFamilyHistory();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
const { children, ...family } = body;
|
||||
|
||||
Object.assign(dataFamily, { ...family, ...meta });
|
||||
|
||||
await this.familyHistoryRepo.save(dataFamily);
|
||||
|
||||
const profileEmployeeId = dataFamily.profileEmployeeId;
|
||||
|
||||
await Promise.all(
|
||||
children.map(async (v) => {
|
||||
const dataChildren = new ProfileChildrenHistory();
|
||||
|
||||
Object.assign(dataChildren, { ...v, profileEmployeeId, ...meta });
|
||||
|
||||
await this.childrenRepo.save(dataChildren);
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{profileEmployeeId}")
|
||||
public async editFamilyHistory(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileFamily,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
const familyRecord = (
|
||||
await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId },
|
||||
})
|
||||
)[0];
|
||||
|
||||
if (!familyRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const childrenRecord = await this.childrenRepo.findBy({
|
||||
profileEmployeeId: familyRecord.profileEmployeeId,
|
||||
});
|
||||
|
||||
const historyData = new ProfileFamilyHistory();
|
||||
|
||||
const { children, ...family } = body;
|
||||
|
||||
Object.assign(historyData, { ...familyRecord, ...family, id: undefined });
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
|
||||
const newChild: CreateChildren[] = [];
|
||||
|
||||
for (let child of children) {
|
||||
newChild.push(
|
||||
Object.assign(new ProfileChildren(), {
|
||||
...child,
|
||||
profileEmployeeId,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
id: !childrenRecord.find((v) => v.id === child.id) ? undefined : child.id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this.familyHistoryRepo.save({ ...historyData, lastUpdatedAt: undefined }),
|
||||
...newChild.map(async (v) => {
|
||||
return await this.childrenRepo.save(v);
|
||||
}),
|
||||
...childrenRecord.map(async (v) => {
|
||||
if (!children.find((x) => x.id === v.id)) {
|
||||
return await this.childrenRepo.delete({ id: v.id });
|
||||
}
|
||||
}),
|
||||
...childrenRecord.map(async (v) => {
|
||||
if (children.find((x) => x.id === v.id)) {
|
||||
return await this.childrenHistoryRepo.save(
|
||||
this.childrenHistoryRepo.create({
|
||||
...v,
|
||||
// profileFamilyHistoryId: familyRecord.id,
|
||||
profileChildrenId: v.id,
|
||||
id: undefined,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{profileEmployeeId}")
|
||||
public async deleteFamilyHistory(@Path() profileEmployeeId: string) {
|
||||
const result = await this.familyHistoryRepo.delete({ id: profileEmployeeId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -220,24 +220,16 @@ export class ProfileFamilyMotherController extends Controller {
|
|||
familyMother.createdFullName = req.user.name;
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyMother.save(familyMother);
|
||||
|
||||
if (familyMother) {
|
||||
const history: ProfileFamilyMotherHistory = Object.assign(new ProfileFamilyMotherHistory(), {
|
||||
profileFamilyMotherId: familyMother.id,
|
||||
motherPrefix: familyMother.motherPrefix,
|
||||
motherFirstName: familyMother.motherFirstName,
|
||||
motherLastName: familyMother.motherLastName,
|
||||
motherCareer: familyMother.motherCareer,
|
||||
motherCitizenId: familyMother.motherCitizenId,
|
||||
motherLive: familyMother.motherLive,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.ProfileFamilyMotherHistory.save(history);
|
||||
}
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
(history.profileFamilyMotherId = familyMother.id),
|
||||
this.ProfileFamilyMotherHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyMother.id);
|
||||
}
|
||||
|
||||
|
|
@ -252,20 +244,17 @@ export class ProfileFamilyMotherController extends Controller {
|
|||
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
Object.assign(familyMother, body);
|
||||
(familyMother.lastUpdateUserId = req.user.sub),
|
||||
(familyMother.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
(history.motherPrefix = familyMother.motherPrefix),
|
||||
(history.motherFirstName = familyMother.motherFirstName),
|
||||
(history.motherLastName = familyMother.motherLastName),
|
||||
(history.motherCareer = familyMother.motherCareer),
|
||||
(history.motherCitizenId = familyMother.motherCitizenId),
|
||||
(history.motherLive = familyMother.motherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
|
|
|
|||
|
|
@ -220,24 +220,16 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
familyMother.createdFullName = req.user.name;
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyMother.save(familyMother);
|
||||
|
||||
if (familyMother) {
|
||||
const history: ProfileFamilyMotherHistory = Object.assign(new ProfileFamilyMotherHistory(), {
|
||||
profileFamilyMotherId: familyMother.id,
|
||||
motherPrefix: familyMother.motherPrefix,
|
||||
motherFirstName: familyMother.motherFirstName,
|
||||
motherLastName: familyMother.motherLastName,
|
||||
motherCareer: familyMother.motherCareer,
|
||||
motherCitizenId: familyMother.motherCitizenId,
|
||||
motherLive: familyMother.motherLive,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.ProfileFamilyMotherHistory.save(history);
|
||||
}
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
(history.profileFamilyMotherId = familyMother.id),
|
||||
this.ProfileFamilyMotherHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyMother.id);
|
||||
}
|
||||
|
||||
|
|
@ -254,20 +246,17 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
Object.assign(familyMother, body);
|
||||
(familyMother.lastUpdateUserId = req.user.sub),
|
||||
(familyMother.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
(history.motherPrefix = familyMother.motherPrefix),
|
||||
(history.motherFirstName = familyMother.motherFirstName),
|
||||
(history.motherLastName = familyMother.motherLastName),
|
||||
(history.motherCareer = familyMother.motherCareer),
|
||||
(history.motherCitizenId = familyMother.motherCitizenId),
|
||||
(history.motherLive = familyMother.motherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
|
|
|
|||
|
|
@ -220,24 +220,16 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
|
|||
familyMother.createdFullName = req.user.name;
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
await this.ProfileFamilyMother.save(familyMother);
|
||||
|
||||
if (familyMother) {
|
||||
const history: ProfileFamilyMotherHistory = Object.assign(new ProfileFamilyMotherHistory(), {
|
||||
profileFamilyMotherId: familyMother.id,
|
||||
motherPrefix: familyMother.motherPrefix,
|
||||
motherFirstName: familyMother.motherFirstName,
|
||||
motherLastName: familyMother.motherLastName,
|
||||
motherCareer: familyMother.motherCareer,
|
||||
motherCitizenId: familyMother.motherCitizenId,
|
||||
motherLive: familyMother.motherLive,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await this.ProfileFamilyMotherHistory.save(history);
|
||||
}
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
(history.profileFamilyMotherId = familyMother.id),
|
||||
this.ProfileFamilyMotherHistory.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess(familyMother.id);
|
||||
}
|
||||
|
||||
|
|
@ -254,20 +246,17 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
|
|||
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
Object.assign(familyMother, body);
|
||||
(familyMother.lastUpdateUserId = req.user.sub),
|
||||
(familyMother.lastUpdateFullName = req.user.name);
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
(history.motherPrefix = familyMother.motherPrefix),
|
||||
(history.motherFirstName = familyMother.motherFirstName),
|
||||
(history.motherLastName = familyMother.motherLastName),
|
||||
(history.motherCareer = familyMother.motherCareer),
|
||||
(history.motherCitizenId = familyMother.motherCitizenId),
|
||||
(history.motherLive = familyMother.motherLive),
|
||||
(history.lastUpdateUserId = req.user.sub),
|
||||
(history.lastUpdateFullName = req.user.name);
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
familyMother.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
|
|
|
|||
|
|
@ -254,34 +254,6 @@ 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");
|
||||
// }
|
||||
|
||||
// const profile = await this.profileRepo.findOneBy({ id: body.profileId });
|
||||
|
||||
// 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,
|
||||
// };
|
||||
|
||||
// Object.assign(data, { ...body, ...meta });
|
||||
|
||||
// await this.govRepo.save(data);
|
||||
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary แก้ไขข้อมูลราชการ
|
||||
|
|
@ -300,29 +272,21 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const historyData = new ProfileGovernment();
|
||||
const history = new ProfileGovernment();
|
||||
|
||||
Object.assign(historyData, { ...record, ...body, id: undefined });
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
historyData.profileId = profileId;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
Object.assign(history, body);
|
||||
|
||||
await Promise.all([this.profileRepo.save(record), this.govRepo.save(historyData)]);
|
||||
history.profileId = profileId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.profileRepo.save(record), this.govRepo.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
// @Delete("{profileId}")
|
||||
// public async deleteGov(@Path() profileId: string) {
|
||||
// const result = await this.govRepo.delete({ profileId: profileId });
|
||||
|
||||
// if (result.affected == undefined || result.affected <= 0) {
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,35 +248,6 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @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 });
|
||||
// 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,
|
||||
// };
|
||||
|
||||
// Object.assign(data, { ...body, ...meta });
|
||||
// await this.govRepo.save(data);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary แก้ไขข้อมูลราชการ
|
||||
|
|
@ -294,30 +265,20 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const historyData = new ProfileGovernment();
|
||||
const history = new ProfileGovernment();
|
||||
|
||||
Object.assign(historyData, { ...record, ...body, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEmployeeId = profileEmployeeId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
historyData.profileEmployeeId = profileEmployeeId;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(historyData)]);
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(history)]);
|
||||
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();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,35 +248,6 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
|
|||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @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 });
|
||||
// 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,
|
||||
// };
|
||||
|
||||
// Object.assign(data, { ...body, ...meta });
|
||||
// await this.govRepo.save(data);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary แก้ไขข้อมูลราชการ
|
||||
|
|
@ -294,30 +265,20 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const historyData = new ProfileGovernment();
|
||||
const history = new ProfileGovernment();
|
||||
|
||||
Object.assign(historyData, { ...record, ...body, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileEmployeeId = profileEmployeeId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
historyData.profileEmployeeId = profileEmployeeId;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(historyData)]);
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(history)]);
|
||||
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();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,8 +159,14 @@ export class ProfileHonorController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileHonorHistory();
|
||||
history.profileHonorId = data.id;
|
||||
|
||||
await this.honorRepo.save(data);
|
||||
await Promise.all([
|
||||
this.honorRepo.save(data),
|
||||
(history.profileHonorId = data.id),
|
||||
this.honorHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -178,11 +184,16 @@ export class ProfileHonorController extends Controller {
|
|||
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileHonorId = honorId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -163,8 +163,14 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileHonorHistory();
|
||||
history.profileHonorId = data.id;
|
||||
|
||||
await this.honorRepo.save(data);
|
||||
await Promise.all([
|
||||
this.honorRepo.save(data),
|
||||
(history.profileHonorId = data.id),
|
||||
this.honorHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -182,11 +188,16 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileHonorId = honorId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -163,8 +163,14 @@ export class ProfileHonorEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileHonorHistory();
|
||||
history.profileHonorId = data.id;
|
||||
|
||||
await this.honorRepo.save(data);
|
||||
await Promise.all([
|
||||
this.honorRepo.save(data),
|
||||
(history.profileHonorId = data.id),
|
||||
this.honorHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -182,11 +188,16 @@ export class ProfileHonorEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileHonorId = honorId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -194,8 +194,14 @@ export class ProfileInsigniaController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileInsigniaHistory();
|
||||
history.profileInsigniaId = data.id;
|
||||
|
||||
await this.insigniaRepo.save(data);
|
||||
await Promise.all([
|
||||
this.insigniaRepo.save(data),
|
||||
(history.profileInsigniaId = data.id),
|
||||
this.insigniaHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -220,11 +226,16 @@ export class ProfileInsigniaController extends Controller {
|
|||
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileInsigniaId = insigniaId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -197,8 +197,14 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileInsigniaHistory();
|
||||
history.profileInsigniaId = data.id;
|
||||
|
||||
await this.insigniaRepo.save(data);
|
||||
await Promise.all([
|
||||
this.insigniaRepo.save(data),
|
||||
(history.profileInsigniaId = data.id),
|
||||
this.insigniaHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -223,11 +229,16 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileInsigniaId = insigniaId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -197,8 +197,14 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileInsigniaHistory();
|
||||
history.profileInsigniaId = data.id;
|
||||
|
||||
await this.insigniaRepo.save(data);
|
||||
await Promise.all([
|
||||
this.insigniaRepo.save(data),
|
||||
(history.profileInsigniaId = data.id),
|
||||
this.insigniaHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -223,11 +229,16 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileInsigniaId = insigniaId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -274,8 +274,14 @@ export class ProfileLeaveController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileLeaveHistory();
|
||||
history.profileLeaveId = data.id;
|
||||
|
||||
await this.leaveRepo.save(data);
|
||||
await Promise.all([
|
||||
this.leaveRepo.save(data),
|
||||
(history.profileLeaveId = data.id),
|
||||
this.leaveHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -300,11 +306,16 @@ export class ProfileLeaveController extends Controller {
|
|||
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileLeaveId = leaveId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,14 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileLeaveHistory();
|
||||
history.profileLeaveId = data.id;
|
||||
|
||||
await this.leaveRepo.save(data);
|
||||
await Promise.all([
|
||||
this.leaveRepo.save(data),
|
||||
(history.profileLeaveId = data.id),
|
||||
this.leaveHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -121,11 +127,16 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileLeaveId = leaveId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,14 @@ export class ProfileLeaveEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileLeaveHistory();
|
||||
history.profileLeaveId = data.id;
|
||||
|
||||
await this.leaveRepo.save(data);
|
||||
await Promise.all([
|
||||
this.leaveRepo.save(data),
|
||||
(history.profileLeaveId = data.id),
|
||||
this.leaveHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -121,11 +127,16 @@ export class ProfileLeaveEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileLeaveId = leaveId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -117,8 +117,14 @@ export class ProfileNopaidController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileNopaidHistory();
|
||||
history.profileNopaidId = data.id;
|
||||
|
||||
await this.nopaidRepository.save(data);
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(data),
|
||||
(history.profileNopaidId = data.id),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -136,11 +142,16 @@ export class ProfileNopaidController extends Controller {
|
|||
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileNopaidId = nopaidId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -88,8 +88,14 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileNopaidHistory();
|
||||
history.profileNopaidId = data.id;
|
||||
|
||||
await this.nopaidRepository.save(data);
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(data),
|
||||
(history.profileNopaidId = data.id),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -107,11 +113,16 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileNopaidId = nopaidId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -88,8 +88,14 @@ export class ProfileNopaidEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileNopaidHistory();
|
||||
history.profileNopaidId = data.id;
|
||||
|
||||
await this.nopaidRepository.save(data);
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(data),
|
||||
(history.profileNopaidId = data.id),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -107,11 +113,16 @@ export class ProfileNopaidEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileNopaidId = nopaidId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -114,8 +114,14 @@ export class ProfileOtherController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileOtherHistory();
|
||||
history.profileOtherId = data.id;
|
||||
|
||||
await this.otherRepository.save(data);
|
||||
await Promise.all([
|
||||
this.otherRepository.save(data),
|
||||
(history.profileOtherId = data.id),
|
||||
this.otherHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -133,11 +139,16 @@ export class ProfileOtherController extends Controller {
|
|||
|
||||
const history = new ProfileOtherHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileOtherId = otherId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.otherRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -85,8 +85,14 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileOtherHistory();
|
||||
history.profileOtherId = data.id;
|
||||
|
||||
await this.otherRepository.save(data);
|
||||
await Promise.all([
|
||||
this.otherRepository.save(data),
|
||||
(history.profileOtherId = data.id),
|
||||
this.otherHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -104,11 +110,16 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileOtherHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileOtherId = otherId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.otherRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -85,8 +85,14 @@ export class ProfileOtherEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileOtherHistory();
|
||||
history.profileOtherId = data.id;
|
||||
|
||||
await this.otherRepository.save(data);
|
||||
await Promise.all([
|
||||
this.otherRepository.save(data),
|
||||
(history.profileOtherId = data.id),
|
||||
this.otherHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -104,11 +110,16 @@ export class ProfileOtherEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileOtherHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileOtherId = otherId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.otherRepository.save(record),
|
||||
|
|
|
|||
|
|
@ -167,8 +167,14 @@ export class ProfileSalaryController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileSalaryHistory();
|
||||
history.profileSalaryId = data.id;
|
||||
|
||||
await this.salaryRepo.save(data);
|
||||
await Promise.all([
|
||||
this.salaryRepo.save(data),
|
||||
(history.profileSalaryId = data.id),
|
||||
this.salaryHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -186,11 +192,16 @@ export class ProfileSalaryController extends Controller {
|
|||
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileSalaryId = salaryId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -96,8 +96,14 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileSalaryHistory();
|
||||
history.profileSalaryId = data.id;
|
||||
|
||||
await this.salaryRepo.save(data);
|
||||
await Promise.all([
|
||||
this.salaryRepo.save(data),
|
||||
(history.profileSalaryId = data.id),
|
||||
this.salaryHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -115,11 +121,16 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileSalaryId = salaryId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -96,8 +96,14 @@ export class ProfileSalaryEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileSalaryHistory();
|
||||
history.profileSalaryId = data.id;
|
||||
|
||||
await this.salaryRepo.save(data);
|
||||
await Promise.all([
|
||||
this.salaryRepo.save(data),
|
||||
(history.profileSalaryId = data.id),
|
||||
this.salaryHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -115,11 +121,16 @@ export class ProfileSalaryEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileSalaryId = salaryId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -160,8 +160,14 @@ export class ProfileTrainingController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileTrainingHistory();
|
||||
history.profileTrainingId = data.id;
|
||||
|
||||
await this.trainingRepo.save(data);
|
||||
await Promise.all([
|
||||
this.trainingRepo.save(data),
|
||||
(history.profileTrainingId = data.id),
|
||||
this.trainingHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -179,11 +185,16 @@ export class ProfileTrainingController extends Controller {
|
|||
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileTrainingId = trainingId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -163,8 +163,14 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileTrainingHistory();
|
||||
history.profileTrainingId = data.id;
|
||||
|
||||
await this.trainingRepo.save(data);
|
||||
await Promise.all([
|
||||
this.trainingRepo.save(data),
|
||||
(history.profileTrainingId = data.id),
|
||||
this.trainingHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -182,11 +188,16 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileTrainingId = trainingId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
|
|
@ -163,8 +163,14 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
const history = new ProfileTrainingHistory();
|
||||
history.profileTrainingId = data.id;
|
||||
|
||||
await this.trainingRepo.save(data);
|
||||
await Promise.all([
|
||||
this.trainingRepo.save(data),
|
||||
(history.profileTrainingId = data.id),
|
||||
this.trainingHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -182,11 +188,16 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
|
||||
history.profileTrainingId = trainingId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateUserId = req.user.sub;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
history.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue