get profile by token

This commit is contained in:
Kittapath 2024-05-24 01:11:47 +07:00
parent 58fe2f08fd
commit 85f8fbb03a
5 changed files with 124 additions and 59 deletions

View file

@ -548,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
* *

View file

@ -68,7 +68,7 @@ export class ProfileEmployeeController extends Controller {
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: [ relations: [
"profileSalarys", "profileSalarys",
@ -78,16 +78,20 @@ export class ProfileEmployeeController extends Controller {
"current_holders.orgChild1", "current_holders.orgChild1",
"current_holders.orgChild2", "current_holders.orgChild2",
"current_holders.orgChild3", "current_holders.orgChild3",
"current_holders.orgChild4" "current_holders.orgChild4",
], ],
where: { id: id, }, where: { id: id },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const province = await this.provinceRepository.findOneBy({ id: profile.registrationProvinceId }) const province = await this.provinceRepository.findOneBy({
const district = await this.districtRepository.findOneBy({ id: profile.registrationDistrictId }) id: profile.registrationProvinceId,
const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId }) });
const district = await this.districtRepository.findOneBy({
id: profile.registrationDistrictId,
});
const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId });
const root = const root =
profile.current_holders == null || profile.current_holders == null ||
profile.current_holders.length == 0 || profile.current_holders.length == 0 ||
@ -123,11 +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 _regisAddres =
let _subDistrict = subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "" profile && profile.registrationAddress != null ? profile.registrationAddress : "";
let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : "" let _subDistrict =
let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : "" subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "";
let registrationZipCode = profile && profile.registrationZipCode != null ? ` รหัสไปรษณีย์ ${profile.registrationZipCode}` : "" 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}/`;
@ -140,25 +149,34 @@ export class ProfileEmployeeController extends Controller {
Prefix: profile.prefix != null ? profile.prefix : "", Prefix: profile.prefix != null ? profile.prefix : "",
FirstName: profile.firstName != null ? profile.firstName : "", FirstName: profile.firstName != null ? profile.firstName : "",
LastName: profile.lastName != null ? profile.lastName : "", LastName: profile.lastName != null ? profile.lastName : "",
DateOfBirth: profile.birthDate != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate)) : "", DateOfBirth:
DateRetire: profile.dateRetire != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire)) : "", 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}`, RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
SalaryAmount: profile.profileSalarys.length > 0 && profile.profileSalarys[0].amount != null SalaryAmount:
? Extension.ToThaiNumber(profile.profileSalarys[0].amount.toLocaleString()) profile.profileSalarys.length > 0 && profile.profileSalarys[0].amount != null
: "", ? Extension.ToThaiNumber(profile.profileSalarys[0].amount.toLocaleString())
Education: profile.profileEducations.length > 0 && profile.profileEducations[profile.profileEducations.length-1].institute != null : "",
? profile.profileEducations[profile.profileEducations.length-1].institute Education:
: "", profile.profileEducations.length > 0 &&
profile.profileEducations[profile.profileEducations.length - 1].institute != null
? profile.profileEducations[profile.profileEducations.length - 1].institute
: "",
AppointText: profile.dateAppoint != null ? profile.dateAppoint : "", AppointText: profile.dateAppoint != null ? profile.dateAppoint : "",
SalaryDate: profile.profileSalarys.length > 0 && profile.profileSalarys[0].date != null SalaryDate:
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalarys[0].date)) profile.profileSalarys.length > 0 && profile.profileSalarys[0].date != null
: "", ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalarys[0].date))
: "",
PositionName: profile.position != null ? profile.position : "", PositionName: profile.position != null ? profile.position : "",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
} };
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
/** /**
@ -349,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
* *
@ -664,7 +707,7 @@ export class ProfileEmployeeController extends Controller {
"profileEmployee.citizenId", "profileEmployee.citizenId",
"profileSalarys.position", "profileSalarys.position",
"profileSalarys.posNo", "profileSalarys.posNo",
"profileSalarys.date" "profileSalarys.date",
]) ])
.andWhere( .andWhere(
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
@ -684,24 +727,24 @@ export class ProfileEmployeeController extends Controller {
) )
.getMany(); .getMany();
const mapData = profiles.map(profile => { const mapData = profiles.map((profile) => {
let profileSalary; let profileSalary;
if (profile.profileSalarys && profile.profileSalarys.length > 0) { if (profile.profileSalarys && profile.profileSalarys.length > 0) {
profileSalary = profile.profileSalarys.reduce((latest, current) => { profileSalary = profile.profileSalarys.reduce((latest, current) => {
return new Date(current.date) > new Date(latest.date) ? current : latest; return new Date(current.date) > new Date(latest.date) ? current : latest;
}); });
} }
return { return {
id: profile.id, id: profile.id,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
citizenId: profile.citizenId, citizenId: profile.citizenId,
position: profileSalary ? profileSalary.position : null, position: profileSalary ? profileSalary.position : null,
posNo: profileSalary ? profileSalary.posNo : null, posNo: profileSalary ? profileSalary.posNo : null,
date: profileSalary ? profileSalary.date : null date: profileSalary ? profileSalary.date : null,
}; };
}); });
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
/** /**

View file

@ -50,7 +50,7 @@ export class ProfileFamilyFatherController extends Controller {
"fatherLive", "fatherLive",
"profileId", "profileId",
], ],
where: { id: profile.id }, where: { profileId: profile.id },
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
}); });

View file

@ -45,7 +45,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
const family = await this.familyHistoryRepo.find({ const family = await this.familyHistoryRepo.find({
take: 1, take: 1,
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
where: { profileId: profile.id }, where: { profileEmployeeId: profile.id },
}); });
const children = await this.childrenRepo.find({ const children = await this.childrenRepo.find({
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },

View file

@ -71,19 +71,19 @@ export class ProfileGovernmentEmployeeController extends Controller {
orgChild4: true, orgChild4: true,
}, },
}); });
const position = await this.positionRepo.findOne({ // const position = await this.positionRepo.findOne({
where: { // where: {
positionIsSelected: true, // positionIsSelected: true,
posMaster: { // posMaster: {
orgRevision: { // orgRevision: {
orgRevisionIsCurrent: true, // orgRevisionIsCurrent: true,
orgRevisionIsDraft: false, // orgRevisionIsDraft: false,
}, // },
current_holderId: profile.id, // current_holderId: profile.id,
}, // },
}, // },
order: { createdAt: "DESC" }, // order: { createdAt: "DESC" },
}); // });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const fullNameParts = [ const fullNameParts = [