Merge branch 'develop' into adiDev

# Conflicts:
#	src/controllers/ProfileController.ts
#	src/controllers/ProfileEmployeeController.ts
This commit is contained in:
AdisakKanthawilang 2024-05-24 11:09:26 +07:00
commit 63d357ea30
45 changed files with 1184 additions and 167 deletions

View file

@ -35,6 +35,8 @@ import { OrgChild4 } from "../entities/OrgChild4";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosType } from "../entities/EmployeePosType";
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
@Route("api/v1/org/pos") @Route("api/v1/org/pos")
@Tags("Position") @Tags("Position")
@Security("bearerAuth") @Security("bearerAuth")
@ -47,6 +49,8 @@ export class PositionController extends Controller {
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive); private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
private posTypeRepository = AppDataSource.getRepository(PosType); private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel); private posLevelRepository = AppDataSource.getRepository(PosLevel);
private posTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType);
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
private posDictRepository = AppDataSource.getRepository(PosDict); private posDictRepository = AppDataSource.getRepository(PosDict);
private posMasterRepository = AppDataSource.getRepository(PosMaster); private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position); private positionRepository = AppDataSource.getRepository(Position);
@ -2759,10 +2763,10 @@ export class PositionController extends Controller {
let typeCondition: any = {}; let typeCondition: any = {};
let conditionA: any = null; let conditionA: any = null;
let posType = await this.posTypeRepository.findOne({ let posType = await this.posTypeEmployeeRepository.findOne({
where: { id: String(body.posType) }, where: { id: String(body.posType) },
}); });
let posLevel = await this.posLevelRepository.findOne({ let posLevel = await this.posLevelEmployeeRepository.findOne({
where: { id: String(body.posLevel) }, where: { id: String(body.posLevel) },
}); });

View file

@ -33,6 +33,21 @@ export class ProfileAbilityController extends Controller {
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility); private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory); private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory);
@Get("user")
public async detailProfileAbilityUser(@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 getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileId: profile.id },
});
if (!getProfileAbilityId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAbilityId);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -35,6 +35,21 @@ export class ProfileAbilityEmployeeController extends Controller {
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility); private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory); private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory);
@Get("user")
public async detailProfileAbilityUser(@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 getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileEmployeeId: profile.id },
});
if (!getProfileAbilityId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAbilityId);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -34,6 +34,34 @@ export class ProfileAddressController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile); private profileRepo = AppDataSource.getRepository(Profile);
private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory); private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory);
@Get("user")
public async detailProfileAddressUser(@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 getProfileAddress = await this.profileRepo.findOne({
where: { id: profile.id },
select: [
"id",
"registrationAddress",
"registrationProvinceId",
"registrationDistrictId",
"registrationSubDistrictId",
"registrationZipCode",
"currentAddress",
"currentProvinceId",
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
],
});
if (!getProfileAddress) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAddress);
}
/** /**
* *
* @summary * @summary

View file

@ -35,6 +35,34 @@ export class ProfileAddressEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory); private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory);
@Get("user")
public async detailProfileAddressUser(@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 getProfileAddress = await this.profileEmployeeRepo.findOne({
where: { id: profile.id },
select: [
"id",
"registrationAddress",
"registrationProvinceId",
"registrationDistrictId",
"registrationSubDistrictId",
"registrationZipCode",
"currentAddress",
"currentProvinceId",
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
],
});
if (!getProfileAddress) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAddress);
}
/** /**
* *
* @summary * @summary

View file

@ -39,6 +39,21 @@ export class ProfileAssessmentsController extends Controller {
private profileAssessmentsHistoryRepository = private profileAssessmentsHistoryRepository =
AppDataSource.getRepository(ProfileAssessmentHistory); AppDataSource.getRepository(ProfileAssessmentHistory);
@Get("user")
public async detailProfileAssessmentsUser(@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 getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { profileId: profile.id },
});
if (!getProfileAssessments) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssessments);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -36,8 +36,22 @@ import { RequestWithUser } from "../middlewares/user";
export class ProfileAssessmentsEmployeeController extends Controller { export class ProfileAssessmentsEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment); private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
private profileAssessmentsHistoryRepository = private profileAssessmentsHistoryRepository = AppDataSource.getRepository(ProfileAssessmentHistory);
AppDataSource.getRepository(ProfileAssessmentHistory);
@Get("user")
public async detailProfileAssessmentsUser(@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 getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: profile.id },
});
if (!getProfileAssessments) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAssessments);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({

View file

@ -33,6 +33,18 @@ export class ProfileCertificateController extends Controller {
private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
@Get("user")
public async getCertificateUser(@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 record = await this.certificateRepo.find({
where: { profileId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileCertificateEmployeeController extends Controller {
private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
@Get("user")
public async getCertificateUser(@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 record = await this.certificateRepo.find({
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -33,6 +33,20 @@ export class ProfileChangeNameController extends Controller {
private changeNameRepository = AppDataSource.getRepository(ProfileChangeName); private changeNameRepository = AppDataSource.getRepository(ProfileChangeName);
private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory); private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory);
@Get("user")
public async getChangeNameUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.changeNameRepository.find({
where: { profileId: profile.id },
select: ["id", "prefix", "firstName", "lastName", "status"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,
@ -158,13 +172,13 @@ export class ProfileChangeNameController extends Controller {
]); ]);
const chkLastRecord = await this.changeNameRepository.findOne({ const chkLastRecord = await this.changeNameRepository.findOne({
where:{ where: {
profileId: record.profileId profileId: record.profileId,
}, },
order:{ order: {
createdAt: "DESC" createdAt: "DESC",
} },
}) });
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profile = await this.profileRepository.findOneBy({ id: record.profileId }); const profile = await this.profileRepository.findOneBy({ id: record.profileId });

View file

@ -35,6 +35,20 @@ export class ProfileChangeNameEmployeeController extends Controller {
private changeNameRepository = AppDataSource.getRepository(ProfileChangeName); private changeNameRepository = AppDataSource.getRepository(ProfileChangeName);
private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory); private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory);
@Get("user")
public async getChangeNameUser(@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 lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profile.id },
select: ["id", "prefix", "firstName", "lastName", "status"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileChildrenController extends Controller {
private childrenRepository = AppDataSource.getRepository(ProfileChildren); private childrenRepository = AppDataSource.getRepository(ProfileChildren);
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
@Get("user")
public async getChildrenUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.childrenRepository.find({
where: { profileId: profile.id },
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
public async getChildren(@Path() profileId: string) { public async getChildren(@Path() profileId: string) {
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
@ -69,7 +81,7 @@ export class ProfileChildrenController extends Controller {
Object.assign(data, { ...body, ...meta }); Object.assign(data, { ...body, ...meta });
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId)); data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
await this.childrenRepository.save(data); await this.childrenRepository.save(data);
if(data){ if (data) {
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), { const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
profileChildrenId: data.id, profileChildrenId: data.id,
childrenCareer: data.childrenCareer, childrenCareer: data.childrenCareer,
@ -107,11 +119,10 @@ export class ProfileChildrenController extends Controller {
history.childrenCareer = record.childrenCareer; history.childrenCareer = record.childrenCareer;
history.childrenFirstName = record.childrenFirstName; history.childrenFirstName = record.childrenFirstName;
history.childrenLastName = record.childrenLastName; history.childrenLastName = record.childrenLastName;
history.childrenPrefix = record.childrenPrefix; history.childrenPrefix = record.childrenPrefix;
history.childrenLive = record.childrenLive; history.childrenLive = record.childrenLive;
history.childrenCitizenId = record.childrenCitizenId; history.childrenCitizenId = record.childrenCitizenId;
history.lastUpdateUserId = req.user.sub, (history.lastUpdateUserId = req.user.sub), (history.lastUpdateFullName = req.user.name);
history.lastUpdateFullName = req.user.name;
await Promise.all([ await Promise.all([
this.childrenRepository.save(record), this.childrenRepository.save(record),
this.childrenHistoryRepository.save(history), this.childrenHistoryRepository.save(history),

View file

@ -35,6 +35,18 @@ export class ProfileChildrenEmployeeController extends Controller {
private childrenRepository = AppDataSource.getRepository(ProfileChildren); private childrenRepository = AppDataSource.getRepository(ProfileChildren);
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
@Get("user")
public async getChildrenUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(lists);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
public async getChildren(@Path() profileEmployeeId: string) { public async getChildren(@Path() profileEmployeeId: string) {
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({

View file

@ -43,6 +43,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Province } from "../entities/Province"; import { Province } from "../entities/Province";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict"; import { SubDistrict } from "../entities/SubDistrict";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile") @Route("api/v1/org/profile")
@Tags("Profile") @Tags("Profile")
@ -136,6 +137,16 @@ export class ProfileController extends Controller {
? null ? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
let _regisAddres =
profile && profile.registrationAddress != null ? profile.registrationAddress : "";
let _subDistrict =
subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "";
let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : "";
let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : "";
let registrationZipCode =
profile && profile.registrationZipCode != null
? ` รหัสไปรษณีย์ ${profile.registrationZipCode}`
: "";
let _root = root == null || root == undefined ? "" : `${root.orgRootName}`; let _root = root == null || root == undefined ? "" : `${root.orgRootName}`;
let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`; let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`; let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`;
@ -144,21 +155,34 @@ export class ProfileController extends Controller {
const mapData = { const mapData = {
Id: profile.id, Id: profile.id,
CitizenId: profile.citizenId, CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "",
Prefix: profile.prefix, Prefix: profile.prefix != null ? profile.prefix : "",
FirstName: profile.firstName, FirstName: profile.firstName != null ? profile.firstName : "",
LastName: profile.lastName, LastName: profile.lastName != null ? profile.lastName : "",
DateOfBirth: profile.birthDate, DateOfBirth:
DateRetire: profile.dateRetire, profile.birthDate != null
RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`, ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate))
SalaryAmount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null, : "",
DateRetire:
profile.dateRetire != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire))
: "",
RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
SalaryAmount:
profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null
? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString())
: "",
Education: Education:
profile.profileEducations.length > 0 profile.profileEducations.length > 0 &&
profile.profileEducations[profile.profileEducations.length - 1].institute != null
? profile.profileEducations[profile.profileEducations.length - 1].institute ? profile.profileEducations[profile.profileEducations.length - 1].institute
: null, : "",
AppointText: profile.dateAppoint, AppointText: profile.dateAppoint != null ? profile.dateAppoint : "",
SalaryDate: profile.profileSalary.length > 0 ? profile.profileSalary[0].date : null, SalaryDate:
PositionName: profile.position, profile.profileSalary.length > 0 && profile.profileSalary[0].date != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalary[0].date))
: "",
PositionName: profile.position != null ? profile.position : "",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
}; };
@ -524,6 +548,28 @@ export class ProfileController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
* @param {string} id Id
*/
@Get("user")
async getProfileByUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
},
where: { keycloak: request.user.sub },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(profile);
}
/** /**
* API * API
* *
@ -1061,6 +1107,8 @@ export class ProfileController extends Controller {
profileId: profile.id, profileId: profile.id,
prefix: profile.prefix, prefix: profile.prefix,
rank: profile.rank, rank: profile.rank,
avatar: profile.avatar,
avatarName: profile.avatarName,
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
citizenId: profile.citizenId, citizenId: profile.citizenId,

View file

@ -33,6 +33,29 @@ export class ProfileDisciplineController extends Controller {
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline); private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory);
@Get("user")
public async getDisciplineUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.disciplineRepository.find({
where: { profileId: profile.id },
select: [
"id",
"date",
"level",
"detail",
"unStigma",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
public async getDiscipline(@Path() profileId: string) { public async getDiscipline(@Path() profileId: string) {
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({

View file

@ -33,6 +33,29 @@ export class ProfileDisciplineEmployeeController extends Controller {
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline); private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory);
@Get("user")
public async getDisciplineUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profile.id },
select: [
"id",
"date",
"level",
"detail",
"unStigma",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -29,6 +29,27 @@ export class ProfileDutyController extends Controller {
private dutyRepository = AppDataSource.getRepository(ProfileDuty); private dutyRepository = AppDataSource.getRepository(ProfileDuty);
private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory); private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory);
@Get("user")
public async getDutyUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.dutyRepository.find({
where: { profileId: profile.id },
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
],
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -29,6 +29,27 @@ export class ProfileDutyEmployeeController extends Controller {
private dutyRepository = AppDataSource.getRepository(ProfileDuty); private dutyRepository = AppDataSource.getRepository(ProfileDuty);
private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory); private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory);
@Get("user")
public async getDutyUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.dutyRepository.find({
where: { profileEmployeeId: profile.id },
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
],
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
public async getDuty(@Path() profileId: string) { public async getDuty(@Path() profileId: string) {
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({

View file

@ -39,6 +39,21 @@ export class ProfileEducationsController extends Controller {
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation); private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory); private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory);
@Get("user")
public async detailProfileEducationUser(@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 getProfileEducation = await this.profileEducationRepo.find({
where: { profileId: profile.id },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileEducation);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -41,6 +41,21 @@ export class ProfileEducationsEmployeeController extends Controller {
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation); private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory); private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory);
@Get("user")
public async detailProfileEducationUser(@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 getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profile.id },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileEducation);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -35,6 +35,7 @@ import { Position } from "../entities/Position";
import { Province } from "../entities/Province"; import { Province } from "../entities/Province";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict"; import { SubDistrict } from "../entities/SubDistrict";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile-employee") @Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee") @Tags("ProfileEmployee")
@ -126,6 +127,16 @@ export class ProfileEmployeeController extends Controller {
? null ? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
let _regisAddres =
profile && profile.registrationAddress != null ? profile.registrationAddress : "";
let _subDistrict =
subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "";
let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : "";
let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : "";
let registrationZipCode =
profile && profile.registrationZipCode != null
? ` รหัสไปรษณีย์ ${profile.registrationZipCode}`
: "";
let _root = root == null || root == undefined ? "" : `${root.orgRootName}`; let _root = root == null || root == undefined ? "" : `${root.orgRootName}`;
let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`; let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`; let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`;
@ -134,21 +145,34 @@ export class ProfileEmployeeController extends Controller {
const mapData = { const mapData = {
Id: profile.id, Id: profile.id,
CitizenId: profile.citizenId, CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "",
Prefix: profile.prefix, Prefix: profile.prefix != null ? profile.prefix : "",
FirstName: profile.firstName, FirstName: profile.firstName != null ? profile.firstName : "",
LastName: profile.lastName, LastName: profile.lastName != null ? profile.lastName : "",
DateOfBirth: profile.birthDate, DateOfBirth:
DateRetire: profile.dateRetire, profile.birthDate != null
RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`, ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate))
SalaryAmount: profile.profileSalarys.length > 0 ? profile.profileSalarys[0].amount : null, : "",
DateRetire:
profile.dateRetire != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire))
: "",
RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
SalaryAmount:
profile.profileSalarys.length > 0 && profile.profileSalarys[0].amount != null
? Extension.ToThaiNumber(profile.profileSalarys[0].amount.toLocaleString())
: "",
Education: Education:
profile.profileEducations.length > 0 profile.profileEducations.length > 0 &&
profile.profileEducations[profile.profileEducations.length - 1].institute != null
? profile.profileEducations[profile.profileEducations.length - 1].institute ? profile.profileEducations[profile.profileEducations.length - 1].institute
: null, : "",
AppointText: profile.dateAppoint, AppointText: profile.dateAppoint != null ? profile.dateAppoint : "",
SalaryDate: profile.profileSalarys.length > 0 ? profile.profileSalarys[0].date : null, SalaryDate:
PositionName: profile.position, profile.profileSalarys.length > 0 && profile.profileSalarys[0].date != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalarys[0].date))
: "",
PositionName: profile.position != null ? profile.position : "",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
}; };
@ -343,6 +367,31 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
/**
* API
*
* @summary ORG_065 - (ADMIN) #70
*
* @param {string} id Id
*/
@Get("user")
async detailProfileUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
// gender: true,
// relationship: true,
// bloodGroup: true,
},
where: { keycloak: request.user.sub },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(profile);
}
/** /**
* API * API
* *

View file

@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { ProfileFamilyCouple, CreateProfileFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import {
ProfileFamilyCouple,
CreateProfileFamilyCouple,
UpdateProfileFamilyCouple,
} from "../entities/ProfileFamilyCouple";
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
@Route("api/v1/org/profile/family/couple") @Route("api/v1/org/profile/family/couple")
@ -29,6 +33,32 @@ export class ProfileFamilyCoupleController extends Controller {
private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple); private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple);
private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory); private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory);
@Get("user")
public async getFamilyCoupleUser(@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 familyCouple = await this.ProfileFamilyCouple.findOne({
select: [
"id",
"couplePrefix",
"coupleFirstName",
"coupleLastName",
"coupleLastNameOld",
"coupleCareer",
"coupleCitizenId",
"coupleLive",
"relationship",
"profileId",
],
where: { profileId: profile.id },
order: { lastUpdatedAt: "DESC" },
});
return new HttpSuccess(familyCouple);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,
@ -48,16 +78,24 @@ export class ProfileFamilyCoupleController extends Controller {
}) })
public async getFamilyCouple(@Path() profileId: string) { public async getFamilyCouple(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileId } where: { id: profileId },
}) });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const familyCouple = await this.ProfileFamilyCouple.findOne({ const familyCouple = await this.ProfileFamilyCouple.findOne({
select: [ select: [
"id", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld", "id",
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId", "couplePrefix",
"coupleFirstName",
"coupleLastName",
"coupleLastNameOld",
"coupleCareer",
"coupleCitizenId",
"coupleLive",
"relationship",
"profileId",
], ],
where: { profileId }, where: { profileId },
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
@ -89,13 +127,13 @@ export class ProfileFamilyCoupleController extends Controller {
relationship: "string", relationship: "string",
profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
} },
], ],
}) })
public async familyCoupleHistory(@Path() profileId: string) { public async familyCoupleHistory(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileId } where: { id: profileId },
}) });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
@ -103,28 +141,30 @@ export class ProfileFamilyCoupleController extends Controller {
const familyCouple = await this.ProfileFamilyCouple.find({ const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"], relations: ["histories"],
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
where: { profileId: profileId}, where: { profileId: profileId },
}); });
const mapData = familyCouple.flatMap((x) => x.histories).map((y) => ({ const mapData = familyCouple
id: y.id, .flatMap((x) => x.histories)
createdAt: y.createdAt, .map((y) => ({
createdUserId: y.createdUserId, id: y.id,
lastUpdatedAt: y.lastUpdatedAt, createdAt: y.createdAt,
lastUpdateUserId: y.lastUpdateUserId, createdUserId: y.createdUserId,
createdFullName: y.createdFullName, lastUpdatedAt: y.lastUpdatedAt,
lastUpdateFullName: y.lastUpdateFullName, lastUpdateUserId: y.lastUpdateUserId,
couplePrefix: y.couplePrefix, createdFullName: y.createdFullName,
coupleFirstName: y.coupleFirstName, lastUpdateFullName: y.lastUpdateFullName,
coupleLastName: y.coupleLastName, couplePrefix: y.couplePrefix,
coupleLastNameOld: y.coupleLastNameOld, coupleFirstName: y.coupleFirstName,
coupleCareer: y.coupleCareer, coupleLastName: y.coupleLastName,
coupleCitizenId: y.coupleCitizenId, coupleLastNameOld: y.coupleLastNameOld,
coupleLive: y.coupleLive, coupleCareer: y.coupleCareer,
relationship: y.relationship, coupleCitizenId: y.coupleCitizenId,
profileFamilyCoupleId: y.profileFamilyCoupleId, coupleLive: y.coupleLive,
profileId: profileId, relationship: y.relationship,
})); profileFamilyCoupleId: y.profileFamilyCoupleId,
profileId: profileId,
}));
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
@ -150,7 +190,7 @@ export class ProfileFamilyCoupleController extends Controller {
await this.ProfileFamilyCouple.save(familyCouple); await this.ProfileFamilyCouple.save(familyCouple);
if (familyCouple) { if (familyCouple) {
profile.relationship = familyCouple.relationship //update profile.relationship profile.relationship = familyCouple.relationship; //update profile.relationship
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), { const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
profileFamilyCoupleId: familyCouple.id, profileFamilyCoupleId: familyCouple.id,
couplePrefix: familyCouple.couplePrefix, couplePrefix: familyCouple.couplePrefix,
@ -168,7 +208,7 @@ export class ProfileFamilyCoupleController extends Controller {
}); });
await Promise.all([ await Promise.all([
this.profileRepo.save(profile), this.profileRepo.save(profile),
this.ProfileFamilyCoupleHistory.save(history) this.ProfileFamilyCoupleHistory.save(history),
]); ]);
} }
return new HttpSuccess(familyCouple.id); return new HttpSuccess(familyCouple.id);
@ -186,20 +226,20 @@ export class ProfileFamilyCoupleController extends Controller {
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
Object.assign(familyCouple, body); Object.assign(familyCouple, body);
familyCouple.lastUpdateUserId = req.user.sub, (familyCouple.lastUpdateUserId = req.user.sub),
familyCouple.lastUpdateFullName = req.user.name; (familyCouple.lastUpdateFullName = req.user.name);
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
history.profileFamilyCoupleId = familyCouple.id; history.profileFamilyCoupleId = familyCouple.id;
history.couplePrefix = familyCouple.couplePrefix, (history.couplePrefix = familyCouple.couplePrefix),
history.coupleFirstName = familyCouple.coupleFirstName, (history.coupleFirstName = familyCouple.coupleFirstName),
history.coupleLastName = familyCouple.coupleLastName, (history.coupleLastName = familyCouple.coupleLastName),
history.coupleLastNameOld = familyCouple.coupleLastNameOld, (history.coupleLastNameOld = familyCouple.coupleLastNameOld),
history.coupleCareer = familyCouple.coupleCareer, (history.coupleCareer = familyCouple.coupleCareer),
history.coupleCitizenId = familyCouple.coupleCitizenId, (history.coupleCitizenId = familyCouple.coupleCitizenId),
history.coupleLive = familyCouple.coupleLive, (history.coupleLive = familyCouple.coupleLive),
history.relationship = familyCouple.relationship, (history.relationship = familyCouple.relationship),
history.lastUpdateUserId = req.user.sub, (history.lastUpdateUserId = req.user.sub),
history.lastUpdateFullName = req.user.name; (history.lastUpdateFullName = req.user.name);
await Promise.all([ await Promise.all([
this.ProfileFamilyCouple.save(familyCouple), this.ProfileFamilyCouple.save(familyCouple),
@ -208,5 +248,4 @@ export class ProfileFamilyCoupleController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -29,6 +29,32 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple); private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple);
private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory); private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory);
@Get("user")
public async getFamilyCoupleUser(@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 familyCouple = await this.ProfileFamilyCouple.findOne({
select: [
"id",
"couplePrefix",
"coupleFirstName",
"coupleLastName",
"coupleLastNameOld",
"coupleCareer",
"coupleCitizenId",
"coupleLive",
"relationship",
"profileId",
],
where: { profileEmployeeId: profile.id },
order: { lastUpdatedAt: "DESC" },
});
return new HttpSuccess(familyCouple);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { ProfileFamilyFather, CreateProfileFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather"; import {
ProfileFamilyFather,
CreateProfileFamilyFather,
UpdateProfileFamilyFather,
} from "../entities/ProfileFamilyFather";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
@Route("api/v1/org/profile/family/father") @Route("api/v1/org/profile/family/father")
@ -29,6 +33,30 @@ export class ProfileFamilyFatherController extends Controller {
private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather); private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather);
private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory); private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory);
@Get("user")
public async getFamilyFatherUser(@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 familyFather = await this.ProfileFamilyFather.findOne({
select: [
"id",
"fatherPrefix",
"fatherFirstName",
"fatherLastName",
"fatherCareer",
"fatherCitizenId",
"fatherLive",
"profileId",
],
where: { profileId: profile.id },
order: { lastUpdatedAt: "DESC" },
});
return new HttpSuccess(familyFather);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,
@ -46,16 +74,22 @@ export class ProfileFamilyFatherController extends Controller {
}) })
public async getFamilyFather(@Path() profileId: string) { public async getFamilyFather(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileId } where: { id: profileId },
}) });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const familyFather = await this.ProfileFamilyFather.findOne({ const familyFather = await this.ProfileFamilyFather.findOne({
select: [ select: [
"id", "fatherPrefix", "fatherFirstName", "fatherLastName", "id",
"fatherCareer", "fatherCitizenId", "fatherLive", "profileId", "fatherPrefix",
"fatherFirstName",
"fatherLastName",
"fatherCareer",
"fatherCitizenId",
"fatherLive",
"profileId",
], ],
where: { profileId }, where: { profileId },
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
@ -85,13 +119,13 @@ export class ProfileFamilyFatherController extends Controller {
fatherLive: true, fatherLive: true,
profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
} },
], ],
}) })
public async familyFatherHistory(@Path() profileId: string) { public async familyFatherHistory(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileId } where: { id: profileId },
}) });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
@ -99,26 +133,28 @@ export class ProfileFamilyFatherController extends Controller {
const familyFather = await this.ProfileFamilyFather.find({ const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"], relations: ["histories"],
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
where: { profileId: profileId}, where: { profileId: profileId },
}); });
const mapData = familyFather.flatMap((x) => x.histories).map((y) => ({ const mapData = familyFather
id: y.id, .flatMap((x) => x.histories)
createdAt: y.createdAt, .map((y) => ({
createdUserId: y.createdUserId, id: y.id,
lastUpdatedAt: y.lastUpdatedAt, createdAt: y.createdAt,
lastUpdateUserId: y.lastUpdateUserId, createdUserId: y.createdUserId,
createdFullName: y.createdFullName, lastUpdatedAt: y.lastUpdatedAt,
lastUpdateFullName: y.lastUpdateFullName, lastUpdateUserId: y.lastUpdateUserId,
fatherPrefix: y.fatherPrefix, createdFullName: y.createdFullName,
fatherFirstName: y.fatherFirstName, lastUpdateFullName: y.lastUpdateFullName,
fatherLastName: y.fatherLastName, fatherPrefix: y.fatherPrefix,
fatherCareer: y.fatherCareer, fatherFirstName: y.fatherFirstName,
fatherCitizenId: y.fatherCitizenId, fatherLastName: y.fatherLastName,
fatherLive: y.fatherLive, fatherCareer: y.fatherCareer,
profileFamilyFatherId: y.profileFamilyFatherId, fatherCitizenId: y.fatherCitizenId,
profileId: profileId, fatherLive: y.fatherLive,
})); profileFamilyFatherId: y.profileFamilyFatherId,
profileId: profileId,
}));
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
@ -174,18 +210,18 @@ export class ProfileFamilyFatherController extends Controller {
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
Object.assign(familyFather, body); Object.assign(familyFather, body);
familyFather.lastUpdateUserId = req.user.sub, (familyFather.lastUpdateUserId = req.user.sub),
familyFather.lastUpdateFullName = req.user.name; (familyFather.lastUpdateFullName = req.user.name);
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
history.profileFamilyFatherId = familyFather.id; //profileFamilyFatherId history.profileFamilyFatherId = familyFather.id; //profileFamilyFatherId
history.fatherPrefix = familyFather.fatherPrefix, (history.fatherPrefix = familyFather.fatherPrefix),
history.fatherFirstName = familyFather.fatherFirstName, (history.fatherFirstName = familyFather.fatherFirstName),
history.fatherLastName = familyFather.fatherLastName, (history.fatherLastName = familyFather.fatherLastName),
history.fatherCareer = familyFather.fatherCareer, (history.fatherCareer = familyFather.fatherCareer),
history.fatherCitizenId = familyFather.fatherCitizenId, (history.fatherCitizenId = familyFather.fatherCitizenId),
history.fatherLive = familyFather.fatherLive, (history.fatherLive = familyFather.fatherLive),
history.lastUpdateUserId = req.user.sub, (history.lastUpdateUserId = req.user.sub),
history.lastUpdateFullName = req.user.name; (history.lastUpdateFullName = req.user.name);
await Promise.all([ await Promise.all([
this.ProfileFamilyFather.save(familyFather), this.ProfileFamilyFather.save(familyFather),

View file

@ -29,6 +29,30 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather); private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather);
private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory); private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory);
@Get("user")
public async getFamilyFatherUser(@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 familyFather = await this.ProfileFamilyFather.findOne({
select: [
"id",
"fatherPrefix",
"fatherFirstName",
"fatherLastName",
"fatherCareer",
"fatherCitizenId",
"fatherLive",
"profileId",
],
where: { profileEmployeeId: profile.id },
order: { lastUpdatedAt: "DESC" },
});
return new HttpSuccess(familyFather);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -36,6 +36,31 @@ export class ProfileFamilyHistoryController extends Controller {
private childrenRepo = AppDataSource.getRepository(ProfileChildren); private childrenRepo = AppDataSource.getRepository(ProfileChildren);
private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory); 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}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -36,6 +36,31 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
private childrenRepo = AppDataSource.getRepository(ProfileChildren); private childrenRepo = AppDataSource.getRepository(ProfileChildren);
private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory); 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}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { ProfileFamilyMother, CreateProfileFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother"; import {
ProfileFamilyMother,
CreateProfileFamilyMother,
UpdateProfileFamilyMother,
} from "../entities/ProfileFamilyMother";
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
@Route("api/v1/org/profile/family/mother") @Route("api/v1/org/profile/family/mother")
@ -29,6 +33,30 @@ export class ProfileFamilyMotherController extends Controller {
private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother); private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother);
private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory); private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory);
@Get("user")
public async getFamilyMotherUser(@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 familyMother = await this.ProfileFamilyMother.findOne({
select: [
"id",
"motherPrefix",
"motherFirstName",
"motherLastName",
"motherCareer",
"motherCitizenId",
"motherLive",
"profileId",
],
where: { profileId: profile.id },
order: { lastUpdatedAt: "DESC" },
});
return new HttpSuccess(familyMother);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,
@ -46,16 +74,22 @@ export class ProfileFamilyMotherController extends Controller {
}) })
public async getFamilyMother(@Path() profileId: string) { public async getFamilyMother(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileId } where: { id: profileId },
}) });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const familyMother = await this.ProfileFamilyMother.findOne({ const familyMother = await this.ProfileFamilyMother.findOne({
select: [ select: [
"id", "motherPrefix", "motherFirstName", "motherLastName", "id",
"motherCareer", "motherCitizenId", "motherLive", "profileId", "motherPrefix",
"motherFirstName",
"motherLastName",
"motherCareer",
"motherCitizenId",
"motherLive",
"profileId",
], ],
where: { profileId }, where: { profileId },
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
@ -85,13 +119,13 @@ export class ProfileFamilyMotherController extends Controller {
motherLive: true, motherLive: true,
profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
} },
], ],
}) })
public async familyMotherHistory(@Path() profileId: string) { public async familyMotherHistory(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileId } where: { id: profileId },
}) });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
@ -99,26 +133,28 @@ export class ProfileFamilyMotherController extends Controller {
const familyMother = await this.ProfileFamilyMother.find({ const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"], relations: ["histories"],
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
where: { profileId: profileId}, where: { profileId: profileId },
}); });
const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({ const mapData = familyMother
id: y.id, .flatMap((x) => x.histories)
createdAt: y.createdAt, .map((y) => ({
createdUserId: y.createdUserId, id: y.id,
lastUpdatedAt: y.lastUpdatedAt, createdAt: y.createdAt,
lastUpdateUserId: y.lastUpdateUserId, createdUserId: y.createdUserId,
createdFullName: y.createdFullName, lastUpdatedAt: y.lastUpdatedAt,
lastUpdateFullName: y.lastUpdateFullName, lastUpdateUserId: y.lastUpdateUserId,
motherPrefix: y.motherPrefix, createdFullName: y.createdFullName,
motherFirstName: y.motherFirstName, lastUpdateFullName: y.lastUpdateFullName,
motherLastName: y.motherLastName, motherPrefix: y.motherPrefix,
motherCareer: y.motherCareer, motherFirstName: y.motherFirstName,
motherCitizenId: y.motherCitizenId, motherLastName: y.motherLastName,
motherLive: y.motherLive, motherCareer: y.motherCareer,
profileFamilyMotherId: y.profileFamilyMotherId, motherCitizenId: y.motherCitizenId,
profileId: profileId, motherLive: y.motherLive,
})); profileFamilyMotherId: y.profileFamilyMotherId,
profileId: profileId,
}));
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
@ -174,18 +210,18 @@ export class ProfileFamilyMotherController extends Controller {
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
Object.assign(familyMother, body); Object.assign(familyMother, body);
familyMother.lastUpdateUserId = req.user.sub, (familyMother.lastUpdateUserId = req.user.sub),
familyMother.lastUpdateFullName = req.user.name; (familyMother.lastUpdateFullName = req.user.name);
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
history.profileFamilyMotherId = familyMother.id; history.profileFamilyMotherId = familyMother.id;
history.motherPrefix = familyMother.motherPrefix, (history.motherPrefix = familyMother.motherPrefix),
history.motherFirstName = familyMother.motherFirstName, (history.motherFirstName = familyMother.motherFirstName),
history.motherLastName = familyMother.motherLastName, (history.motherLastName = familyMother.motherLastName),
history.motherCareer = familyMother.motherCareer, (history.motherCareer = familyMother.motherCareer),
history.motherCitizenId = familyMother.motherCitizenId, (history.motherCitizenId = familyMother.motherCitizenId),
history.motherLive = familyMother.motherLive, (history.motherLive = familyMother.motherLive),
history.lastUpdateUserId = req.user.sub, (history.lastUpdateUserId = req.user.sub),
history.lastUpdateFullName = req.user.name; (history.lastUpdateFullName = req.user.name);
await Promise.all([ await Promise.all([
this.ProfileFamilyMother.save(familyMother), this.ProfileFamilyMother.save(familyMother),
@ -194,5 +230,4 @@ export class ProfileFamilyMotherController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -29,6 +29,30 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother); private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother);
private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory); private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory);
@Get("user")
public async getFamilyMotherUser(@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 familyMother = await this.ProfileFamilyMother.findOne({
select: [
"id",
"motherPrefix",
"motherFirstName",
"motherLastName",
"motherCareer",
"motherCitizenId",
"motherLive",
"profileId",
],
where: { profileEmployeeId: profile.id },
order: { lastUpdatedAt: "DESC" },
});
return new HttpSuccess(familyMother);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -19,6 +19,107 @@ export class ProfileGovernmentHistoryController extends Controller {
private positionRepo = AppDataSource.getRepository(Position); private positionRepo = AppDataSource.getRepository(Position);
private posMasterRepo = AppDataSource.getRepository(PosMaster); private posMasterRepo = AppDataSource.getRepository(PosMaster);
/**
*
* @summary
*
*/
@Get("user")
public async getGovHistoryUser(@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 record = await this.profileRepo.findOne({
where: { id: profile.id },
relations: {
posType: true,
posLevel: true,
},
});
const posMaster = await this.posMasterRepo.findOne({
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
current_holderId: profile.id,
},
order: { createdAt: "DESC" },
relations: {
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
});
const position = await this.positionRepo.findOne({
where: {
positionIsSelected: true,
posMaster: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
current_holderId: profile.id,
},
},
order: { createdAt: "DESC" },
relations: {
posExecutive: true,
},
});
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const fullNameParts = [
posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name,
posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name,
posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name,
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
orgShortName = posMaster.orgRoot?.orgRootShortName;
} else if (posMaster.orgChild2Id === null) {
orgShortName = posMaster.orgChild1?.orgChild1ShortName;
} else if (posMaster.orgChild3Id === null) {
orgShortName = posMaster.orgChild2?.orgChild2ShortName;
} else if (posMaster.orgChild4Id === null) {
orgShortName = posMaster.orgChild3?.orgChild3ShortName;
} else {
orgShortName = posMaster.orgChild4?.orgChild4ShortName;
}
}
const data = {
org: org, //สังกัด
positionField: position == null ? null : position.positionField, //สายงาน
position: record.position, //ตำแหน่ง
posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ
posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง
posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท
posExecutive:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร
positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา
positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
dateRetireLaw: record.dateRetireLaw ?? null,
govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
dateAppoint: record.dateAppoint,
dateStart: record.dateStart,
govAgeAbsent: record.govAgeAbsent,
govAgePlus: record.govAgePlus,
reasonSameDate: record.reasonSameDate,
};
return new HttpSuccess(data);
}
/** /**
* *
* @summary * @summary

View file

@ -36,6 +36,97 @@ export class ProfileGovernmentEmployeeController extends Controller {
private positionRepo = AppDataSource.getRepository(EmployeePosition); private positionRepo = AppDataSource.getRepository(EmployeePosition);
private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster); private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
/**
*
* @summary
*
*/
@Get("user")
public async getGovHistoryUser(@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 record = await this.profileEmployeeRepo.findOne({
where: { id: profile.id },
relations: {
posType: true,
posLevel: true,
},
});
const posMaster = await this.posMasterRepo.findOne({
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
current_holderId: profile.id,
},
order: { createdAt: "DESC" },
relations: {
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
});
// const position = await this.positionRepo.findOne({
// where: {
// positionIsSelected: true,
// posMaster: {
// orgRevision: {
// orgRevisionIsCurrent: true,
// orgRevisionIsDraft: false,
// },
// current_holderId: profile.id,
// },
// },
// order: { createdAt: "DESC" },
// });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const fullNameParts = [
posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name,
posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name,
posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name,
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
let orgShortName = "";
if (posMaster != null) {
if (posMaster.orgChild1Id === null) {
orgShortName = posMaster.orgRoot?.orgRootShortName;
} else if (posMaster.orgChild2Id === null) {
orgShortName = posMaster.orgChild1?.orgChild1ShortName;
} else if (posMaster.orgChild3Id === null) {
orgShortName = posMaster.orgChild2?.orgChild2ShortName;
} else if (posMaster.orgChild4Id === null) {
orgShortName = posMaster.orgChild3?.orgChild3ShortName;
} else {
orgShortName = posMaster.orgChild4?.orgChild4ShortName;
}
}
const data = {
org: org, //สังกัด
position: record.position, //ตำแหน่ง
posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ
posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง
posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
dateRetireLaw: record.dateRetireLaw ?? null,
govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
dateAppoint: record.dateAppoint,
dateStart: record.dateStart,
govAgeAbsent: record.govAgeAbsent,
govAgePlus: record.govAgePlus,
reasonSameDate: record.reasonSameDate,
};
return new HttpSuccess(data);
}
/** /**
* *
* @summary * @summary

View file

@ -29,6 +29,18 @@ export class ProfileHonorController extends Controller {
private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorRepo = AppDataSource.getRepository(ProfileHonor);
private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory);
@Get("user")
public async getHonorUser(@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 record = await this.honorRepo.find({
where: { profileId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -29,6 +29,18 @@ export class ProfileHonorEmployeeController extends Controller {
private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorRepo = AppDataSource.getRepository(ProfileHonor);
private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory);
@Get("user")
public async getHonorUser(@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 record = await this.honorRepo.find({
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -35,6 +35,23 @@ export class ProfileInsigniaController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private insigniaMetaRepo = AppDataSource.getRepository(Insignia); private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
@Get("user")
public async getInsigniaUser(@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 record = await this.insigniaRepo.find({
relations: {
insignia: {
insigniaType: true,
},
},
where: { profileId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -35,6 +35,23 @@ export class ProfileInsigniaEmployeeController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private insigniaMetaRepo = AppDataSource.getRepository(Insignia); private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
@Get("user")
public async getInsigniaUser(@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 record = await this.insigniaRepo.find({
relations: {
insignia: {
insigniaType: true,
},
},
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -36,6 +36,19 @@ export class ProfileLeaveController extends Controller {
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory); private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
private leaveTypeRepository = AppDataSource.getRepository(LeaveType); private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
@Get("user")
public async getLeaveUser(@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 record = await this.leaveRepo.find({
relations: { leaveType: true },
where: { profileId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -36,6 +36,19 @@ export class ProfileLeaveEmployeeController extends Controller {
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory); private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
private leaveTypeRepository = AppDataSource.getRepository(LeaveType); private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
@Get("user")
public async getLeaveUser(@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 record = await this.leaveRepo.find({
relations: { leaveType: true },
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
public async getLeave(@Path() profileId: string) { public async getLeave(@Path() profileId: string) {
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({

View file

@ -29,6 +29,18 @@ export class ProfileNopaidController extends Controller {
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid); private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory); private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory);
@Get("user")
public async getNopaidUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.nopaidRepository.find({
where: { profileId: profile.id },
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileNopaidEmployeeController extends Controller {
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid); private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory); private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory);
@Get("user")
public async getNopaidUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.nopaidRepository.find({
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
public async getNopaid(@Path() profileId: string) { public async getNopaid(@Path() profileId: string) {
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({

View file

@ -29,6 +29,18 @@ export class ProfileOtherController extends Controller {
private otherRepository = AppDataSource.getRepository(ProfileOther); private otherRepository = AppDataSource.getRepository(ProfileOther);
private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory); private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory);
@Get("user")
public async getOtherUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.otherRepository.find({
where: { profileId: profile.id },
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileOtherEmployeeController extends Controller {
private otherRepository = AppDataSource.getRepository(ProfileOther); private otherRepository = AppDataSource.getRepository(ProfileOther);
private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory); private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory);
@Get("user")
public async getOtherUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lists = await this.otherRepository.find({
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(lists);
}
@Get("{profileId}") @Get("{profileId}")
public async getOther(@Path() profileId: string) { public async getOther(@Path() profileId: string) {
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({

View file

@ -30,6 +30,19 @@ export class ProfileSalaryController extends Controller {
private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryRepo = AppDataSource.getRepository(ProfileSalary);
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
@Get("user")
public async getSalaryUser(@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 record = await this.salaryRepo.find({
where: { profileId: profile.id },
order: { order: "ASC" },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -34,6 +34,19 @@ export class ProfileSalaryEmployeeController extends Controller {
private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryRepo = AppDataSource.getRepository(ProfileSalary);
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
@Get("user")
public async getSalaryUser(@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 record = await this.salaryRepo.find({
where: { profileEmployeeId: profile.id },
order: { order: "ASC" },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
public async getSalaryEmployee(@Path() profileId: string) { public async getSalaryEmployee(@Path() profileId: string) {
const record = await this.salaryRepo.find({ const record = await this.salaryRepo.find({

View file

@ -33,6 +33,18 @@ export class ProfileTrainingController extends Controller {
private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingRepo = AppDataSource.getRepository(ProfileTraining);
private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory);
@Get("user")
public async getTrainingUser(@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 record = await this.trainingRepo.find({
where: { profileId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileId}") @Get("{profileId}")
@Example({ @Example({
status: 200, status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileTrainingEmployeeController extends Controller {
private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingRepo = AppDataSource.getRepository(ProfileTraining);
private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory);
@Get("user")
public async getTrainingUser(@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 record = await this.trainingRepo.find({
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(record);
}
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({ @Example({
status: 200, status: 200,