no message

This commit is contained in:
kittapath 2024-09-27 13:50:26 +07:00
parent 71cfc78c6e
commit 7297f2bbc3
3 changed files with 318 additions and 235 deletions

View file

@ -128,17 +128,17 @@ export class ProfileController extends Controller {
where: { id: id }, where: { id: id },
order: { order: {
profileSalary: { profileSalary: {
date: "DESC" date: "DESC",
} },
} },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let ImgUrl: any let ImgUrl: any;
if (profile?.avatar != null && profile?.avatarName != null) { if (profile?.avatar != null && profile?.avatarName != null) {
await new CallAPI() await new CallAPI()
.GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) .GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
.then(async (x) => { .then(async (x) => {
ImgUrl = x.downloadUrl ImgUrl = x.downloadUrl;
}) })
.catch(); .catch();
} }
@ -249,7 +249,9 @@ export class ProfileController extends Controller {
: "-", : "-",
PositionName: profile.position != null ? profile.position : "-", PositionName: profile.position != null ? profile.position : "-",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
ImgUrl: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg` ImgUrl: ImgUrl
? ImgUrl
: `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
}; };
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
@ -282,12 +284,12 @@ export class ProfileController extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let ImgUrl: any let ImgUrl: any;
if (profiles?.avatar != null && profiles?.avatarName != null) { if (profiles?.avatar != null && profiles?.avatarName != null) {
await new CallAPI() await new CallAPI()
.GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) .GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
.then(async (x) => { .then(async (x) => {
ImgUrl = x.downloadUrl ImgUrl = x.downloadUrl;
}) })
.catch(); .catch();
} }
@ -450,31 +452,37 @@ export class ProfileController extends Controller {
? Extension.ToThaiNumber(profiles.currentProvince.name) ? Extension.ToThaiNumber(profiles.currentProvince.name)
: "", : "",
// AvatarId: profiles?.avatar ?? null, // AvatarId: profiles?.avatar ?? null,
ImgUrl: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg` ImgUrl: ImgUrl
? ImgUrl
: `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
}; };
const certs = await this.certificateRepository.find({ const certs = await this.certificateRepository.find({
where: { profileId: id }, where: { profileId: id },
select: ["certificateType", "issuer", "certificateNo", "issueDate"], select: ["certificateType", "issuer", "certificateNo", "issueDate"],
}); });
const Cert = certs.length > 0 const Cert =
certs.length > 0
? certs.map((item) => ({ ? certs.map((item) => ({
CertificateType: item.certificateType ?? null, CertificateType: item.certificateType ?? null,
Issuer: item.issuer ?? null, Issuer: item.issuer ?? null,
CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null,
IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null,
})) }))
:[{ : [
{
CertificateType: "-", CertificateType: "-",
Issuer: "-", Issuer: "-",
CertificateNo: "-", CertificateNo: "-",
IssueDate: "-" IssueDate: "-",
}]; },
];
const trainings = await this.trainingRepository.find({ const trainings = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department", "name"], select: ["startDate", "endDate", "place", "department", "name"],
where: { profileId: id }, where: { profileId: id },
}); });
const Training = trainings.length > 0 const Training =
trainings.length > 0
? trainings.map((item) => ({ ? trainings.map((item) => ({
Institute: item.department ?? "", Institute: item.department ?? "",
Start: Start:
@ -482,7 +490,9 @@ export class ProfileController extends Controller {
? "" ? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)), : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)),
End: End:
item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), item.endDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)),
Date: Date:
item.startDate && item.endDate item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
@ -491,7 +501,8 @@ export class ProfileController extends Controller {
Degree: item.name, Degree: item.name,
Field: "", Field: "",
})) }))
: [{ : [
{
Institute: "-", Institute: "-",
Start: "-", Start: "-",
End: "-", End: "-",
@ -499,31 +510,37 @@ export class ProfileController extends Controller {
Level: "-", Level: "-",
Degree: "-", Degree: "-",
Field: "-", Field: "-",
}]; },
];
const disciplines = await this.disciplineRepository.find({ const disciplines = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"], select: ["refCommandDate", "refCommandNo", "detail"],
where: { profileId: id }, where: { profileId: id },
}); });
const Discipline = disciplines.length > 0 const Discipline =
disciplines.length > 0
? disciplines.map((item) => ({ ? disciplines.map((item) => ({
DisciplineYear: DisciplineYear:
Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null, Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ??
null,
DisciplineDetail: item.detail ?? null, DisciplineDetail: item.detail ?? null,
RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null,
})) }))
: [{ : [
{
DisciplineYear: "-", DisciplineYear: "-",
DisciplineDetail: "-", DisciplineDetail: "-",
RefNo: "-", RefNo: "-",
}]; },
];
const educations = await this.educationRepository.find({ const educations = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileId: id }, where: { profileId: id },
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
}); });
const Education = educations.length > 0 const Education =
educations.length > 0
? educations.map((item) => ({ ? educations.map((item) => ({
Institute: item.institute, Institute: item.institute,
Start: Start:
@ -542,7 +559,8 @@ export class ProfileController extends Controller {
Degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", Degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "",
Field: item.field ?? "-", Field: item.field ?? "-",
})) }))
: [{ : [
{
Institute: "-", Institute: "-",
Start: "-", Start: "-",
End: "-", End: "-",
@ -550,7 +568,8 @@ export class ProfileController extends Controller {
Level: "-", Level: "-",
Degree: "-", Degree: "-",
Field: "-", Field: "-",
}]; },
];
const salarys = await this.salaryRepository.find({ const salarys = await this.salaryRepository.find({
select: [ select: [
"date", "date",
@ -564,18 +583,23 @@ export class ProfileController extends Controller {
"templateDoc", "templateDoc",
], ],
where: { profileId: id }, where: { profileId: id },
order: { order: "ASC" } order: { order: "ASC" },
}); });
const Salary = salarys.length > 0 const Salary =
salarys.length > 0
? salarys.map((item) => ({ ? salarys.map((item) => ({
SalaryDate: item.date ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) : null, SalaryDate: item.date
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date))
: null,
Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, Position: item.position != null ? Extension.ToThaiNumber(item.position) : null,
PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null,
Salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, Salary:
item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null, RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null,
PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, PositionLevel:
item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
PositionType: item.positionType ?? null, PositionType: item.positionType ?? null,
PositionAmount: PositionAmount:
item.positionSalaryAmount == null item.positionSalaryAmount == null
@ -584,7 +608,8 @@ export class ProfileController extends Controller {
FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
})) }))
: [{ : [
{
SalaryDate: "-", SalaryDate: "-",
Position: "-", Position: "-",
PosNo: "-", PosNo: "-",
@ -596,7 +621,8 @@ export class ProfileController extends Controller {
PositionAmount: "-", PositionAmount: "-",
FullName: "-", FullName: "-",
OcFullPath: "-", OcFullPath: "-",
}]; },
];
const insignias = await this.profileInsigniaRepo.find({ const insignias = await this.profileInsigniaRepo.find({
relations: { relations: {
@ -607,7 +633,8 @@ export class ProfileController extends Controller {
where: { profileId: id }, where: { profileId: id },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const Insignia = insignias.length > 0 const Insignia =
insignias.length > 0
? insignias.map((item) => ({ ? insignias.map((item) => ({
ReceiveDate: item.receiveDate ReceiveDate: item.receiveDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate))
@ -625,7 +652,8 @@ export class ProfileController extends Controller {
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
: "", : "",
})) }))
: [{ : [
{
ReceiveDate: "-", ReceiveDate: "-",
InsigniaName: "-", InsigniaName: "-",
InsigniaShortName: "-", InsigniaShortName: "-",
@ -637,14 +665,16 @@ export class ProfileController extends Controller {
Section: "-", Section: "-",
Page: "-", Page: "-",
RefCommandDate: "-", RefCommandDate: "-",
}]; },
];
const leaves = await this.profileLeaveRepository.find({ const leaves = await this.profileLeaveRepository.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileId: id }, where: { profileId: id },
order: { dateLeaveStart: "ASC" }, order: { dateLeaveStart: "ASC" },
}); });
const Leave = leaves.length > 0 const Leave =
leaves.length > 0
? leaves.map((item) => ({ ? leaves.map((item) => ({
LeaveTypeName: item.leaveType.name, LeaveTypeName: item.leaveType.name,
DateLeaveStart: item.dateLeaveStart DateLeaveStart: item.dateLeaveStart
@ -652,11 +682,13 @@ export class ProfileController extends Controller {
: "", : "",
LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "", LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "",
})) }))
: [{ : [
{
LeaveTypeName: "-", LeaveTypeName: "-",
DateLeaveStart: "-", DateLeaveStart: "-",
LeaveDays: "-", LeaveDays: "-",
}]; },
];
return new HttpSuccess({ return new HttpSuccess({
Profile: [Profile], Profile: [Profile],
@ -2604,7 +2636,7 @@ export class ProfileController extends Controller {
@Get("{id}") @Get("{id}")
async getProfile(@Request() req: RequestWithUser, @Path() id: string) { async getProfile(@Request() req: RequestWithUser, @Path() id: string) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id);
const profile = await this.profileRepo.findOne({ let profile: any = await this.profileRepo.findOne({
relations: { relations: {
posLevel: true, posLevel: true,
posType: true, posType: true,
@ -2613,7 +2645,7 @@ export class ProfileController extends Controller {
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
profile.profileType = "OFFICER";
return new HttpSuccess(profile); return new HttpSuccess(profile);
} }
@ -3187,21 +3219,30 @@ export class ProfileController extends Controller {
* *
*/ */
@Get("keycloak/position") @Get("keycloak/position")
async getProfileByKeycloak(@Request() request: { user: Record<string, any> } , @Query("revisionId") revisionId?: string,) { async getProfileByKeycloak(
@Request() request: { user: Record<string, any> },
@Query("revisionId") revisionId?: string,
) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot", "profileSalary"], relations: [
"posLevel",
"posType",
"current_holders",
"current_holders.orgRoot",
"profileSalary",
],
order: { order: {
profileSalary: { profileSalary: {
order: "DESC", order: "DESC",
} },
} },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const orgRevisionPublish = await this.orgRevisionRepo let orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
@ -3211,7 +3252,7 @@ export class ProfileController extends Controller {
} }
if (revisionId) { if (revisionId) {
const orgRevisionPublish = await this.orgRevisionRepo orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.id = :revisionId", { revisionId }) .where("orgRevision.id = :revisionId", { revisionId })
.getOne(); .getOne();
@ -3314,9 +3355,7 @@ export class ProfileController extends Controller {
child4ShortName: child4 == null ? null : child4.orgChild4ShortName, child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null, node: null,
nodeId: null, nodeId: null,
salary: profile && profile.profileSalary.length > 0 salary: profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
? profile.profileSalary[0].amount
: null
}; };
if (_profile.child4Id != null) { if (_profile.child4Id != null) {
@ -3357,9 +3396,9 @@ export class ProfileController extends Controller {
const orgRevisionPublish = await this.orgRevisionRepo.findOne({ const orgRevisionPublish = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsDraft: false, orgRevisionIsDraft: false,
orgRevisionIsCurrent: true orgRevisionIsCurrent: true,
} },
}) });
if (!orgRevisionPublish) { if (!orgRevisionPublish) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
} }
@ -3421,10 +3460,18 @@ export class ProfileController extends Controller {
}, },
}); });
const fullNameParts = [ const fullNameParts = [
posMaster_ == null || posMaster_.orgChild4 == null ? null : posMaster_.orgChild4.orgChild4Name, posMaster_ == null || posMaster_.orgChild4 == null
posMaster_ == null || posMaster_.orgChild3 == null ? null : posMaster_.orgChild3.orgChild3Name, ? null
posMaster_ == null || posMaster_.orgChild2 == null ? null : posMaster_.orgChild2.orgChild2Name, : posMaster_.orgChild4.orgChild4Name,
posMaster_ == null || posMaster_.orgChild1 == null ? null : posMaster_.orgChild1.orgChild1Name, 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, posMaster_ == null || posMaster_.orgRoot == null ? null : posMaster_.orgRoot.orgRootName,
]; ];
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/"); const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
@ -3539,7 +3586,7 @@ export class ProfileController extends Controller {
let commanderAbovePosition_: any = {}; let commanderAbovePosition_: any = {};
let commanderAboveRootName_: any = {}; let commanderAboveRootName_: any = {};
let commanderAboveOrg_: any; let commanderAboveOrg_: any;
let dataCommander: any let dataCommander: any;
commanderFullname_ = commanderFullname_ =
(findCmd?.current_holder?.prefix ?? "") + (findCmd?.current_holder?.prefix ?? "") +
@ -3555,14 +3602,14 @@ export class ProfileController extends Controller {
commanderAbovePosition_ = findOSAB?.current_holder?.position ?? ""; commanderAbovePosition_ = findOSAB?.current_holder?.position ?? "";
if (findCmd?.current_holderId == profile?.id) { if (findCmd?.current_holderId == profile?.id) {
commandProfileId = findOSAB?.current_holderId commandProfileId = findOSAB?.current_holderId;
commanderFullname_ = commanderFullname_ =
(findOSAB?.current_holder?.prefix ?? "") + (findOSAB?.current_holder?.prefix ?? "") +
(findOSAB?.current_holder?.firstName ?? "") + (findOSAB?.current_holder?.firstName ?? "") +
(findOSAB?.current_holder?.firstName ? " " : "") + (findOSAB?.current_holder?.firstName ? " " : "") +
(findOSAB?.current_holder?.lastName ?? ""); (findOSAB?.current_holder?.lastName ?? "");
commanderPosition_ = findOSAB?.current_holder?.position ?? ""; commanderPosition_ = findOSAB?.current_holder?.position ?? "";
commandAboveProfileId = findTSAB?.current_holderId commandAboveProfileId = findTSAB?.current_holderId;
commanderAboveFullname_ = commanderAboveFullname_ =
(findTSAB?.current_holder?.prefix ?? "") + (findTSAB?.current_holder?.prefix ?? "") +
(findTSAB?.current_holder?.firstName ?? "") + (findTSAB?.current_holder?.firstName ?? "") +
@ -3575,10 +3622,9 @@ export class ProfileController extends Controller {
commanderAboveFullname: commanderAboveFullname_, commanderAboveFullname: commanderAboveFullname_,
commanderAbovePosition: commanderAbovePosition_, commanderAbovePosition: commanderAbovePosition_,
}; };
} } else {
else { commandProfileId = findCmd?.current_holderId;
commandProfileId = findCmd?.current_holderId commandAboveProfileId = findOSAB?.current_holderId;
commandAboveProfileId = findOSAB?.current_holderId
dataCommander = { dataCommander = {
commanderFullname: commanderFullname_, commanderFullname: commanderFullname_,
commanderPosition: commanderPosition_, commanderPosition: commanderPosition_,
@ -3594,9 +3640,11 @@ export class ProfileController extends Controller {
commanderRootName_ = commanderRootName_ =
commandProfile?.current_holders == null || commandProfile?.current_holders == null ||
commandProfile?.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null commandProfile?.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
?.orgRoot == null
? null ? null
: commandProfile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot; : commandProfile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
?.orgRoot;
//find สังกัดผู้บังคับบัญชา //find สังกัดผู้บังคับบัญชา
const commanderPosMaster_ = await this.posMasterRepo.findOne({ const commanderPosMaster_ = await this.posMasterRepo.findOne({
where: { where: {
@ -3613,13 +3661,25 @@ export class ProfileController extends Controller {
}, },
}); });
const commanderFullNameParts = [ const commanderFullNameParts = [
commanderPosMaster_ == null || commanderPosMaster_.orgChild4 == null ? null : commanderPosMaster_.orgChild4.orgChild4Name, commanderPosMaster_ == null || commanderPosMaster_.orgChild4 == null
commanderPosMaster_ == null || commanderPosMaster_.orgChild3 == null ? null : commanderPosMaster_.orgChild3.orgChild3Name, ? null
commanderPosMaster_ == null || commanderPosMaster_.orgChild2 == null ? null : commanderPosMaster_.orgChild2.orgChild2Name, : commanderPosMaster_.orgChild4.orgChild4Name,
commanderPosMaster_ == null || commanderPosMaster_.orgChild1 == null ? null : commanderPosMaster_.orgChild1.orgChild1Name, commanderPosMaster_ == null || commanderPosMaster_.orgChild3 == null
commanderPosMaster_ == null || commanderPosMaster_.orgRoot == null ? null : commanderPosMaster_.orgRoot.orgRootName, ? null
: commanderPosMaster_.orgChild3.orgChild3Name,
commanderPosMaster_ == null || commanderPosMaster_.orgChild2 == null
? null
: commanderPosMaster_.orgChild2.orgChild2Name,
commanderPosMaster_ == null || commanderPosMaster_.orgChild1 == null
? null
: commanderPosMaster_.orgChild1.orgChild1Name,
commanderPosMaster_ == null || commanderPosMaster_.orgRoot == null
? null
: commanderPosMaster_.orgRoot.orgRootName,
]; ];
commanderOrg_ = commanderFullNameParts.filter((part) => part !== undefined && part !== null).join("/"); commanderOrg_ = commanderFullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
const commandAboveProfile = await this.profileRepo.findOne({ const commandAboveProfile = await this.profileRepo.findOne({
where: { id: String(commandAboveProfileId) }, where: { id: String(commandAboveProfileId) },
@ -3628,9 +3688,11 @@ export class ProfileController extends Controller {
commanderAboveRootName_ = commanderAboveRootName_ =
commandAboveProfile?.current_holders == null || commandAboveProfile?.current_holders == null ||
commandAboveProfile?.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null commandAboveProfile?.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
?.orgRoot == null
? null ? null
: commandAboveProfile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot; : commandAboveProfile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
?.orgRoot;
//find สังกัดผู้บังคับบัญชาเหนือไป1ขั้น //find สังกัดผู้บังคับบัญชาเหนือไป1ขั้น
const commanderAbovePosMaster_ = await this.posMasterRepo.findOne({ const commanderAbovePosMaster_ = await this.posMasterRepo.findOne({
where: { where: {
@ -3647,13 +3709,25 @@ export class ProfileController extends Controller {
}, },
}); });
const commanderAboveFullNameParts = [ const commanderAboveFullNameParts = [
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild4 == null ? null : commanderAbovePosMaster_.orgChild4.orgChild4Name, commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild4 == null
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild3 == null ? null : commanderAbovePosMaster_.orgChild3.orgChild3Name, ? null
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild2 == null ? null : commanderAbovePosMaster_.orgChild2.orgChild2Name, : commanderAbovePosMaster_.orgChild4.orgChild4Name,
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild1 == null ? null : commanderAbovePosMaster_.orgChild1.orgChild1Name, commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild3 == null
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgRoot == null ? null : commanderAbovePosMaster_.orgRoot.orgRootName, ? null
: commanderAbovePosMaster_.orgChild3.orgChild3Name,
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild2 == null
? null
: commanderAbovePosMaster_.orgChild2.orgChild2Name,
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgChild1 == null
? null
: commanderAbovePosMaster_.orgChild1.orgChild1Name,
commanderAbovePosMaster_ == null || commanderAbovePosMaster_.orgRoot == null
? null
: commanderAbovePosMaster_.orgRoot.orgRootName,
]; ];
commanderAboveOrg_ = commanderAboveFullNameParts.filter((part) => part !== undefined && part !== null).join("/"); commanderAboveOrg_ = commanderAboveFullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
const _profile: any = { const _profile: any = {
profileId: profile.id, profileId: profile.id,
@ -3707,19 +3781,27 @@ export class ProfileController extends Controller {
nodeId: null, nodeId: null,
org: org ? org : null, org: org ? org : null,
// commander: dataCommander, // commander: dataCommander,
commanderFullname: dataCommander && dataCommander.commanderFullname commanderFullname:
? dataCommander.commanderFullname : null, dataCommander && dataCommander.commanderFullname ? dataCommander.commanderFullname : null,
commanderPosition: dataCommander && dataCommander.commanderPosition commanderPosition:
? dataCommander.commanderPosition : null, dataCommander && dataCommander.commanderPosition ? dataCommander.commanderPosition : null,
commanderRootName: commanderRootName_ && commanderRootName_.orgRootName commanderRootName:
? commanderRootName_.orgRootName : null, commanderRootName_ && commanderRootName_.orgRootName
? commanderRootName_.orgRootName
: null,
commanderOrg: commanderOrg_ ? commanderOrg_ : null, commanderOrg: commanderOrg_ ? commanderOrg_ : null,
commanderAboveFullname: dataCommander && dataCommander.commanderAboveFullname commanderAboveFullname:
? dataCommander.commanderAboveFullname : null, dataCommander && dataCommander.commanderAboveFullname
commanderAbovePosition: dataCommander && dataCommander.commanderAbovePosition ? dataCommander.commanderAboveFullname
? dataCommander.commanderAbovePosition : null, : null,
commanderAboveRootName: commanderAboveRootName_ && commanderAboveRootName_.orgRootName commanderAbovePosition:
? commanderAboveRootName_.orgRootName : null, dataCommander && dataCommander.commanderAbovePosition
? dataCommander.commanderAbovePosition
: null,
commanderAboveRootName:
commanderAboveRootName_ && commanderAboveRootName_.orgRootName
? commanderAboveRootName_.orgRootName
: null,
commanderAboveOrg: commanderAboveOrg_ ? commanderAboveOrg_ : null, commanderAboveOrg: commanderAboveOrg_ ? commanderAboveOrg_ : null,
}; };

View file

@ -1204,7 +1204,7 @@ export class ProfileEmployeeController extends Controller {
@Get("{id}") @Get("{id}")
async detailProfile(@Path() id: string, @Request() req: RequestWithUser) { async detailProfile(@Path() id: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id);
const profile = await this.profileRepo.findOne({ const profile: any = await this.profileRepo.findOne({
relations: { relations: {
posLevel: true, posLevel: true,
posType: true, posType: true,
@ -1216,6 +1216,7 @@ export class ProfileEmployeeController extends Controller {
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
profile.profileType = "EMPLOYEE";
return new HttpSuccess(profile); return new HttpSuccess(profile);
} }
@ -1795,7 +1796,7 @@ export class ProfileEmployeeController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const orgRevisionPublish = await this.orgRevisionRepo let orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
@ -1805,7 +1806,7 @@ export class ProfileEmployeeController extends Controller {
} }
if (revisionId) { if (revisionId) {
const orgRevisionPublish = await this.orgRevisionRepo orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.id = :revisionId", { revisionId }) .where("orgRevision.id = :revisionId", { revisionId })
// .andWhere("orgRevision.orgRevisionIsDraft = false") // .andWhere("orgRevision.orgRevisionIsDraft = false")

View file

@ -1558,7 +1558,7 @@ export class ProfileEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
const orgRevisionPublish = await this.orgRevisionRepo let orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false") .where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true") .andWhere("orgRevision.orgRevisionIsCurrent = true")
@ -1568,7 +1568,7 @@ export class ProfileEmployeeTempController extends Controller {
} }
if (revisionId) { if (revisionId) {
const orgRevisionPublish = await this.orgRevisionRepo orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.id = :revisionId", { revisionId }) .where("orgRevision.id = :revisionId", { revisionId })
// .andWhere("orgRevision.orgRevisionIsDraft = false") // .andWhere("orgRevision.orgRevisionIsDraft = false")