filter education
This commit is contained in:
parent
e7798402eb
commit
332a96efb3
4 changed files with 187 additions and 159 deletions
|
|
@ -5,6 +5,7 @@ import { PosMaster } from "../entities/PosMaster";
|
|||
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
|
||||
import { PosMasterEmployeeTempHistory } from "../entities/PosMasterEmployeeTempHistory";
|
||||
import { PosMasterHistory } from "../entities/PosMasterHistory";
|
||||
import { ProfileEducation } from "../entities/ProfileEducation";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
export async function CreatePosMasterHistoryOfficer(
|
||||
|
|
@ -38,9 +39,9 @@ export async function CreatePosMasterHistoryOfficer(
|
|||
const h = new PosMasterHistory();
|
||||
const selectedPosition =
|
||||
pm.positions.length > 0
|
||||
? pm.positions.find((p) => p.positionIsSelected === true) ?? null
|
||||
? pm.positions.find((p) => p.positionIsSelected === true) ?? null
|
||||
: null;
|
||||
h.ancestorDNA = pm.ancestorDNA? pm.ancestorDNA : _null;
|
||||
h.ancestorDNA = pm.ancestorDNA ? pm.ancestorDNA : _null;
|
||||
h.prefix = pm.current_holder?.prefix || _null;
|
||||
h.firstName = pm.current_holder?.firstName || _null;
|
||||
h.lastName = pm.current_holder?.lastName || _null;
|
||||
|
|
@ -214,3 +215,22 @@ export async function CreatePosMasterHistoryEmployeeTemp(
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getTopDegrees(educations: ProfileEducation[]): Promise<string> {
|
||||
// filter เฉพาะ isUse==true หรือ isEducation==true
|
||||
const filtered = educations.filter((e) => e.isUse === true || e.isEducation === true);
|
||||
// sort: isEducation==true ก่อน, ถ้าเท่ากัน sort ด้วย level น้อยสุด
|
||||
const sorted = filtered.sort((a, b) => {
|
||||
const aEdu = !!a.isEducation ? 0 : 1;
|
||||
const bEdu = !!b.isEducation ? 0 : 1;
|
||||
if (aEdu !== bEdu) return aEdu - bEdu;
|
||||
const aLevel = typeof a.level === "number" ? a.level : Number.MAX_SAFE_INTEGER;
|
||||
const bLevel = typeof b.level === "number" ? b.level : Number.MAX_SAFE_INTEGER;
|
||||
return aLevel - bLevel;
|
||||
});
|
||||
|
||||
return sorted
|
||||
.map((e) => [e.degree, e.field].filter(Boolean).join(" "))
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue