sort edu by level

This commit is contained in:
kittapath 2025-01-06 23:58:24 +07:00
parent 4b05629c29
commit 587fe5d5b6
11 changed files with 229 additions and 266 deletions

View file

@ -624,9 +624,9 @@ export class CommandController extends Controller {
const command = await this.commandRepository.findOne({
where: { id },
order: {
commandSends : {
createdAt: "ASC"
}
commandSends: {
createdAt: "ASC",
},
},
relations: ["commandSends", "commandSends.commandSendCCs"],
});
@ -642,9 +642,7 @@ export class CommandController extends Controller {
lastName: item.lastName,
position: item.position,
org: item.org,
sendCC: item.commandSendCCs
.sort((a, b) => a.name.localeCompare(b.name))
.map((x) => x.name),
sendCC: item.commandSendCCs.sort((a, b) => a.name.localeCompare(b.name)).map((x) => x.name),
profileId: item.profileId,
}));
return new HttpSuccess(_command);
@ -1334,7 +1332,7 @@ export class CommandController extends Controller {
});
if (profile != null) {
issue =
orgRevisionActive?.posMasters?.filter((x:any) => x.current_holderId == profile.id)[0]
orgRevisionActive?.posMasters?.filter((x: any) => x.current_holderId == profile.id)[0]
?.orgRoot?.orgRootName || null;
}
}
@ -1397,16 +1395,16 @@ export class CommandController extends Controller {
};
} else {
let _persons: any;
_persons = await Promise.all(
command.commandRecives.map(async(x, idx) => {
_persons = await Promise.all(
command.commandRecives.map(async (x, idx) => {
const profile = await this.profileEmployeeRepository.findOne({
where: {
where: {
id: x.profileId,
},
relations: [
"posLevel",
"posType",
"current_holders",
"posLevel",
"posType",
"current_holders",
"current_holders.orgRevision",
"current_holders.orgRoot",
"current_holders.orgChild1",
@ -1418,65 +1416,78 @@ export class CommandController extends Controller {
const shortName =
profile?.current_holders.length == 0
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) != null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4 !=
null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) !=
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4.orgChild4ShortName}${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) != null &&
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) !=
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild3 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3.orgChild3ShortName}${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) != null &&
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild2 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2.orgChild2ShortName}${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) !=
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild1 != null
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
)?.orgChild1 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1.orgChild1ShortName}${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) !=
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgRoot != null
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
)?.orgRoot != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot.orgRootShortName}${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: null;
const root =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgRoot;
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgRoot;
const child1 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild1;
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild1;
const child2 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild2;
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild2;
const child3 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3;
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild3;
const child4 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4;
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
@ -1484,33 +1495,30 @@ export class CommandController extends Controller {
let _root = root == null ? "" : `${root.orgRootName}`;
return {
no: Extension.ToThaiNumber((idx+1).toString()),
no: Extension.ToThaiNumber((idx + 1).toString()),
org: `${_child4}${_child3}${_child2}${_child1}${_root}`,
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
citizenId: Extension.ToThaiNumber(x.citizenId),
position: profile?.position
? profile?.position
: "-",
posLevel: profile?.posType && profile?.posLevel
? Extension.ToThaiNumber(`${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`)
: "-",
posNo: shortName
? Extension.ToThaiNumber(shortName)
: "-",
amount: x.amount
? Extension.ToThaiNumber(x.amount.toString())
: "-",
dateRetire: profile?.dateRetire
position: profile?.position ? profile?.position : "-",
posLevel:
profile?.posType && profile?.posLevel
? Extension.ToThaiNumber(
`${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`,
)
: "-",
posNo: shortName ? Extension.ToThaiNumber(shortName) : "-",
amount: x.amount ? Extension.ToThaiNumber(x.amount.toString()) : "-",
dateRetire: profile?.dateRetire
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile?.dateRetire))
: "-",
dateExecute: command.commandExcecuteDate
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(command.commandExcecuteDate))
: "-",
remark: x.remarkVertical
? x.remarkVertical
: "-"
}
})
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_monthYear(command.commandExcecuteDate),
)
: "-",
remark: x.remarkVertical ? x.remarkVertical : "-",
};
}),
);
_command = {
issue: issue,
@ -1552,7 +1560,7 @@ export class CommandController extends Controller {
res && res.length > 3
? `๔. ${res[3].name}.........${res[3].role}`
: "๔. ..........................กรรมการ",
persons: _persons
persons: _persons,
};
}
@ -2095,7 +2103,7 @@ export class CommandController extends Controller {
if (["C-PM-10"].includes(commandCode)) {
await Promise.all(
requestBody.persons.map(async (item:any) => {
requestBody.persons.map(async (item: any) => {
const _posMasterDirector = await this.posMasterRepository.findOne({
where: {
orgRootId: item.rootId,
@ -2103,11 +2111,11 @@ export class CommandController extends Controller {
current_holderId: item.profileId,
},
relations: ["current_holder", "orgRoot", "positions"],
});
});
const _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: item.profileId ?? null_
profileId: item.profileId ?? null_,
},
});
if (!_commandSend) {
@ -2116,12 +2124,14 @@ export class CommandController extends Controller {
commandSend.prefix = item.prefix;
commandSend.firstName = item.firstName;
commandSend.lastName = item.lastName;
commandSend.position = _posMasterDirector && _posMasterDirector.positions.length > 0
? _posMasterDirector.positions[0].positionName
: null_;
commandSend.org = _posMasterDirector && _posMasterDirector.orgRoot
? _posMasterDirector.orgRoot.orgRootName
: null_;
commandSend.position =
_posMasterDirector && _posMasterDirector.positions.length > 0
? _posMasterDirector.positions[0].positionName
: null_;
commandSend.org =
_posMasterDirector && _posMasterDirector.orgRoot
? _posMasterDirector.orgRoot.orgRootName
: null_;
commandSend.profileId = item.profileId;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
@ -2149,10 +2159,9 @@ export class CommandController extends Controller {
await this.commandSendCCRepository.save(_dataSendCC);
}
}
})
)
}),
);
}
}
return new HttpSuccess(command.id);
}
@ -3786,6 +3795,12 @@ export class CommandController extends Controller {
const eduHistory = new ProfileEducationHistory();
Object.assign(eduHistory, { ...profileEdu, id: undefined });
profileEdu.profileId = profile.id;
const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileId"],
where: { profileId: profile.id },
order: { level: "DESC" },
});
profileEdu.level = educationLevel == null ? 1 : educationLevel.level + 1;
await this.profileEducationRepo.save(profileEdu, { data: req });
setLogDataDiff(req, { before, after: profileEdu });
eduHistory.profileEducationId = profileEdu.id;

View file

@ -264,7 +264,7 @@ export class DPISController extends Controller {
dateLeaveStart: "ASC",
},
profileEducations: {
degree: "ASC",
level: "ASC",
},
},
});

View file

@ -42,7 +42,7 @@ import { HR_PERSONAL_EMP_FAMILY } from "../entities/HR_PERSONAL_EMP_FAMILY";
@Tags("UPLOAD")
@Security("bearerAuth")
export class ImportDataController extends Controller {
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple);
private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother);
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
@ -762,6 +762,12 @@ export class ImportDataController extends Controller {
select: ["CIT", "EDUCATION_CODE", "START_EDUCATION_YEAR", "EDUCATION_YEAR", "INSTITUE"],
});
const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileId"],
where: { profileId: _item.id },
order: { level: "DESC" },
});
// educations = await [];
await Promise.all(
existingProfile.map(async (item) => {
@ -781,6 +787,7 @@ export class ImportDataController extends Controller {
: null_;
// endDate = endDate ? new Date(endDate, 0, 1) : null_;
education.level = educationLevel == null ? 1 : educationLevel.level + 1;
education.profileId = _item.id;
education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
education.institute = item.INSTITUE;
@ -794,16 +801,16 @@ export class ImportDataController extends Controller {
education.lastUpdatedAt = new Date();
// await educations.push(await education);
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
await this.educationRepository.save(await education);
await this.profileEducationRepo.save(await education);
}),
);
// await this.educationRepository.save(educations);
// await this.profileEducationRepo.save(educations);
// educations = await [];
}),
);
// }
// console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
// await this.educationRepository.save(educations);
// await this.profileEducationRepo.save(educations);
return new HttpSuccess();
}
@ -838,6 +845,12 @@ export class ImportDataController extends Controller {
select: ["CIT", "EDUCATION_CODE", "START_EDUCATION_YEAR", "EDUCATION_YEAR", "INSTITUE"],
});
const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileId"],
where: { profileEmployeeId: _item.id },
order: { level: "DESC" },
});
educations = await [];
await Promise.all(
existingProfile.map(async (item) => {
@ -857,6 +870,7 @@ export class ImportDataController extends Controller {
: null_;
// endDate = endDate ? new Date(endDate, 0, 1) : null_;
education.level = educationLevel == null ? 1 : educationLevel.level + 1;
education.profileEmployeeId = _item.id;
education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
education.institute = item.INSTITUE;
@ -870,15 +884,15 @@ export class ImportDataController extends Controller {
education.lastUpdatedAt = new Date();
// educations.push(education);
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
await this.educationRepository.save(education);
await this.profileEducationRepo.save(education);
}),
);
// await this.educationRepository.save(educations);
// await this.profileEducationRepo.save(educations);
}),
);
// }
// console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
// await this.educationRepository.save(educations);
// await this.profileEducationRepo.save(educations);
return new HttpSuccess();
}

View file

@ -63,6 +63,13 @@ export class InsigniaController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
}
const _insignia = await this.insigniaRepository.findOne({
select: ["id", "level", "insigniaTypeId"],
where: { insigniaTypeId: requestBody.insigniaTypeId },
order: { level: "DESC" },
});
insignia.level = _insignia == null ? 1 : _insignia.level + 1;
insignia.createdUserId = request.user.sub;
insignia.createdFullName = request.user.name;
insignia.lastUpdateUserId = request.user.sub;
@ -131,6 +138,19 @@ export class InsigniaController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชอิสริยาภรณ์นี้");
}
await this.insigniaRepository.remove(delInsignia);
const insignia = await this.insigniaRepository.find({
select: ["id", "level", "insigniaTypeId"],
where: { insigniaTypeId: delInsignia.insigniaTypeId },
order: { level: "DESC" },
});
const sortLevel = insignia.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.insigniaRepository.save(sortLevel);
return new HttpSuccess();
}
@ -284,7 +304,7 @@ export class InsigniaController extends Controller {
}
const insignia = await this.insigniaRepository.find({
select: ["id", "level"],
select: ["id", "level", "insigniaTypeId"],
where: { insigniaTypeId: insigniaTypeId },
});

View file

@ -99,9 +99,8 @@ export class ProfileController extends Controller {
private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory);
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private profileEducationRepository = AppDataSource.getRepository(ProfileEducation);
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private provinceRepo = AppDataSource.getRepository(Province);
private districtRepo = AppDataSource.getRepository(District);
private subDistrictRepo = AppDataSource.getRepository(SubDistrict);
@ -254,10 +253,10 @@ export class ProfileController extends Controller {
},
];
const educations = await this.educationRepository.find({
const educations = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileId: id },
order: { startDate: "ASC" },
order: { level: "ASC" },
});
const Education =
educations && educations.length > 0
@ -544,11 +543,11 @@ export class ProfileController extends Controller {
},
];
const education_raw = await this.educationRepository.find({
const education_raw = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileId: id },
// order: { lastUpdatedAt: "DESC" },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
const educations =
education_raw.length > 0
@ -5590,7 +5589,7 @@ export class ProfileController extends Controller {
// order: "DESC",
// },
profileEducations: {
createdAt: "DESC",
level: "ASC",
},
},
});
@ -5772,7 +5771,7 @@ export class ProfileController extends Controller {
salary: profile ? profile.amount : null,
education:
profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}`
? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}`
: "-",
};
@ -5829,7 +5828,7 @@ export class ProfileController extends Controller {
@Get("citizenid/position/{id}")
async getProfileByCitizenId(@Request() request: RequestWithUser, @Path() id: string) {
const profile = await this.profileRepo.findOne({
where: { citizenId: id, isActive: true },
where: { citizenId: id, isActive: true, profileEducations: { isUse: true } },
relations: [
"posLevel",
"posType",
@ -5840,11 +5839,15 @@ export class ProfileController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
"profileSalary",
"profileEducations",
],
order: {
profileSalary: {
order: "DESC",
},
profileEducations: {
level: "ASC",
},
},
});
if (!profile) {
@ -5934,6 +5937,10 @@ export class ProfileController extends Controller {
amount: profile ? profile.amount : null,
positionSalaryAmount: profile ? profile.positionSalaryAmount : null,
mouthSalaryAmount: profile ? profile.mouthSalaryAmount : null,
education:
profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}`
: "",
};
if (_profile.child4Id != null) {
@ -5984,7 +5991,7 @@ export class ProfileController extends Controller {
],
order: {
profileEducations: {
createdAt: "DESC",
level: "ASC",
},
},
});
@ -6073,7 +6080,7 @@ export class ProfileController extends Controller {
salary: profile.amount,
education:
profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}`
? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}`
: "-",
};
@ -6396,9 +6403,9 @@ export class ProfileController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileId: item.id },
order: { endDate: "DESC" },
order: { level: "ASC" },
});
return {
@ -6444,28 +6451,6 @@ export class ProfileController extends Controller {
latestProfileEducation != null && latestProfileEducation.educationLevel != null
? latestProfileEducation.educationLevel
: null,
// ? {
// id: latestProfileEducation.id,
// degree: latestProfileEducation.degree,
// country: latestProfileEducation.country,
// duration: latestProfileEducation.duration,
// durationYear: latestProfileEducation.durationYear,
// field: latestProfileEducation.field,
// finishDate: latestProfileEducation.finishDate,
// fundName: latestProfileEducation.fundName,
// gpa: latestProfileEducation.gpa,
// institute: latestProfileEducation.institute,
// other: latestProfileEducation.other,
// startDate: latestProfileEducation.startDate,
// endDate: latestProfileEducation.endDate,
// educationLevel: latestProfileEducation.educationLevel,
// positionPath: latestProfileEducation.positionPath,
// positionPathId: latestProfileEducation.positionPathId,
// isDate: latestProfileEducation.isDate,
// isEducation: latestProfileEducation.isEducation,
// note: latestProfileEducation.note,
// }
// : null,
};
}),
);
@ -7922,9 +7907,9 @@ export class ProfileController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileId: item.id },
order: { endDate: "DESC" },
order: { level: "ASC" },
});
return {

View file

@ -44,7 +44,7 @@ export class ProfileEducationsController extends Controller {
}
const getProfileEducation = await this.profileEducationRepo.find({
where: { profileId: profile.id },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -59,7 +59,7 @@ export class ProfileEducationsController extends Controller {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileEducation = await this.profileEducationRepo.find({
where: { profileId: profileId },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -133,23 +133,18 @@ export class ProfileEducationsController extends Controller {
const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined });
const education = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileId"],
where: { profileId: body.profileId },
order: { level: "DESC" },
});
data.level = education == null ? 1 : education.level + 1;
await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
where: { profileId: body.profileId },
});
const sortLevel = education.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.profileEducationRepo.save(sortLevel);
return new HttpSuccess();
}
@ -187,17 +182,6 @@ export class ProfileEducationsController extends Controller {
// setLogDataDiff(req, { before: before_null, after: history }),
]);
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
where: { profileId: record.profileId },
});
const sortLevel = education.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.profileEducationRepo.save(sortLevel);
return new HttpSuccess();
}
@ -220,8 +204,9 @@ export class ProfileEducationsController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileId"],
where: { profileId: record?.profileId },
order: { level: "ASC" },
});
const sortLevel = education.map((data, i) => ({
@ -240,7 +225,10 @@ export class ProfileEducationsController extends Controller {
*
*/
@Put("sort/{profileId}")
async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) {
async Sort(
@Path() profileId: string,
@Body() requestBody: { data: { id: string; isUse: boolean }[] },
) {
const profile = await this.profileRepo.findOne({
where: { id: profileId },
});
@ -249,13 +237,14 @@ export class ProfileEducationsController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileId", "isUse"],
where: { profileId: profileId },
});
const sortLevel = education.map((data) => ({
id: data.id,
level: requestBody.id.indexOf(data.id) + 1,
level: requestBody.data.findIndex((x) => x.id == data.id) + 1,
isUse: requestBody.data.find((x) => x.id == data.id)?.isUse ?? false,
}));
await this.profileEducationRepo.save(sortLevel);

View file

@ -139,23 +139,18 @@ export class ProfileEducationsEmployeeController extends Controller {
const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined });
const education = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: body.profileEmployeeId },
order: { level: "DESC" },
});
data.level = education == null ? 1 : education.level + 1;
await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
where: { profileEmployeeId: body.profileEmployeeId },
});
const sortLevel = education.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.profileEducationRepo.save(sortLevel);
return new HttpSuccess();
}
@ -197,17 +192,6 @@ export class ProfileEducationsEmployeeController extends Controller {
setLogDataDiff(req, { before, after: history }),
]);
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
where: { profileEmployeeId: record.profileEmployeeId },
});
const sortLevel = education.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.profileEducationRepo.save(sortLevel);
return new HttpSuccess();
}
@ -236,8 +220,9 @@ export class ProfileEducationsEmployeeController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: _record?.profileEmployeeId },
order: { level: "ASC" },
});
const sortLevel = education.map((data, i) => ({
@ -256,7 +241,10 @@ export class ProfileEducationsEmployeeController extends Controller {
*
*/
@Put("sort/{profileId}")
async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) {
async Sort(
@Path() profileId: string,
@Body() requestBody: { data: { id: string; isUse: boolean }[] },
) {
const profile = await this.profileEmployeeRepo.findOne({
where: { id: profileId },
});
@ -265,13 +253,14 @@ export class ProfileEducationsEmployeeController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: profileId },
});
const sortLevel = education.map((data) => ({
id: data.id,
level: requestBody.id.indexOf(data.id) + 1,
level: requestBody.data.findIndex((x) => x.id == data.id) + 1,
isUse: requestBody.data.find((x) => x.id == data.id)?.isUse ?? false,
}));
await this.profileEducationRepo.save(sortLevel);

View file

@ -42,7 +42,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
}
const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profile.id },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -59,7 +59,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -129,22 +129,18 @@ export class ProfileEducationsEmployeeTempController extends Controller {
const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined });
const education = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: body.profileEmployeeId },
order: { level: "DESC" },
});
data.level = education == null ? 1 : education.level + 1;
await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
where: { profileEmployeeId: body.profileEmployeeId },
});
const sortLevel = education.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.profileEducationRepo.save(sortLevel);
return new HttpSuccess();
}
@ -182,17 +178,6 @@ export class ProfileEducationsEmployeeTempController extends Controller {
// setLogDataDiff(req, { before: before_null, after: history }),
]);
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
where: { profileEmployeeId: record.profileEmployeeId },
});
const sortLevel = education.map((data, i) => ({
id: data.id,
level: i + 1,
}));
await this.profileEducationRepo.save(sortLevel);
return new HttpSuccess();
}
@ -214,8 +199,9 @@ export class ProfileEducationsEmployeeTempController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: _record?.profileEmployeeId },
order: { level: "ASC" },
});
const sortLevel = education.map((data, i) => ({
@ -234,7 +220,10 @@ export class ProfileEducationsEmployeeTempController extends Controller {
*
*/
@Put("sort/{profileId}")
async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) {
async Sort(
@Path() profileId: string,
@Body() requestBody: { data: { id: string; isUse: boolean }[] },
) {
const profile = await this.profileEmployeeRepo.findOne({
where: { id: profileId },
});
@ -243,13 +232,14 @@ export class ProfileEducationsEmployeeTempController extends Controller {
}
const education = await this.profileEducationRepo.find({
select: ["id", "level"],
select: ["id", "level", "profileEmployeeId"],
where: { profileEmployeeId: profileId },
});
const sortLevel = education.map((data) => ({
id: data.id,
level: requestBody.id.indexOf(data.id) + 1,
level: requestBody.data.findIndex((x) => x.id == data.id) + 1,
isUse: requestBody.data.find((x) => x.id == data.id)?.isUse ?? false,
}));
await this.profileEducationRepo.save(sortLevel);

View file

@ -91,7 +91,6 @@ export class ProfileEmployeeController extends Controller {
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
@ -105,7 +104,7 @@ export class ProfileEmployeeController extends Controller {
private employmentHistoryRepository = AppDataSource.getRepository(
ProfileEmployeeEmploymentHistory,
);
private profileEducationRepository = AppDataSource.getRepository(ProfileEducation);
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
private positionRepository = AppDataSource.getRepository(Position);
@ -226,10 +225,10 @@ export class ProfileEmployeeController extends Controller {
let _child3 = child3 == null || child3 == undefined ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null || child4 == undefined ? "" : `${child4.orgChild4Name}/`;
const educations = await this.educationRepository.find({
const educations = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" },
order: { level: "ASC" },
});
const Education =
educations && educations.length > 0
@ -512,11 +511,11 @@ export class ProfileEmployeeController extends Controller {
},
];
const education_raw = await this.educationRepository.find({
const education_raw = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id },
// order: { lastUpdatedAt: "DESC" },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
const educations =
education_raw.length > 0
@ -2462,9 +2461,9 @@ export class ProfileEmployeeController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
order: { level: "ASC" },
});
return {
@ -2510,28 +2509,6 @@ export class ProfileEmployeeController extends Controller {
latestProfileEducation != null && latestProfileEducation.educationLevel != null
? latestProfileEducation.educationLevel
: null,
// ? {
// id: latestProfileEducation.id,
// degree: latestProfileEducation.degree,
// country: latestProfileEducation.country,
// duration: latestProfileEducation.duration,
// durationYear: latestProfileEducation.durationYear,
// field: latestProfileEducation.field,
// finishDate: latestProfileEducation.finishDate,
// fundName: latestProfileEducation.fundName,
// gpa: latestProfileEducation.gpa,
// institute: latestProfileEducation.institute,
// other: latestProfileEducation.other,
// startDate: latestProfileEducation.startDate,
// endDate: latestProfileEducation.endDate,
// educationLevel: latestProfileEducation.educationLevel,
// positionPath: latestProfileEducation.positionPath,
// positionPathId: latestProfileEducation.positionPathId,
// isDate: latestProfileEducation.isDate,
// isEducation: latestProfileEducation.isEducation,
// note: latestProfileEducation.note,
// }
// : null,
};
}),
);
@ -4103,9 +4080,9 @@ export class ProfileEmployeeController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
order: { level: "ASC" },
});
return {
@ -4169,7 +4146,7 @@ export class ProfileEmployeeController extends Controller {
// order: "DESC",
// },
profileEducations: {
createdAt: "DESC",
level: "ASC",
},
},
});
@ -4295,7 +4272,7 @@ export class ProfileEmployeeController extends Controller {
salary: profile.amount,
education:
profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}`
? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}`
: "-",
};

View file

@ -90,7 +90,6 @@ export class ProfileEmployeeTempController extends Controller {
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
@ -104,7 +103,7 @@ export class ProfileEmployeeTempController extends Controller {
private employmentHistoryRepository = AppDataSource.getRepository(
ProfileEmployeeEmploymentHistory,
);
private profileEducationRepository = AppDataSource.getRepository(ProfileEducation);
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
/**
@ -223,10 +222,10 @@ export class ProfileEmployeeTempController extends Controller {
let _child3 = child3 == null || child3 == undefined ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null || child4 == undefined ? "" : `${child4.orgChild4Name}/`;
const educations = await this.educationRepository.find({
const educations = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" },
order: { level: "ASC" },
});
const Education =
educations && educations.length > 0
@ -509,11 +508,11 @@ export class ProfileEmployeeTempController extends Controller {
},
];
const education_raw = await this.educationRepository.find({
const education_raw = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id },
// order: { lastUpdatedAt: "DESC" },
order: { createdAt: "ASC" },
order: { level: "ASC" },
});
const educations =
education_raw.length > 0
@ -2027,9 +2026,9 @@ export class ProfileEmployeeTempController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
order: { level: "ASC" },
});
return {
@ -2075,28 +2074,6 @@ export class ProfileEmployeeTempController extends Controller {
latestProfileEducation != null && latestProfileEducation.educationLevel != null
? latestProfileEducation.educationLevel
: null,
// ? {
// id: latestProfileEducation.id,
// degree: latestProfileEducation.degree,
// country: latestProfileEducation.country,
// duration: latestProfileEducation.duration,
// durationYear: latestProfileEducation.durationYear,
// field: latestProfileEducation.field,
// finishDate: latestProfileEducation.finishDate,
// fundName: latestProfileEducation.fundName,
// gpa: latestProfileEducation.gpa,
// institute: latestProfileEducation.institute,
// other: latestProfileEducation.other,
// startDate: latestProfileEducation.startDate,
// endDate: latestProfileEducation.endDate,
// educationLevel: latestProfileEducation.educationLevel,
// positionPath: latestProfileEducation.positionPath,
// positionPathId: latestProfileEducation.positionPathId,
// isDate: latestProfileEducation.isDate,
// isEducation: latestProfileEducation.isEducation,
// note: latestProfileEducation.note,
// }
// : null,
};
}),
);
@ -3556,9 +3533,9 @@ export class ProfileEmployeeTempController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
order: { level: "ASC" },
});
return {
@ -3619,7 +3596,7 @@ export class ProfileEmployeeTempController extends Controller {
],
order: {
profileEducations: {
createdAt: "DESC",
level: "ASC",
},
},
});
@ -3744,7 +3721,7 @@ export class ProfileEmployeeTempController extends Controller {
salary: profile.amount,
education:
profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""}/${profile.profileEducations[0].field ?? ""}`
? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}`
: "-",
};

View file

@ -161,6 +161,13 @@ export class ProfileEducation extends EntityBase {
})
isEducation: boolean;
@Column({
nullable: true,
comment: "ใช้ประวัติการศึกษา",
default: null,
})
isUse: boolean;
@Column({
nullable: true,
length: 40,