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

View file

@ -33,6 +33,21 @@ export class ProfileAbilityController extends Controller {
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
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}")
@Example({
status: 200,

View file

@ -35,6 +35,21 @@ export class ProfileAbilityEmployeeController extends Controller {
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
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}")
@Example({
status: 200,
@ -181,7 +196,7 @@ export class ProfileAbilityEmployeeController extends Controller {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -34,6 +34,34 @@ export class ProfileAddressController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
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

View file

@ -35,6 +35,34 @@ export class ProfileAddressEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
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

View file

@ -39,6 +39,21 @@ export class ProfileAssessmentsController extends Controller {
private profileAssessmentsHistoryRepository =
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}")
@Example({
status: 200,

View file

@ -36,8 +36,22 @@ import { RequestWithUser } from "../middlewares/user";
export class ProfileAssessmentsEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
private profileAssessmentsHistoryRepository =
AppDataSource.getRepository(ProfileAssessmentHistory);
private profileAssessmentsHistoryRepository = 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}")
@Example({

View file

@ -33,6 +33,18 @@ export class ProfileCertificateController extends Controller {
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
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}")
@Example({
status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileCertificateEmployeeController extends Controller {
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
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}")
@Example({
status: 200,

View file

@ -33,6 +33,20 @@ export class ProfileChangeNameController extends Controller {
private changeNameRepository = AppDataSource.getRepository(ProfileChangeName);
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}")
@Example({
status: 200,
@ -158,17 +172,17 @@ export class ProfileChangeNameController extends Controller {
]);
const chkLastRecord = await this.changeNameRepository.findOne({
where:{
profileId: record.profileId
where: {
profileId: record.profileId,
},
order:{
createdAt: "DESC"
}
})
order: {
createdAt: "DESC",
},
});
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profile = await this.profileRepository.findOneBy({ id: record.profileId });
if (profile && chkLastRecord.id === record.id) {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;

View file

@ -35,6 +35,20 @@ export class ProfileChangeNameEmployeeController extends Controller {
private changeNameRepository = AppDataSource.getRepository(ProfileChangeName);
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}")
@Example({
status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileChildrenController extends Controller {
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
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}")
public async getChildren(@Path() profileId: string) {
const lists = await this.childrenRepository.find({
@ -67,9 +79,9 @@ export class ProfileChildrenController extends Controller {
};
Object.assign(data, { ...body, ...meta });
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
await this.childrenRepository.save(data);
if(data){
if (data) {
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
profileChildrenId: data.id,
childrenCareer: data.childrenCareer,
@ -102,16 +114,15 @@ export class ProfileChildrenController extends Controller {
Object.assign(record, body);
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId));
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.childrenPrefix = record.childrenPrefix;
history.childrenLive = record.childrenLive;
history.childrenCitizenId = record.childrenCitizenId;
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
(history.lastUpdateUserId = req.user.sub), (history.lastUpdateFullName = req.user.name);
await Promise.all([
this.childrenRepository.save(record),
this.childrenHistoryRepository.save(history),

View file

@ -35,6 +35,18 @@ export class ProfileChildrenEmployeeController extends Controller {
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
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}")
public async getChildren(@Path() profileEmployeeId: string) {
const lists = await this.childrenRepository.find({

View file

@ -43,6 +43,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Province } from "../entities/Province";
import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile")
@Tags("Profile")
@ -136,6 +137,16 @@ export class ProfileController extends Controller {
? null
: 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 _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`;
@ -144,21 +155,34 @@ export class ProfileController extends Controller {
const mapData = {
Id: profile.id,
CitizenId: profile.citizenId,
Prefix: profile.prefix,
FirstName: profile.firstName,
LastName: profile.lastName,
DateOfBirth: profile.birthDate,
DateRetire: profile.dateRetire,
RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`,
SalaryAmount: profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "",
Prefix: profile.prefix != null ? profile.prefix : "",
FirstName: profile.firstName != null ? profile.firstName : "",
LastName: profile.lastName != null ? profile.lastName : "",
DateOfBirth:
profile.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate))
: "",
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:
profile.profileEducations.length > 0
profile.profileEducations.length > 0 &&
profile.profileEducations[profile.profileEducations.length - 1].institute != null
? profile.profileEducations[profile.profileEducations.length - 1].institute
: null,
AppointText: profile.dateAppoint,
SalaryDate: profile.profileSalary.length > 0 ? profile.profileSalary[0].date : null,
PositionName: profile.position,
: "",
AppointText: profile.dateAppoint != null ? profile.dateAppoint : "",
SalaryDate:
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}`,
};
@ -524,6 +548,28 @@ export class ProfileController extends Controller {
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
*
@ -1061,6 +1107,8 @@ export class ProfileController extends Controller {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
avatar: profile.avatar,
avatarName: profile.avatarName,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,

View file

@ -33,6 +33,29 @@ export class ProfileDisciplineController extends Controller {
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
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}")
public async getDiscipline(@Path() profileId: string) {
const lists = await this.disciplineRepository.find({

View file

@ -33,6 +33,29 @@ export class ProfileDisciplineEmployeeController extends Controller {
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
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}")
@Example({
status: 200,

View file

@ -29,6 +29,27 @@ export class ProfileDutyController extends Controller {
private dutyRepository = AppDataSource.getRepository(ProfileDuty);
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}")
@Example({
status: 200,

View file

@ -29,6 +29,27 @@ export class ProfileDutyEmployeeController extends Controller {
private dutyRepository = AppDataSource.getRepository(ProfileDuty);
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}")
public async getDuty(@Path() profileId: string) {
const lists = await this.dutyRepository.find({

View file

@ -39,6 +39,21 @@ export class ProfileEducationsController extends Controller {
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
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}")
@Example({
status: 200,

View file

@ -41,6 +41,21 @@ export class ProfileEducationsEmployeeController extends Controller {
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
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}")
@Example({
status: 200,

View file

@ -35,6 +35,7 @@ import { Position } from "../entities/Position";
import { Province } from "../entities/Province";
import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@ -126,6 +127,16 @@ export class ProfileEmployeeController extends Controller {
? null
: 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 _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`;
@ -134,21 +145,34 @@ export class ProfileEmployeeController extends Controller {
const mapData = {
Id: profile.id,
CitizenId: profile.citizenId,
Prefix: profile.prefix,
FirstName: profile.firstName,
LastName: profile.lastName,
DateOfBirth: profile.birthDate,
DateRetire: profile.dateRetire,
RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`,
SalaryAmount: profile.profileSalarys.length > 0 ? profile.profileSalarys[0].amount : null,
CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "",
Prefix: profile.prefix != null ? profile.prefix : "",
FirstName: profile.firstName != null ? profile.firstName : "",
LastName: profile.lastName != null ? profile.lastName : "",
DateOfBirth:
profile.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate))
: "",
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:
profile.profileEducations.length > 0
profile.profileEducations.length > 0 &&
profile.profileEducations[profile.profileEducations.length - 1].institute != null
? profile.profileEducations[profile.profileEducations.length - 1].institute
: null,
AppointText: profile.dateAppoint,
SalaryDate: profile.profileSalarys.length > 0 ? profile.profileSalarys[0].date : null,
PositionName: profile.position,
: "",
AppointText: profile.dateAppoint != null ? profile.dateAppoint : "",
SalaryDate:
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}`,
};
@ -343,6 +367,31 @@ export class ProfileEmployeeController extends Controller {
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
*

View file

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

View file

@ -29,6 +29,32 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple);
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}")
@Example({
status: 200,

View file

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

View file

@ -29,6 +29,30 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather);
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}")
@Example({
status: 200,

View file

@ -36,6 +36,31 @@ export class ProfileFamilyHistoryController extends Controller {
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,

View file

@ -36,6 +36,31 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
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,

View file

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

View file

@ -29,6 +29,30 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother);
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}")
@Example({
status: 200,

View file

@ -19,6 +19,107 @@ export class ProfileGovernmentHistoryController extends Controller {
private positionRepo = AppDataSource.getRepository(Position);
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

View file

@ -36,6 +36,97 @@ export class ProfileGovernmentEmployeeController extends Controller {
private positionRepo = AppDataSource.getRepository(EmployeePosition);
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

View file

@ -29,6 +29,18 @@ export class ProfileHonorController extends Controller {
private honorRepo = AppDataSource.getRepository(ProfileHonor);
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}")
@Example({
status: 200,

View file

@ -29,6 +29,18 @@ export class ProfileHonorEmployeeController extends Controller {
private honorRepo = AppDataSource.getRepository(ProfileHonor);
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}")
@Example({
status: 200,

View file

@ -35,6 +35,23 @@ export class ProfileInsigniaController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
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}")
@Example({
status: 200,

View file

@ -35,6 +35,23 @@ export class ProfileInsigniaEmployeeController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
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}")
@Example({
status: 200,

View file

@ -36,6 +36,19 @@ export class ProfileLeaveController extends Controller {
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
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}")
@Example({
status: 200,

View file

@ -36,6 +36,19 @@ export class ProfileLeaveEmployeeController extends Controller {
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
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}")
public async getLeave(@Path() profileId: string) {
const record = await this.leaveRepo.find({

View file

@ -29,6 +29,18 @@ export class ProfileNopaidController extends Controller {
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
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}")
@Example({
status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileNopaidEmployeeController extends Controller {
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
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}")
public async getNopaid(@Path() profileId: string) {
const lists = await this.nopaidRepository.find({

View file

@ -29,6 +29,18 @@ export class ProfileOtherController extends Controller {
private otherRepository = AppDataSource.getRepository(ProfileOther);
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}")
@Example({
status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileOtherEmployeeController extends Controller {
private otherRepository = AppDataSource.getRepository(ProfileOther);
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}")
public async getOther(@Path() profileId: string) {
const lists = await this.otherRepository.find({

View file

@ -30,6 +30,19 @@ export class ProfileSalaryController extends Controller {
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
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}")
@Example({
status: 200,

View file

@ -34,6 +34,19 @@ export class ProfileSalaryEmployeeController extends Controller {
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
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}")
public async getSalaryEmployee(@Path() profileId: string) {
const record = await this.salaryRepo.find({

View file

@ -33,6 +33,18 @@ export class ProfileTrainingController extends Controller {
private trainingRepo = AppDataSource.getRepository(ProfileTraining);
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}")
@Example({
status: 200,

View file

@ -33,6 +33,18 @@ export class ProfileTrainingEmployeeController extends Controller {
private trainingRepo = AppDataSource.getRepository(ProfileTraining);
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}")
@Example({
status: 200,