Merge branch 'develop' into task/#1542

This commit is contained in:
Adisak 2026-02-13 09:30:06 +07:00
commit 74b2694aef
90 changed files with 1027 additions and 333 deletions

View file

@ -99,6 +99,7 @@ import {
CreatePosMasterHistoryOfficer, CreatePosMasterHistoryOfficer,
} from "../services/PositionService"; } from "../services/PositionService";
import { PostRetireToExprofile } from "./ExRetirementController"; import { PostRetireToExprofile } from "./ExRetirementController";
import { LeaveType } from "../entities/LeaveType"
@Route("api/v1/org/command") @Route("api/v1/org/command")
@Tags("Command") @Tags("Command")
@Security("bearerAuth") @Security("bearerAuth")
@ -154,7 +155,7 @@ export class CommandController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private genderRepo = AppDataSource.getRepository(Gender); private genderRepo = AppDataSource.getRepository(Gender);
private avatarRepository = AppDataSource.getRepository(ProfileAvatar); private avatarRepository = AppDataSource.getRepository(ProfileAvatar);
private leaveType = AppDataSource.getRepository(LeaveType);
/** /**
* API list * API list
* *
@ -5766,10 +5767,15 @@ export class CommandController extends Controller {
) { ) {
let _posNumCodeSit: string = ""; let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = ""; let _posNumCodeSitAbb: string = "";
let commandType: any = ""
const _command = await this.commandRepository.findOne({ const _command = await this.commandRepository.findOne({
where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" },
}); });
if (_command) { if (_command) {
commandType = await this.commandTypeRepository.findOne({
select: { code: true },
where: { id: _command.commandTypeId }
});
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
const orgRootDeputy = await this.orgRootRepository.findOne({ const orgRootDeputy = await this.orgRootRepository.findOne({
where: { where: {
@ -5807,11 +5813,15 @@ export class CommandController extends Controller {
.orgRootShortName ?? ""; .orgRootShortName ?? "";
} }
} }
const leaveType = await this.leaveType.findOne({
select:{ id: true, limit: true, code: true },
where:{ code: "LV-005" }
});
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
relations: [ relations: [
"profileSalary", // "profileSalary",
"posType", "posType",
"posLevel", "posLevel",
"current_holders", "current_holders",
@ -5822,16 +5832,21 @@ export class CommandController extends Controller {
"current_holders.orgChild4", "current_holders.orgChild4",
], ],
where: { id: item.profileId }, where: { id: item.profileId },
order: { // order: {
profileSalary: { // profileSalary: {
order: "DESC", // order: "DESC",
}, // },
}, // },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
const lastSalary = await this.salaryRepo.findOne({
where: { profileId: item.profileId },
select: ["order"],
order: { order: "DESC" },
});
const nextOrder = lastSalary ? lastSalary.order + 1 : 1;
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
@ -5892,12 +5907,13 @@ export class CommandController extends Controller {
amountSpecial: item.amountSpecial ? item.amountSpecial : null, amountSpecial: item.amountSpecial ? item.amountSpecial : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
order: // order:
profile.profileSalary.length >= 0 // profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 // ? profile.profileSalary.length > 0
? profile.profileSalary[0].order + 1 // ? profile.profileSalary[0].order + 1
: 1 // : 1
: null, // : null,
order: nextOrder,
orgRoot: orgRootRef?.orgRootName ?? null, orgRoot: orgRootRef?.orgRootName ?? null,
orgChild1: orgChild1Ref?.orgChild1Name ?? null, orgChild1: orgChild1Ref?.orgChild1Name ?? null,
orgChild2: orgChild2Ref?.orgChild2Name ?? null, orgChild2: orgChild2Ref?.orgChild2Name ?? null,
@ -5928,19 +5944,41 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history); await this.salaryHistoryRepo.save(history);
}), }),
); );
const checkCommandType = await this.commandRepository.findOne({ // const checkCommandType = await this.commandRepository.findOne({
where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" }, // where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" },
relations: ["commandType"], // relations: ["commandType"],
}); // });
if (checkCommandType?.commandType.code == "C-PM-11") { if (commandType && String(commandType.code) == "C-PM-11") {
const profile = await this.profileRepository.find({ // const profile = await this.profileRepository.find({
where: { id: In(body.data.map((x) => x.profileId)) }, // where: { id: In(body.data.map((x) => x.profileId)) },
}); // });
const data = profile.map((x) => ({ // const data = profile.map((x) => ({
...x, // ...x,
isProbation: false, // isProbation: false,
})); // }));
await this.profileRepository.save(data); // await this.profileRepository.save(data);
const profileIds = body.data.map((x) => x.profileId);
await this.profileRepository.update(
{ id: In(profileIds) },
{ isProbation: false }
);
// Task #2304 อัปเดตจำนวนสิทธิ์การลา เมื่อผ่านทดลองงานฯ
if (leaveType != null) {
await Promise.all(
body.data.map((item) =>
new CallAPI().PutData(req, `/leave-beginning/schedule`, {
profileId: item.profileId,
leaveTypeId: leaveType.id,
leaveYear: item.commandYear,
leaveDays: leaveType.limit,
leaveDaysUsed: 0,
leaveCount: 0,
beginningLeaveDays: 0,
beginningLeaveCount: 0,
})
)
);
}
} }
return new HttpSuccess(); return new HttpSuccess();
} }
@ -6461,7 +6499,7 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history, { data: req }); await this.salaryHistoryRepo.save(history, { data: req });
if (profileEmployee.profileInsignias.length > 0) { if (profileEmployee.profileInsignias.length > 0) {
_oldInsigniaIds = profileEmployee.profileInsignias.map((x: any) => x.id); _oldInsigniaIds = profileEmployee.profileInsignias.filter().map((x: any) => x.id);
} }
await removeProfileInOrganize(profileEmployee.id, "EMPLOYEE"); await removeProfileInOrganize(profileEmployee.id, "EMPLOYEE");
if (profileEmployee.keycloak != null) { if (profileEmployee.keycloak != null) {
@ -6679,7 +6717,7 @@ export class CommandController extends Controller {
profileEdu.profileId = profile.id; profileEdu.profileId = profile.id;
const educationLevel = await this.profileEducationRepo.findOne({ const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileId"], select: ["id", "level", "profileId"],
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { level: "DESC" }, order: { level: "DESC" },
}); });
profileEdu.level = educationLevel == null ? 1 : educationLevel.level + 1; profileEdu.level = educationLevel == null ? 1 : educationLevel.level + 1;
@ -6871,7 +6909,7 @@ export class CommandController extends Controller {
// Insignia // Insignia
if (_oldInsigniaIds.length > 0) { if (_oldInsigniaIds.length > 0) {
const _insignias = await this.insigniaRepo.find({ const _insignias = await this.insigniaRepo.find({
where: { id: In(_oldInsigniaIds) }, where: { id: In(_oldInsigniaIds), isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
for (const oldInsignia of _insignias) { for (const oldInsignia of _insignias) {

View file

@ -2475,8 +2475,8 @@ export class ImportDataController extends Controller {
}); });
const educationLevel = await this.profileEducationRepo.findOne({ const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileId"], select: ["id", "level", "profileId", "isDeleted"],
where: { profileId: _item.id }, where: { profileId: _item.id, isDeleted: false },
order: { level: "DESC" }, order: { level: "DESC" },
}); });
@ -2607,8 +2607,8 @@ export class ImportDataController extends Controller {
}); });
const educationLevel = await this.profileEducationRepo.findOne({ const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileEmployeeId"], select: ["id", "level", "profileEmployeeId", "isDeleted"],
where: { profileEmployeeId: _item.id }, where: { profileEmployeeId: _item.id, isDeleted: false },
order: { level: "DESC" }, order: { level: "DESC" },
}); });
@ -2740,8 +2740,8 @@ export class ImportDataController extends Controller {
}); });
const educationLevel = await this.profileEducationRepo.findOne({ const educationLevel = await this.profileEducationRepo.findOne({
select: ["id", "level", "profileEmployeeId"], select: ["id", "level", "profileEmployeeId", "isDeleted"],
where: { profileEmployeeId: _item.id }, where: { profileEmployeeId: _item.id, isDeleted: false },
order: { level: "DESC" }, order: { level: "DESC" },
}); });
@ -5799,7 +5799,7 @@ export class ImportDataController extends Controller {
}, },
}); });
const eduLevel = await this.profileEducationRepo.findOne({ const eduLevel = await this.profileEducationRepo.findOne({
where: { profileId: _item.id }, where: { profileId: _item.id, isDeleted: false },
order: { order: {
startDate: "DESC", startDate: "DESC",
}, },

View file

@ -204,6 +204,9 @@ export class OrgChild1Controller {
child1.orgChild1Order = child1.orgChild1Order =
order == null || order.orgChild1Order == null ? 1 : order.orgChild1Order + 1; order == null || order.orgChild1Order == null ? 1 : order.orgChild1Order + 1;
await this.child1Repository.save(child1, { data: request }); await this.child1Repository.save(child1, { data: request });
// update ancestorDNA = id row
child1.ancestorDNA = child1.id;
await this.child1Repository.save(child1, { data: request });
setLogDataDiff(request, { before, after: child1 }); setLogDataDiff(request, { before, after: child1 });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -164,6 +164,9 @@ export class OrgChild2Controller extends Controller {
child2.orgChild2Order = child2.orgChild2Order =
order == null || order.orgChild2Order == null ? 1 : order.orgChild2Order + 1; order == null || order.orgChild2Order == null ? 1 : order.orgChild2Order + 1;
await this.child2Repository.save(child2, { data: request }); await this.child2Repository.save(child2, { data: request });
// update ancestorDNA = id row
child2.ancestorDNA = child2.id;
await this.child2Repository.save(child2, { data: request });
setLogDataDiff(request, { before, after: child2 }); setLogDataDiff(request, { before, after: child2 });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -132,6 +132,9 @@ export class OrgChild3Controller {
child3.orgChild3Order = child3.orgChild3Order =
order == null || order.orgChild3Order == null ? 1 : order.orgChild3Order + 1; order == null || order.orgChild3Order == null ? 1 : order.orgChild3Order + 1;
await this.child3Repository.save(child3, { data: request }); await this.child3Repository.save(child3, { data: request });
// update ancestorDNA = id row
child3.ancestorDNA = child3.id;
await this.child3Repository.save(child3, { data: request });
setLogDataDiff(request, { before, after: child3 }); setLogDataDiff(request, { before, after: child3 });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -163,6 +163,9 @@ export class OrgChild4Controller extends Controller {
child4.orgChild4Order = child4.orgChild4Order =
order == null || order.orgChild4Order == null ? 1 : order.orgChild4Order + 1; order == null || order.orgChild4Order == null ? 1 : order.orgChild4Order + 1;
await this.child4Repository.save(child4, { data: request }); await this.child4Repository.save(child4, { data: request });
// update ancestorDNA = id row
child4.ancestorDNA = child4.id;
await this.child4Repository.save(child4, { data: request });
setLogDataDiff(request, { before, after: child4 }); setLogDataDiff(request, { before, after: child4 });
return new HttpSuccess(); return new HttpSuccess();

View file

@ -203,6 +203,9 @@ export class OrgRootController extends Controller {
orgRoot.lastUpdatedAt = new Date(); orgRoot.lastUpdatedAt = new Date();
orgRoot.orgRootOrder = order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1; orgRoot.orgRootOrder = order == null || order.orgRootOrder == null ? 1 : order.orgRootOrder + 1;
await this.orgRootRepository.save(orgRoot, { data: request }); await this.orgRootRepository.save(orgRoot, { data: request });
// update ancestorDNA = id row
orgRoot.ancestorDNA = orgRoot.id;
await this.orgRootRepository.save(orgRoot, { data: request });
setLogDataDiff(request, { before, after: orgRoot }); setLogDataDiff(request, { before, after: orgRoot });
return new HttpSuccess(); return new HttpSuccess();

View file

@ -53,11 +53,13 @@ import {
} from "../keycloak"; } from "../keycloak";
// import { getPositionCounts, getCounts, getRootCounts } from "../services/OrganizationService"; // import { getPositionCounts, getCounts, getRootCounts } from "../services/OrganizationService";
import { import {
BatchSavePosMasterHistoryOfficer,
CreatePosMasterHistoryEmployee, CreatePosMasterHistoryEmployee,
CreatePosMasterHistoryOfficer, CreatePosMasterHistoryOfficer,
SavePosMasterHistoryOfficer,
} from "../services/PositionService"; } from "../services/PositionService";
import { orgStructureCache } from "../utils/OrgStructureCache"; import { orgStructureCache } from "../utils/OrgStructureCache";
import { OrgIdMapping, AllOrgMappings } from "../interfaces/OrgMapping"; import { OrgIdMapping, AllOrgMappings, SavePosMasterHistory } from "../interfaces/OrgMapping";
@Route("api/v1/org") @Route("api/v1/org")
@Tags("Organization") @Tags("Organization")
@ -7930,13 +7932,13 @@ export class OrganizationController extends Controller {
const currentRevisionId = currentRevision.id; const currentRevisionId = currentRevision.id;
// ตรวจสอบว่ามี rootDnaId ในโครงสร้างร่าง และในโครงสร้างปัจจุบันหรือไม่ // ตรวจสอบว่ามี rootDnaId ในโครงสร้างร่าง และในโครงสร้างปัจจุบันหรือไม่
const [orgRootDraft, orgRootCurrent] = await Promise.all([ let [orgRootDraft, orgRootCurrent] = await Promise.all([
this.orgRootRepository.findOne({ this.orgRootRepository.findOne({
where: { where: {
ancestorDNA: rootDnaId, ancestorDNA: rootDnaId,
orgRevisionId: drafRevisionId, orgRevisionId: drafRevisionId,
}, },
select: ["id"], // select: ["id"],
}), }),
this.orgRootRepository.findOne({ this.orgRootRepository.findOne({
where: { where: {
@ -7948,8 +7950,23 @@ export class OrganizationController extends Controller {
]); ]);
if (!orgRootDraft) return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างร่าง"); if (!orgRootDraft) return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างร่าง");
// if current record not found, create new one
if (!orgRootCurrent) {
// Create new current record using draft's ID
const newCurrentRoot = queryRunner.manager.create(OrgRoot, {
...orgRootDraft,
id: undefined, // Let database generate new ID
orgRevisionId: currentRevisionId, // Change to current revision
});
const savedRoot = await queryRunner.manager.save(OrgRoot, newCurrentRoot);
orgRootCurrent = savedRoot; // Use saved record for sync
}
// Part 1: Differential sync of organization structure (bottom-up) // Part 1: Differential sync of organization structure (bottom-up)
// Build mapping incrementally as we process each level // Build mapping incrementally as we process each level
const allMappings: AllOrgMappings = { const allMappings: AllOrgMappings = {
orgRoot: { byAncestorDNA: new Map(), byDraftId: new Map() }, orgRoot: { byAncestorDNA: new Map(), byDraftId: new Map() },
orgChild1: { byAncestorDNA: new Map(), byDraftId: new Map() }, orgChild1: { byAncestorDNA: new Map(), byDraftId: new Map() },
@ -7964,7 +7981,29 @@ export class OrganizationController extends Controller {
// Process from top (Root) to bottom (Child4) to handle foreign key constraints // Process from top (Root) to bottom (Child4) to handle foreign key constraints
// OrgRoot (sync first - no parent dependencies) // OrgRoot (sync first - no parent dependencies)
const orgRootResult = await this.syncOrgLevel( // If we manually created orgRootCurrent, skip syncOrgLevel and set up mapping directly
// to avoid double insert (syncOrgLevel would try to insert again because IDs don't match)
let orgRootResult: {
mapping: OrgIdMapping;
counts: { deleted: number; updated: number; inserted: number };
};
if (
orgRootCurrent &&
orgRootDraft &&
orgRootCurrent.ancestorDNA === orgRootDraft.ancestorDNA
) {
// Manually created - set up mapping directly
const rootMapping: OrgIdMapping = {
byAncestorDNA: new Map([[orgRootDraft.ancestorDNA, orgRootCurrent.id]]),
byDraftId: new Map([[orgRootDraft.id, orgRootCurrent.id]]),
};
orgRootResult = {
mapping: rootMapping,
counts: { deleted: 0, updated: 0, inserted: 1 }, // Count as insert since we created it
};
} else {
// Not manually created - use normal syncOrgLevel flow
orgRootResult = await this.syncOrgLevel(
queryRunner, queryRunner,
OrgRoot, OrgRoot,
this.orgRootRepository, this.orgRootRepository,
@ -7974,6 +8013,7 @@ export class OrganizationController extends Controller {
orgRootDraft?.id, orgRootDraft?.id,
orgRootCurrent?.id, orgRootCurrent?.id,
); );
}
allMappings.orgRoot = orgRootResult.mapping; allMappings.orgRoot = orgRootResult.mapping;
orgSyncStats.orgRoot = orgRootResult.counts; orgSyncStats.orgRoot = orgRootResult.counts;
@ -8061,9 +8101,28 @@ export class OrganizationController extends Controller {
// Clear current_holderId for positions that will have new holders // Clear current_holderId for positions that will have new holders
const nextHolderIds = posMasterDraft const nextHolderIds = posMasterDraft
.filter((x) => x.next_holderId != null) .filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId); .map((x) => x.next_holderId) as string[];
if (nextHolderIds.length > 0) { if (nextHolderIds.length > 0) {
// FIX: Fetch positions first before updating (to avoid race condition)
const posMastersToUpdate = await queryRunner.manager.find(PosMaster, {
where: {
orgRevisionId: currentRevisionId,
current_holderId: In(nextHolderIds),
},
});
// Save history BEFORE clearing current_holderId
const historyOps = posMastersToUpdate
.filter((x) => x.orgRootId != orgRootCurrent?.id)
.map((pos) => ({
posMasterDnaId: pos.ancestorDNA,
profileId: null,
pm: null,
}));
await BatchSavePosMasterHistoryOfficer(queryRunner, historyOps);
// Now clear current_holderId
await queryRunner.manager.update( await queryRunner.manager.update(
PosMaster, PosMaster,
{ {
@ -8110,6 +8169,13 @@ export class OrganizationController extends Controller {
// Then delete posMaster records // Then delete posMaster records
await queryRunner.manager.delete(PosMaster, toDeleteIds); await queryRunner.manager.delete(PosMaster, toDeleteIds);
const deleteHistoryOps = toDelete.map((pos) => ({
posMasterDnaId: pos.ancestorDNA,
profileId: null,
pm: null,
}));
await BatchSavePosMasterHistoryOfficer(queryRunner, deleteHistoryOps);
} }
// 2.4 Process draft positions (UPDATE or INSERT) // 2.4 Process draft positions (UPDATE or INSERT)
@ -8160,6 +8226,10 @@ export class OrganizationController extends Controller {
}); });
toUpdate.push(current); toUpdate.push(current);
if (draftPos.next_holderId === null) {
await SavePosMasterHistoryOfficer(queryRunner, draftPos.ancestorDNA, null, null);
}
// Track mapping for position sync // Track mapping for position sync
posMasterMapping.set(draftPos.id, [current.id, draftPos.next_holderId]); posMasterMapping.set(draftPos.id, [current.id, draftPos.next_holderId]);
} else { } else {
@ -8176,6 +8246,7 @@ export class OrganizationController extends Controller {
current_holderId: draftPos.next_holderId, current_holderId: draftPos.next_holderId,
statusReport: "DONE", statusReport: "DONE",
}); });
toInsert.push(newPosMaster); toInsert.push(newPosMaster);
} }
} }
@ -8231,6 +8302,11 @@ export class OrganizationController extends Controller {
console.error("Error moving draft to current:", error); console.error("Error moving draft to current:", error);
await queryRunner.rollbackTransaction(); await queryRunner.rollbackTransaction();
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาดในการย้ายโครงสร้าง"); throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาดในการย้ายโครงสร้าง");
} finally {
if (queryRunner.isTransactionActive) {
await queryRunner.rollbackTransaction();
}
await queryRunner.release();
} }
} }
@ -8499,107 +8575,6 @@ export class OrganizationController extends Controller {
}; };
} }
/**
* Helper function: Sync positions for a PosMaster
* Handles DELETE/UPDATE/INSERT for positions associated with a posMaster
*
* @deprecated Kept as fallback - use syncAllPositionsBatch for better performance
*/
private async syncPositionsForPosMaster(
queryRunner: any,
draftPosMasterId: string,
currentPosMasterId: string,
_draftRevisionId: string,
_currentRevisionId: string,
nextHolderId: string | null | undefined,
): Promise<{ deleted: number; updated: number; inserted: number }> {
// Fetch draft and current positions for this posMaster
const [draftPositions, currentPositions] = await Promise.all([
queryRunner.manager.find(Position, {
where: {
posMasterId: draftPosMasterId,
},
order: { orderNo: "ASC" },
}),
queryRunner.manager.find(Position, {
where: {
posMasterId: currentPosMasterId,
},
}),
]);
// If no draft positions, delete all current positions
if (draftPositions.length === 0) {
if (currentPositions.length > 0) {
await queryRunner.manager.delete(
Position,
currentPositions.map((p: any) => p.id),
);
}
return { deleted: currentPositions.length, updated: 0, inserted: 0 };
}
// Build maps for tracking
const currentByOrderNo = new Map(currentPositions.map((p: any) => [p.orderNo, p]));
// DELETE: Current positions not in draft (by orderNo)
const draftOrderNos = new Set(draftPositions.map((p: any) => p.orderNo));
const toDelete = currentPositions.filter((p: any) => !draftOrderNos.has(p.orderNo));
if (toDelete.length > 0) {
await queryRunner.manager.delete(
Position,
toDelete.map((p: any) => p.id),
);
}
// UPDATE and INSERT
let updatedCount = 0;
let insertedCount = 0;
for (const draftPos of draftPositions) {
const current: any = currentByOrderNo.get(draftPos.orderNo);
if (current) {
// UPDATE existing position
await queryRunner.manager.update(Position, current.id, {
positionName: draftPos.positionName,
positionField: draftPos.positionField,
posTypeId: draftPos.posTypeId,
posLevelId: draftPos.posLevelId,
posExecutiveId: draftPos.posExecutiveId,
positionExecutiveField: draftPos.positionExecutiveField,
positionArea: draftPos.positionArea,
isSpecial: draftPos.isSpecial,
orderNo: draftPos.orderNo,
positionIsSelected: draftPos.positionIsSelected,
lastUpdateFullName: draftPos.lastUpdateFullName,
lastUpdatedAt: new Date(),
});
updatedCount++;
} else {
// INSERT new position
const newPosition = queryRunner.manager.create(Position, {
...draftPos,
id: undefined,
posMasterId: currentPosMasterId,
});
await queryRunner.manager.save(newPosition);
insertedCount++;
}
// update profile
if (nextHolderId != null && draftPos.positionIsSelected) {
await queryRunner.manager.update(Profile, nextHolderId, {
position: draftPos.positionName,
posTypeId: draftPos.posTypeId,
posLevelId: draftPos.posLevelId,
});
}
}
return { deleted: toDelete.length, updated: updatedCount, inserted: insertedCount };
}
/** /**
* Batch version: Sync positions for ALL posMasters in a single operation * Batch version: Sync positions for ALL posMasters in a single operation
* This significantly reduces database round trips for large organizations * This significantly reduces database round trips for large organizations
@ -8612,18 +8587,27 @@ export class OrganizationController extends Controller {
): Promise<{ deleted: number; updated: number; inserted: number }> { ): Promise<{ deleted: number; updated: number; inserted: number }> {
// Extract draft and current posMaster IDs // Extract draft and current posMaster IDs
const draftPosMasterIds = Array.from(posMasterMapping.keys()); const draftPosMasterIds = Array.from(posMasterMapping.keys());
const currentPosMasterIds = Array.from(posMasterMapping.values()).map(([currentId]) => currentId); const currentPosMasterIds = Array.from(posMasterMapping.values()).map(
([currentId]) => currentId,
);
if (draftPosMasterIds.length === 0) { if (draftPosMasterIds.length === 0) {
return { deleted: 0, updated: 0, inserted: 0 }; return { deleted: 0, updated: 0, inserted: 0 };
} }
// Fetch draft PosMasters with relations for history tracking
const draftPosMasters = await queryRunner.manager.find(PosMaster, {
where: { id: In(draftPosMasterIds) },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", "next_holder"],
});
// Fetch ALL positions for ALL posMasters in just 2 queries // Fetch ALL positions for ALL posMasters in just 2 queries
const [allDraftPositions, allCurrentPositions] = await Promise.all([ const [allDraftPositions, allCurrentPositions] = await Promise.all([
queryRunner.manager.find(Position, { queryRunner.manager.find(Position, {
where: { where: {
posMasterId: In(draftPosMasterIds), posMasterId: In(draftPosMasterIds),
}, },
relations: ["posType", "posLevel", "posExecutive"],
order: { orderNo: "ASC" }, order: { orderNo: "ASC" },
}), }),
queryRunner.manager.find(Position, { queryRunner.manager.find(Position, {
@ -8652,10 +8636,21 @@ export class OrganizationController extends Controller {
// Collect all operations // Collect all operations
const allToDelete: string[] = []; const allToDelete: string[] = [];
const allToDeleteHistory: string[] = [];
const allToUpdate: Array<{ id: string; data: any }> = []; const allToUpdate: Array<{ id: string; data: any }> = [];
const allToInsert: Array<any> = []; const allToInsert: Array<any> = [];
const profileUpdates: Map<string, any> = new Map(); const profileUpdates: Map<string, any> = new Map();
// Create a map for quick lookup of draft PosMasters with relations
const draftPosMasterMap = new Map(draftPosMasters.map((pm: PosMaster) => [pm.id, pm]));
// Collect PosMasterHistory calls for selected positions
const historyCalls: Array<{
ancestorDNA: string;
profileId: string | null;
historyData: SavePosMasterHistory;
}> = [];
// Process each posMaster mapping // Process each posMaster mapping
for (const [draftPosMasterId, [currentPosMasterId, nextHolderId]] of posMasterMapping) { for (const [draftPosMasterId, [currentPosMasterId, nextHolderId]] of posMasterMapping) {
const draftPositions = draftPositionsByMaster.get(draftPosMasterId) || []; const draftPositions = draftPositionsByMaster.get(draftPosMasterId) || [];
@ -8664,6 +8659,7 @@ export class OrganizationController extends Controller {
// If no draft positions, mark all current positions for deletion // If no draft positions, mark all current positions for deletion
if (draftPositions.length === 0) { if (draftPositions.length === 0) {
allToDelete.push(...currentPositions.map((p: any) => p.id)); allToDelete.push(...currentPositions.map((p: any) => p.id));
allToDeleteHistory.push(...currentPositions.map((p: any) => p.ancestorDNA));
continue; continue;
} }
@ -8675,6 +8671,7 @@ export class OrganizationController extends Controller {
for (const currentPos of currentPositions) { for (const currentPos of currentPositions) {
if (!draftOrderNos.has(currentPos.orderNo)) { if (!draftOrderNos.has(currentPos.orderNo)) {
allToDelete.push(currentPos.id); allToDelete.push(currentPos.id);
allToDeleteHistory.push(currentPos.ancestorDNA);
} }
} }
@ -8717,6 +8714,44 @@ export class OrganizationController extends Controller {
posTypeId: draftPos.posTypeId, posTypeId: draftPos.posTypeId,
posLevelId: draftPos.posLevelId, posLevelId: draftPos.posLevelId,
}); });
// Collect history data for the selected position
const draftPosMaster = draftPosMasterMap.get(draftPosMasterId) as any;
if (draftPosMaster && draftPosMaster.ancestorDNA) {
// Find the selected position from draft positions
const selectedPos =
draftPositions.find((p) => p.positionIsSelected === true) || draftPos;
historyCalls.push({
ancestorDNA: draftPosMaster.ancestorDNA,
profileId: nextHolderId,
historyData: {
prefix: draftPosMaster.next_holder?.prefix ?? null,
firstName: draftPosMaster.next_holder?.firstName ?? null,
lastName: draftPosMaster.next_holder?.lastName ?? null,
position: selectedPos.positionName ?? null,
posType: (selectedPos as any).posType?.posTypeName ?? null,
posLevel: (selectedPos as any).posLevel?.posLevelName ?? null,
posExecutive: (selectedPos as any).posExecutive?.posExecutiveName ?? null,
profileId: nextHolderId,
rootDnaId: draftPosMaster.orgRoot?.ancestorDNA ?? null,
child1DnaId: draftPosMaster.orgChild1?.ancestorDNA ?? null,
child2DnaId: draftPosMaster.orgChild2?.ancestorDNA ?? null,
child3DnaId: draftPosMaster.orgChild3?.ancestorDNA ?? null,
child4DnaId: draftPosMaster.orgChild4?.ancestorDNA ?? null,
shortName:
[
draftPosMaster.orgChild4?.orgChild4ShortName,
draftPosMaster.orgChild3?.orgChild3ShortName,
draftPosMaster.orgChild2?.orgChild2ShortName,
draftPosMaster.orgChild1?.orgChild1ShortName,
draftPosMaster.orgRoot?.orgRootShortName,
].find((s) => typeof s === "string" && s.trim().length > 0) ?? null,
posMasterNoPrefix: draftPosMaster.posMasterNoPrefix ?? null,
posMasterNo: draftPosMaster.posMasterNo ?? null,
posMasterNoSuffix: draftPosMaster.posMasterNoSuffix ?? null,
},
});
}
} }
} }
} }
@ -8729,16 +8764,22 @@ export class OrganizationController extends Controller {
// Bulk DELETE // Bulk DELETE
if (allToDelete.length > 0) { if (allToDelete.length > 0) {
await queryRunner.manager.delete(Position, allToDelete); await queryRunner.manager.delete(Position, allToDelete);
const deleteOps = allToDeleteHistory.map((ancestorDNA) => ({
posMasterDnaId: ancestorDNA,
profileId: null,
pm: null,
}));
await BatchSavePosMasterHistoryOfficer(queryRunner, deleteOps);
deletedCount = allToDelete.length; deletedCount = allToDelete.length;
} }
// Bulk UPDATE (batch by 500 to avoid query size limits) // Bulk UPDATE (batch by 100 to avoid query size limits)
if (allToUpdate.length > 0) { if (allToUpdate.length > 0) {
const batchSize = 500; const batchSize = 100;
for (let i = 0; i < allToUpdate.length; i += batchSize) { for (let i = 0; i < allToUpdate.length; i += batchSize) {
const batch = allToUpdate.slice(i, i + batchSize); const batch = allToUpdate.slice(i, i + batchSize);
await Promise.all( await Promise.all(
batch.map(({ id, data }) => queryRunner.manager.update(Position, id, data)) batch.map(({ id, data }) => queryRunner.manager.update(Position, id, data)),
); );
} }
updatedCount = allToUpdate.length; updatedCount = allToUpdate.length;
@ -8746,7 +8787,7 @@ export class OrganizationController extends Controller {
// Bulk INSERT // Bulk INSERT
if (allToInsert.length > 0) { if (allToInsert.length > 0) {
const batchSize = 500; const batchSize = 100;
for (let i = 0; i < allToInsert.length; i += batchSize) { for (let i = 0; i < allToInsert.length; i += batchSize) {
const batch = allToInsert.slice(i, i + batchSize); const batch = allToInsert.slice(i, i + batchSize);
await queryRunner.manager.save(Position, batch); await queryRunner.manager.save(Position, batch);
@ -8759,8 +8800,20 @@ export class OrganizationController extends Controller {
const profileUpdateEntries = Array.from(profileUpdates.entries()); const profileUpdateEntries = Array.from(profileUpdates.entries());
await Promise.all( await Promise.all(
profileUpdateEntries.map(([profileId, data]) => profileUpdateEntries.map(([profileId, data]) =>
queryRunner.manager.update(Profile, profileId, data) queryRunner.manager.update(Profile, profileId, data),
) ),
);
}
// Save PosMasterHistory for updated positions
if (historyCalls.length > 0) {
await BatchSavePosMasterHistoryOfficer(
queryRunner,
historyCalls.map(({ ancestorDNA, profileId, historyData }) => ({
posMasterDnaId: ancestorDNA,
profileId,
pm: historyData,
})),
); );
} }

View file

@ -1359,7 +1359,7 @@ export class OrganizationDotnetController extends Controller {
order: { commandDateAffect: "DESC" }, order: { commandDateAffect: "DESC" },
}), }),
this.insigniaRepo.findOne({ this.insigniaRepo.findOne({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { receiveDate: "DESC" }, order: { receiveDate: "DESC" },
}), }),
]); ]);
@ -1542,7 +1542,7 @@ export class OrganizationDotnetController extends Controller {
order: { commandDateAffect: "DESC" }, order: { commandDateAffect: "DESC" },
}), }),
this.insigniaRepo.findOne({ this.insigniaRepo.findOne({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { receiveDate: "DESC" }, order: { receiveDate: "DESC" },
}), }),
]); ]);
@ -2379,7 +2379,7 @@ export class OrganizationDotnetController extends Controller {
order: { commandDateAffect: "DESC" }, order: { commandDateAffect: "DESC" },
}), }),
this.insigniaRepo.findOne({ this.insigniaRepo.findOne({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { receiveDate: "DESC" }, order: { receiveDate: "DESC" },
}), }),
]); ]);
@ -2694,7 +2694,7 @@ export class OrganizationDotnetController extends Controller {
order: { commandDateAffect: "DESC" }, order: { commandDateAffect: "DESC" },
}), }),
this.insigniaRepo.findOne({ this.insigniaRepo.findOne({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { receiveDate: "DESC" }, order: { receiveDate: "DESC" },
}), }),
]); ]);
@ -7441,7 +7441,7 @@ export class OrganizationDotnetController extends Controller {
: []; : [];
const profileEducations = await this.educationRepo.find({ const profileEducations = await this.educationRepo.find({
where: { profileEmployeeId: profile!.id }, where: { profileEmployeeId: profile!.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
_educations = profileEducations.length > 0 _educations = profileEducations.length > 0
@ -7581,7 +7581,7 @@ export class OrganizationDotnetController extends Controller {
: []; : [];
const profileEducations = await this.educationRepo.find({ const profileEducations = await this.educationRepo.find({
where: { profileId: profile!.id }, where: { profileId: profile!.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
_educations = profileEducations.length > 0 _educations = profileEducations.length > 0

View file

@ -423,6 +423,7 @@ export class OrganizationUnauthorizeController extends Controller {
year: body.year.toString(), year: body.year.toString(),
pointSum: MoreThanOrEqual(90), pointSum: MoreThanOrEqual(90),
period: body.period.toLocaleUpperCase(), period: body.period.toLocaleUpperCase(),
isDeleted: false
} }
} }
); );
@ -884,6 +885,7 @@ export class OrganizationUnauthorizeController extends Controller {
year: body.year.toString(), year: body.year.toString(),
pointSum: MoreThanOrEqual(90), pointSum: MoreThanOrEqual(90),
period: body.period.toLocaleUpperCase(), period: body.period.toLocaleUpperCase(),
isDeleted: false
} }
} }
); );
@ -1088,7 +1090,7 @@ export class OrganizationUnauthorizeController extends Controller {
order: { commandDateAffect: "DESC" }, order: { commandDateAffect: "DESC" },
}), }),
this.insigniaRepo.findOne({ this.insigniaRepo.findOne({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { receiveDate: "DESC" }, order: { receiveDate: "DESC" },
}), }),
]); ]);
@ -1403,7 +1405,7 @@ export class OrganizationUnauthorizeController extends Controller {
order: { commandDateAffect: "DESC" }, order: { commandDateAffect: "DESC" },
}), }),
this.insigniaRepo.findOne({ this.insigniaRepo.findOne({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { receiveDate: "DESC" }, order: { receiveDate: "DESC" },
}), }),
]); ]);

View file

@ -715,6 +715,7 @@ export class PosMasterActController extends Controller {
"lastUpdateFullName", "lastUpdateFullName",
"lastUpdatedAt", "lastUpdatedAt",
"dateEnd", "dateEnd",
"isDeleted"
], ],
where: { profileId, status: true, isDeleted: false }, where: { profileId, status: true, isDeleted: false },
}); });

View file

@ -40,7 +40,7 @@ export class ProfileAbilityController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAbilityId = await this.profileAbilityRepo.find({ const getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {
@ -55,7 +55,7 @@ export class ProfileAbilityController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileAbilityId = await this.profileAbilityRepo.find({ const getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {

View file

@ -40,7 +40,7 @@ export class ProfileAbilityEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAbilityId = await this.profileAbilityRepo.find({ const getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {
@ -58,7 +58,7 @@ export class ProfileAbilityEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAbilityId = await this.profileAbilityRepo.find({ const getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {

View file

@ -40,7 +40,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAbilityId = await this.profileAbilityRepo.find({ const getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {
@ -57,7 +57,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileAbilityId = await this.profileAbilityRepo.find({ const getProfileAbilityId = await this.profileAbilityRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {

View file

@ -41,7 +41,7 @@ export class ProfileAssessmentsController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAssessments = await this.profileAssessmentsRepository.find({ const getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssessments) { if (!getProfileAssessments) {
@ -59,7 +59,7 @@ export class ProfileAssessmentsController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileAssessments = await this.profileAssessmentsRepository.find({ const getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssessments) { if (!getProfileAssessments) {

View file

@ -41,7 +41,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAssessments = await this.profileAssessmentsRepository.find({ const getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssessments) { if (!getProfileAssessments) {
@ -61,6 +61,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
const getProfileAssessments = await this.profileAssessmentsRepository.find({ const getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { where: {
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
isDeleted: false
}, },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });

View file

@ -41,7 +41,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAssessments = await this.profileAssessmentsRepository.find({ const getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssessments) { if (!getProfileAssessments) {
@ -60,6 +60,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
const getProfileAssessments = await this.profileAssessmentsRepository.find({ const getProfileAssessments = await this.profileAssessmentsRepository.find({
where: { where: {
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
isDeleted: false
}, },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });

View file

@ -40,7 +40,7 @@ export class ProfileAssistanceController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAssistanceId = await this.profileAssistanceRepo.find({ const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssistanceId) { if (!getProfileAssistanceId) {
@ -55,7 +55,7 @@ export class ProfileAssistanceController extends Controller {
// if (_workflow == false) // if (_workflow == false)
// await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileAssistanceId = await this.profileAssistanceRepo.find({ const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssistanceId) { if (!getProfileAssistanceId) {

View file

@ -40,7 +40,7 @@ export class ProfileAssistanceEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAssistanceId = await this.profileAssistanceRepo.find({ const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssistanceId) { if (!getProfileAssistanceId) {
@ -58,7 +58,7 @@ export class ProfileAssistanceEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAssistanceId = await this.profileAssistanceRepo.find({ const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssistanceId) { if (!getProfileAssistanceId) {

View file

@ -40,7 +40,7 @@ export class ProfileAssistanceEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileAssistanceId = await this.profileAssistanceRepo.find({ const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssistanceId) { if (!getProfileAssistanceId) {
@ -57,7 +57,7 @@ export class ProfileAssistanceEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileAssistanceId = await this.profileAssistanceRepo.find({ const getProfileAssistanceId = await this.profileAssistanceRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
if (!getProfileAssistanceId) { if (!getProfileAssistanceId) {

View file

@ -40,7 +40,7 @@ export class ProfileCertificateController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.certificateRepo.find({ const record = await this.certificateRepo.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -52,7 +52,7 @@ export class ProfileCertificateController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.certificateRepo.find({ const record = await this.certificateRepo.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -40,7 +40,7 @@ export class ProfileCertificateEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.certificateRepo.find({ const record = await this.certificateRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -52,7 +52,7 @@ export class ProfileCertificateEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.certificateRepo.find({ const record = await this.certificateRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -40,7 +40,7 @@ export class ProfileCertificateEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.certificateRepo.find({ const record = await this.certificateRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -51,7 +51,7 @@ export class ProfileCertificateEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const record = await this.certificateRepo.find({ const record = await this.certificateRepo.find({
where: { profileEmployeeId }, where: { profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -41,7 +41,7 @@ export class ProfileChangeNameController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -53,7 +53,7 @@ export class ProfileChangeNameController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -41,7 +41,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -53,7 +53,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -41,7 +41,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -52,7 +52,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -41,7 +41,7 @@ export class ProfileChildrenController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -53,7 +53,7 @@ export class ProfileChildrenController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -41,7 +41,7 @@ export class ProfileChildrenEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -53,7 +53,7 @@ export class ProfileChildrenEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -41,7 +41,7 @@ export class ProfileChildrenEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -52,7 +52,7 @@ export class ProfileChildrenEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -322,8 +322,8 @@ export class ProfileController extends Controller {
]; ];
const educations = await this.profileEducationRepo.find({ const educations = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
const Education = const Education =
@ -575,8 +575,8 @@ export class ProfileController extends Controller {
let _child4 = child4?.orgChild4Name; let _child4 = child4?.orgChild4Name;
const cert_raw = await this.certificateRepository.find({ const cert_raw = await this.certificateRepository.find({
where: { profileId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate", "isDeleted"],
select: ["certificateType", "issuer", "certificateNo", "issueDate"], where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const certs = const certs =
@ -596,8 +596,8 @@ export class ProfileController extends Controller {
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department", "name"], select: ["startDate", "endDate", "place", "department", "name", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const trainings = const trainings =
@ -633,8 +633,8 @@ export class ProfileController extends Controller {
]; ];
const discipline_raw = await this.disciplineRepository.find({ const discipline_raw = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"], select: ["refCommandDate", "refCommandNo", "detail", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const disciplines = const disciplines =
@ -655,8 +655,8 @@ export class ProfileController extends Controller {
]; ];
const education_raw = await this.profileEducationRepo.find({ const education_raw = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
// order: { lastUpdatedAt: "DESC" }, // order: { lastUpdatedAt: "DESC" },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
@ -756,7 +756,7 @@ export class ProfileController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const insignias = const insignias =
@ -796,7 +796,7 @@ export class ProfileController extends Controller {
const leave_raw = await this.profileLeaveRepository.find({ const leave_raw = await this.profileLeaveRepository.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { dateLeaveStart: "ASC" }, order: { dateLeaveStart: "ASC" },
}); });
const leaves = const leaves =
@ -1052,8 +1052,8 @@ export class ProfileController extends Controller {
let _child4 = child4?.orgChild4Name; let _child4 = child4?.orgChild4Name;
const cert_raw = await this.certificateRepository.find({ const cert_raw = await this.certificateRepository.find({
where: { profileId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate", "expireDate", "isDeleted"],
select: ["certificateType", "issuer", "certificateNo", "issueDate", "expireDate"], where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const certs = const certs =
@ -1087,8 +1087,8 @@ export class ProfileController extends Controller {
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
select: ["place", "department", "name", "duration"], select: ["place", "department", "name", "duration", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const trainings = const trainings =
@ -1109,8 +1109,8 @@ export class ProfileController extends Controller {
]; ];
const discipline_raw = await this.disciplineRepository.find({ const discipline_raw = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail", "level"], select: ["refCommandDate", "refCommandNo", "detail", "level", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const disciplines = const disciplines =
@ -1135,6 +1135,7 @@ export class ProfileController extends Controller {
const education_raw = await this.profileEducationRepo const education_raw = await this.profileEducationRepo
.createQueryBuilder("education") .createQueryBuilder("education")
.where("education.profileId = :profileId", { profileId: id }) .where("education.profileId = :profileId", { profileId: id })
.andWhere("education.isDeleted = :isDeleted", { isDeleted: false })
.orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC") .orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC")
.addOrderBy("education.level", "ASC") .addOrderBy("education.level", "ASC")
.getMany(); .getMany();
@ -1245,13 +1246,14 @@ export class ProfileController extends Controller {
"page", "page",
"refCommandDate", "refCommandDate",
"note", "note",
"isDeleted"
], ],
relations: { relations: {
insignia: { insignia: {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const insignias = const insignias =
@ -1294,6 +1296,7 @@ export class ProfileController extends Controller {
.createQueryBuilder("profileLeave") .createQueryBuilder("profileLeave")
.leftJoinAndSelect("profileLeave.leaveType", "leaveType") .leftJoinAndSelect("profileLeave.leaveType", "leaveType")
.select([ .select([
"profileLeave.isDeleted",
"profileLeave.leaveTypeId", "profileLeave.leaveTypeId",
"leaveType.name as name", "leaveType.name as name",
"leaveType.code as code", "leaveType.code as code",
@ -1303,6 +1306,7 @@ export class ProfileController extends Controller {
]) ])
.addSelect("SUM(profileLeave.leaveDays)", "totalLeaveDays") .addSelect("SUM(profileLeave.leaveDays)", "totalLeaveDays")
.where("profileLeave.profileId = :profileId", { profileId: id }) .where("profileLeave.profileId = :profileId", { profileId: id })
.andWhere("profileLeave.isDeleted = :isDeleted", { isDeleted: false })
.andWhere("profileLeave.status = :status", { status: "approve" }) .andWhere("profileLeave.status = :status", { status: "approve" })
.groupBy("profileLeave.leaveTypeId") .groupBy("profileLeave.leaveTypeId")
.orderBy("code", "ASC") .orderBy("code", "ASC")
@ -1354,6 +1358,7 @@ export class ProfileController extends Controller {
.createQueryBuilder("profileLeave") .createQueryBuilder("profileLeave")
.leftJoinAndSelect("profileLeave.leaveType", "leaveType") .leftJoinAndSelect("profileLeave.leaveType", "leaveType")
.select([ .select([
"profileLeave.isDeleted AS isDeleted",
"profileLeave.dateLeaveStart AS dateLeaveStart", "profileLeave.dateLeaveStart AS dateLeaveStart",
"profileLeave.dateLeaveEnd AS dateLeaveEnd", "profileLeave.dateLeaveEnd AS dateLeaveEnd",
"profileLeave.leaveDays AS leaveDays", "profileLeave.leaveDays AS leaveDays",
@ -1361,6 +1366,7 @@ export class ProfileController extends Controller {
"leaveType.name as name", "leaveType.name as name",
]) ])
.where("profileLeave.profileId = :profileId", { profileId: id }) .where("profileLeave.profileId = :profileId", { profileId: id })
.andWhere("profileLeave.isDeleted = :isDeleted", { isDeleted: false })
.andWhere("leaveType.code IN (:...codes)", { codes: ["LV-008", "LV-009", "LV-010"] }) .andWhere("leaveType.code IN (:...codes)", { codes: ["LV-008", "LV-009", "LV-010"] })
.andWhere("profileLeave.status = :status", { status: "approve" }) .andWhere("profileLeave.status = :status", { status: "approve" })
.orderBy("leaveType.code", "ASC") .orderBy("leaveType.code", "ASC")
@ -1387,7 +1393,7 @@ export class ProfileController extends Controller {
}, },
]; ];
const children_raw = await this.profileChildrenRepository.find({ const children_raw = await this.profileChildrenRepository.find({
where: { profileId: id }, where: { profileId: id, isDeleted: false },
}); });
const children = const children =
children_raw.length > 0 children_raw.length > 0
@ -1410,7 +1416,7 @@ export class ProfileController extends Controller {
}, },
]; ];
const changeName_raw = await this.changeNameRepository.find({ const changeName_raw = await this.changeNameRepository.find({
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const changeName = const changeName =
@ -1504,13 +1510,13 @@ export class ProfileController extends Controller {
]; ];
const actposition_raw = await this.profileActpositionRepo.find({ const actposition_raw = await this.profileActpositionRepo.find({
select: ["dateStart", "dateEnd", "position"], select: ["dateStart", "dateEnd", "position", "isDeleted"],
where: { profileId: id, isDeleted: false }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const assistance_raw = await this.profileAssistanceRepository.find({ const assistance_raw = await this.profileAssistanceRepository.find({
select: ["dateStart", "dateEnd", "commandName", "agency", "document"], select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"],
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -1566,7 +1572,7 @@ export class ProfileController extends Controller {
]; ];
const actposition = [..._actposition, ..._assistance]; const actposition = [..._actposition, ..._assistance];
const duty_raw = await this.dutyRepository.find({ const duty_raw = await this.dutyRepository.find({
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const duty = const duty =
@ -1593,7 +1599,7 @@ export class ProfileController extends Controller {
}, },
]; ];
const assessments_raw = await this.profileAssessmentsRepository.find({ const assessments_raw = await this.profileAssessmentsRepository.find({
where: { profileId: id }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const assessments = const assessments =
@ -9093,7 +9099,7 @@ export class ProfileController extends Controller {
)?.posMasterNo; )?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepo.findOne({ const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileId: item.id }, where: { profileId: item.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
@ -11106,7 +11112,7 @@ export class ProfileController extends Controller {
} }
const latestProfileEducation = await this.profileEducationRepo.findOne({ const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileId: item.id }, where: { profileId: item.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });

View file

@ -40,7 +40,7 @@ export class ProfileDisciplineController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -52,7 +52,7 @@ export class ProfileDisciplineController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -63,7 +63,7 @@ export class ProfileDisciplineController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_SALARY_OFFICER"); let _workflow = await new permission().Workflow(req, profileId, "SYS_SALARY_OFFICER");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_SALARY_OFFICER"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_SALARY_OFFICER");
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -40,7 +40,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -52,7 +52,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -63,7 +63,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE"); let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE");
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -40,7 +40,7 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -51,7 +51,7 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -62,7 +62,7 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE"); let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE");
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -36,7 +36,7 @@ export class ProfileDutyController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -48,7 +48,7 @@ export class ProfileDutyController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -36,7 +36,7 @@ export class ProfileDutyEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -48,7 +48,7 @@ export class ProfileDutyEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -36,7 +36,7 @@ export class ProfileDutyEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -47,7 +47,7 @@ export class ProfileDutyEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -42,7 +42,7 @@ export class ProfileEducationsController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
if (!getProfileEducation) { if (!getProfileEducation) {
@ -57,7 +57,7 @@ export class ProfileEducationsController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
if (!getProfileEducation) { if (!getProfileEducation) {

View file

@ -42,7 +42,7 @@ export class ProfileEducationsEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
if (!getProfileEducation) { if (!getProfileEducation) {
@ -60,7 +60,7 @@ export class ProfileEducationsEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
if (!getProfileEducation) { if (!getProfileEducation) {

View file

@ -42,7 +42,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
if (!getProfileEducation) { if (!getProfileEducation) {
@ -59,7 +59,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
if (!getProfileEducation) { if (!getProfileEducation) {

View file

@ -317,8 +317,8 @@ export class ProfileEmployeeController extends Controller {
]; ];
const educations = await this.profileEducationRepo.find({ const educations = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
const Education = const Education =
@ -571,8 +571,8 @@ export class ProfileEmployeeController extends Controller {
let _child4 = child4?.orgChild4Name; let _child4 = child4?.orgChild4Name;
const cert_raw = await this.certificateRepository.find({ const cert_raw = await this.certificateRepository.find({
where: { profileEmployeeId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate", "isDeleted"],
select: ["certificateType", "issuer", "certificateNo", "issueDate"], where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const certs = const certs =
@ -592,8 +592,8 @@ export class ProfileEmployeeController extends Controller {
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department"], select: ["startDate", "endDate", "place", "department", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const trainings = const trainings =
@ -629,8 +629,8 @@ export class ProfileEmployeeController extends Controller {
]; ];
const discipline_raw = await this.disciplineRepository.find({ const discipline_raw = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"], select: ["refCommandDate", "refCommandNo", "detail", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const disciplines = const disciplines =
@ -651,8 +651,8 @@ export class ProfileEmployeeController extends Controller {
]; ];
const education_raw = await this.profileEducationRepo.find({ const education_raw = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
// order: { lastUpdatedAt: "DESC" }, // order: { lastUpdatedAt: "DESC" },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
@ -752,7 +752,7 @@ export class ProfileEmployeeController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const insignias = const insignias =
@ -792,7 +792,7 @@ export class ProfileEmployeeController extends Controller {
const leave_raw = await this.profileLeaveRepository.find({ const leave_raw = await this.profileLeaveRepository.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { dateLeaveStart: "ASC" }, order: { dateLeaveStart: "ASC" },
}); });
const leaves = const leaves =
@ -1048,8 +1048,8 @@ export class ProfileEmployeeController extends Controller {
let _child4 = child4?.orgChild4Name; let _child4 = child4?.orgChild4Name;
const cert_raw = await this.certificateRepository.find({ const cert_raw = await this.certificateRepository.find({
where: { profileEmployeeId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate", "expireDate", "isDeleted"],
select: ["certificateType", "issuer", "certificateNo", "issueDate", "expireDate"], where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const certs = const certs =
@ -1083,8 +1083,8 @@ export class ProfileEmployeeController extends Controller {
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
select: ["place", "department", "name", "duration"], select: ["place", "department", "name", "duration", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const trainings = const trainings =
@ -1105,8 +1105,8 @@ export class ProfileEmployeeController extends Controller {
]; ];
const discipline_raw = await this.disciplineRepository.find({ const discipline_raw = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail", "level"], select: ["refCommandDate", "refCommandNo", "detail", "level", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const disciplines = const disciplines =
@ -1131,6 +1131,7 @@ export class ProfileEmployeeController extends Controller {
const education_raw = await this.profileEducationRepo const education_raw = await this.profileEducationRepo
.createQueryBuilder("education") .createQueryBuilder("education")
.where("education.profileEmployeeId = :profileId", { profileId: id }) .where("education.profileEmployeeId = :profileId", { profileId: id })
.andWhere("education.isDeleted = :isDeleted", { isDeleted: false })
.orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC") .orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC")
.addOrderBy("education.level", "ASC") .addOrderBy("education.level", "ASC")
.getMany(); .getMany();
@ -1241,13 +1242,14 @@ export class ProfileEmployeeController extends Controller {
"page", "page",
"refCommandDate", "refCommandDate",
"note", "note",
"isDeleted"
], ],
relations: { relations: {
insignia: { insignia: {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const insignias = const insignias =
@ -1290,6 +1292,7 @@ export class ProfileEmployeeController extends Controller {
.createQueryBuilder("profileLeave") .createQueryBuilder("profileLeave")
.leftJoinAndSelect("profileLeave.leaveType", "leaveType") .leftJoinAndSelect("profileLeave.leaveType", "leaveType")
.select([ .select([
"profileLeave.isDeleted",
"profileLeave.leaveTypeId", "profileLeave.leaveTypeId",
"leaveType.name as name", "leaveType.name as name",
"leaveType.code as code", "leaveType.code as code",
@ -1299,6 +1302,7 @@ export class ProfileEmployeeController extends Controller {
]) ])
.addSelect("SUM(profileLeave.leaveDays)", "totalLeaveDays") .addSelect("SUM(profileLeave.leaveDays)", "totalLeaveDays")
.where("profileLeave.profileEmployeeId = :profileId", { profileId: id }) .where("profileLeave.profileEmployeeId = :profileId", { profileId: id })
.andWhere("profileLeave.isDeleted = :isDeleted", { isDeleted: false })
.andWhere("profileLeave.status = :status", { status: "approve" }) .andWhere("profileLeave.status = :status", { status: "approve" })
.groupBy("profileLeave.leaveTypeId") .groupBy("profileLeave.leaveTypeId")
.orderBy("code", "ASC") .orderBy("code", "ASC")
@ -1350,6 +1354,7 @@ export class ProfileEmployeeController extends Controller {
.createQueryBuilder("profileLeave") .createQueryBuilder("profileLeave")
.leftJoinAndSelect("profileLeave.leaveType", "leaveType") .leftJoinAndSelect("profileLeave.leaveType", "leaveType")
.select([ .select([
"profileLeave.isDeleted AS isDeleted",
"profileLeave.dateLeaveStart AS dateLeaveStart", "profileLeave.dateLeaveStart AS dateLeaveStart",
"profileLeave.dateLeaveEnd AS dateLeaveEnd", "profileLeave.dateLeaveEnd AS dateLeaveEnd",
"profileLeave.leaveDays AS leaveDays", "profileLeave.leaveDays AS leaveDays",
@ -1357,6 +1362,7 @@ export class ProfileEmployeeController extends Controller {
"leaveType.name as name", "leaveType.name as name",
]) ])
.where("profileLeave.profileEmployeeId = :profileId", { profileId: id }) .where("profileLeave.profileEmployeeId = :profileId", { profileId: id })
.andWhere("profileLeave.isDeleted = :isDeleted", { isDeleted: false })
.andWhere("leaveType.code IN (:...codes)", { codes: ["LV-008", "LV-009", "LV-010"] }) .andWhere("leaveType.code IN (:...codes)", { codes: ["LV-008", "LV-009", "LV-010"] })
.andWhere("profileLeave.status = :status", { status: "approve" }) .andWhere("profileLeave.status = :status", { status: "approve" })
.orderBy("leaveType.code", "ASC") .orderBy("leaveType.code", "ASC")
@ -1383,7 +1389,7 @@ export class ProfileEmployeeController extends Controller {
}, },
]; ];
const children_raw = await this.profileChildrenRepository.find({ const children_raw = await this.profileChildrenRepository.find({
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
}); });
const children = const children =
children_raw.length > 0 children_raw.length > 0
@ -1406,7 +1412,7 @@ export class ProfileEmployeeController extends Controller {
}, },
]; ];
const changeName_raw = await this.changeNameRepository.find({ const changeName_raw = await this.changeNameRepository.find({
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const changeName = const changeName =
@ -1500,13 +1506,13 @@ export class ProfileEmployeeController extends Controller {
]; ];
const actposition_raw = await this.profileActpositionRepo.find({ const actposition_raw = await this.profileActpositionRepo.find({
select: ["dateStart", "dateEnd", "position"], select: ["dateStart", "dateEnd", "position", "isDeleted"],
where: { profileEmployeeId: id, isDeleted: false }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const assistance_raw = await this.profileAssistanceRepository.find({ const assistance_raw = await this.profileAssistanceRepository.find({
select: ["dateStart", "dateEnd", "commandName", "agency", "document"], select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -1562,7 +1568,7 @@ export class ProfileEmployeeController extends Controller {
]; ];
const actposition = [..._actposition, ..._assistance]; const actposition = [..._actposition, ..._assistance];
const duty_raw = await this.dutyRepository.find({ const duty_raw = await this.dutyRepository.find({
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const duty = const duty =
@ -1589,7 +1595,7 @@ export class ProfileEmployeeController extends Controller {
}, },
]; ];
const assessments_raw = await this.profileAssessmentsRepository.find({ const assessments_raw = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const assessments = const assessments =
@ -3854,7 +3860,7 @@ export class ProfileEmployeeController extends Controller {
)?.posMasterNo; )?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepo.findOne({ const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id }, where: { profileEmployeeId: item.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
@ -5953,7 +5959,7 @@ export class ProfileEmployeeController extends Controller {
} }
const latestProfileEducation = await this.profileEducationRepo.findOne({ const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id }, where: { profileEmployeeId: item.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });

View file

@ -289,8 +289,8 @@ export class ProfileEmployeeTempController extends Controller {
}, },
]; ];
const educations = await this.profileEducationRepo.find({ const educations = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
const Education = const Education =
@ -547,8 +547,8 @@ export class ProfileEmployeeTempController extends Controller {
let _child4 = child4?.orgChild4Name; let _child4 = child4?.orgChild4Name;
const cert_raw = await this.certificateRepository.find({ const cert_raw = await this.certificateRepository.find({
where: { profileEmployeeId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate", "isDeleted"],
select: ["certificateType", "issuer", "certificateNo", "issueDate"], where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const certs = const certs =
@ -627,8 +627,8 @@ export class ProfileEmployeeTempController extends Controller {
]; ];
const education_raw = await this.profileEducationRepo.find({ const education_raw = await this.profileEducationRepo.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute", "isDeleted"],
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
// order: { lastUpdatedAt: "DESC" }, // order: { lastUpdatedAt: "DESC" },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
@ -734,7 +734,7 @@ export class ProfileEmployeeTempController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { receiveDate: "ASC" }, order: { receiveDate: "ASC" },
}); });
const insignias = const insignias =
@ -774,7 +774,7 @@ export class ProfileEmployeeTempController extends Controller {
const leave_raw = await this.profileLeaveRepository.find({ const leave_raw = await this.profileLeaveRepository.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: id }, where: { profileEmployeeId: id, isDeleted: false },
order: { dateLeaveStart: "ASC" }, order: { dateLeaveStart: "ASC" },
}); });
const leaves = const leaves =
@ -2370,7 +2370,7 @@ export class ProfileEmployeeTempController extends Controller {
)?.posMasterNo; )?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepo.findOne({ const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id }, where: { profileEmployeeId: item.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });
@ -4043,7 +4043,7 @@ export class ProfileEmployeeTempController extends Controller {
)?.posMasterNo; )?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepo.findOne({ const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileEmployeeId: item.id }, where: { profileEmployeeId: item.id, isDeleted: false },
order: { level: "ASC" }, order: { level: "ASC" },
}); });

View file

@ -36,7 +36,7 @@ export class ProfileHonorController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.honorRepo.find({ const record = await this.honorRepo.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -48,7 +48,7 @@ export class ProfileHonorController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.honorRepo.find({ const record = await this.honorRepo.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -40,7 +40,7 @@ export class ProfileHonorEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.honorRepo.find({ const record = await this.honorRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -52,7 +52,7 @@ export class ProfileHonorEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.honorRepo.find({ const record = await this.honorRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -40,7 +40,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const record = await this.honorRepo.find({ const record = await this.honorRepo.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -51,7 +51,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileEmployeeId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const record = await this.honorRepo.find({ const record = await this.honorRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -50,7 +50,7 @@ export class ProfileInsigniaController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -67,7 +67,7 @@ export class ProfileInsigniaController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileId }, where: { profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -47,7 +47,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -64,7 +64,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId }, where: { profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -47,7 +47,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -63,7 +63,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
insigniaType: true, insigniaType: true,
}, },
}, },
where: { profileEmployeeId }, where: { profileEmployeeId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -120,7 +120,7 @@ export class ProfileLeaveController extends Controller {
} }
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -136,6 +136,7 @@ export class ProfileLeaveController extends Controller {
where: { where: {
profileId: profileId, profileId: profileId,
// status: Not("cancel") // status: Not("cancel")
isDeleted: false
}, },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -148,7 +149,7 @@ export class ProfileLeaveController extends Controller {
if (_workflow == false) await new permission().PermissionGet(req, "SYS_SALARY_OFFICER"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_SALARY_OFFICER");
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileId }, where: { profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -43,7 +43,7 @@ export class ProfileLeaveEmployeeController extends Controller {
} }
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -56,7 +56,7 @@ export class ProfileLeaveEmployeeController extends Controller {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -68,7 +68,7 @@ export class ProfileLeaveEmployeeController extends Controller {
if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE");
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -43,7 +43,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
} }
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -55,7 +55,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);
@ -67,7 +67,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE");
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(record); return new HttpSuccess(record);

View file

@ -36,7 +36,7 @@ export class ProfileNopaidController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -48,7 +48,7 @@ export class ProfileNopaidController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({
where: { profileId }, where: { profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -40,7 +40,7 @@ export class ProfileNopaidEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -51,7 +51,7 @@ export class ProfileNopaidEmployeeController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_EMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_EMP");
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -40,7 +40,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -51,7 +51,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const lists = await this.nopaidRepository.find({ const lists = await this.nopaidRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -37,7 +37,7 @@ export class ProfileOtherController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileId: profile.id }, where: { profileId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -49,7 +49,7 @@ export class ProfileOtherController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileId: profileId }, where: { profileId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -40,7 +40,7 @@ export class ProfileOtherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -52,7 +52,7 @@ export class ProfileOtherEmployeeController extends Controller {
if (_workflow == false) if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -40,7 +40,7 @@ export class ProfileOtherEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileEmployeeId: profile.id }, where: { profileEmployeeId: profile.id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);
@ -51,7 +51,7 @@ export class ProfileOtherEmployeeTempController extends Controller {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP"); let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_TEMP");
if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
return new HttpSuccess(lists); return new HttpSuccess(lists);

View file

@ -3659,8 +3659,9 @@ export class ReportController extends Controller {
if (profileIds.length > 0) { if (profileIds.length > 0) {
educationsData = await this.profileEducationRepository educationsData = await this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...profileIds)", { profileIds }) .where("pe.profileId IN (:...profileIds)", { profileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -3844,8 +3845,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds }) .where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -4025,8 +4027,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds }) .where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -4206,8 +4209,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds }) .where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -4385,8 +4389,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds }) .where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -8955,8 +8960,9 @@ export class ReportController extends Controller {
if (profileIds.length > 0) { if (profileIds.length > 0) {
educationsData = await this.profileEducationRepository educationsData = await this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...profileIds)", { profileIds }) .where("pe.profileId IN (:...profileIds)", { profileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -9146,8 +9152,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds }) .where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -9333,8 +9340,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds }) .where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -9521,8 +9529,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds }) .where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,
@ -9708,8 +9717,9 @@ export class ReportController extends Controller {
this.profileEducationRepository this.profileEducationRepository
.createQueryBuilder("pe") .createQueryBuilder("pe")
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"]) .select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level", "pe.isDeleted"])
.where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds }) .where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
.andWhere("pe.isDeleted = :isDeleted", { isDeleted: false })
.andWhere( .andWhere(
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN ( `(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
SELECT pe2.profileId, SELECT pe2.profileId,

View file

@ -82,6 +82,13 @@ export class ProfileAbility extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany( @OneToMany(
() => ProfileAbilityHistory, () => ProfileAbilityHistory,
(profileAbilityHistory) => profileAbilityHistory.histories, (profileAbilityHistory) => profileAbilityHistory.histories,

View file

@ -66,6 +66,13 @@ export class ProfileAbilityHistory extends EntityBase {
}) })
profileAbilityId: string; profileAbilityId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileAbility, (profileAbility) => profileAbility.profileAbilityHistorys) @ManyToOne(() => ProfileAbility, (profileAbility) => profileAbility.profileAbilityHistorys)
@JoinColumn({ name: "profileAbilityId" }) @JoinColumn({ name: "profileAbilityId" })
histories: ProfileAbility; histories: ProfileAbility;

View file

@ -100,6 +100,13 @@ export class ProfileAssessment extends EntityBase {
}) })
pointSumTotal: number; pointSumTotal: number;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany( @OneToMany(
() => ProfileAssessmentHistory, () => ProfileAssessmentHistory,
(profileAssessmentHistory) => profileAssessmentHistory.histories, (profileAssessmentHistory) => profileAssessmentHistory.histories,

View file

@ -96,6 +96,13 @@ export class ProfileAssessmentHistory extends EntityBase {
}) })
profileAssessmentId: string; profileAssessmentId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne( @ManyToOne(
() => ProfileAssessment, () => ProfileAssessment,
(profileAssessment) => profileAssessment.profileAssessmentHistorys, (profileAssessment) => profileAssessment.profileAssessmentHistorys,

View file

@ -94,6 +94,13 @@ export class ProfileAssistance extends EntityBase {
}) })
commandId: string; commandId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => Command, (command) => command.profileSalarys) @ManyToOne(() => Command, (command) => command.profileSalarys)
@JoinColumn({ name: "commandId" }) @JoinColumn({ name: "commandId" })
command: Command; command: Command;

View file

@ -62,6 +62,13 @@ export class ProfileAssistanceHistory extends EntityBase {
}) })
profileAssistanceId: string; profileAssistanceId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne( @ManyToOne(
() => ProfileAssistance, () => ProfileAssistance,
(profileAssistance) => profileAssistance.profileAssistanceHistorys, (profileAssistance) => profileAssistance.profileAssistanceHistorys,

View file

@ -74,6 +74,13 @@ export class ProfileCertificate extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany( @OneToMany(
() => ProfileCertificateHistory, () => ProfileCertificateHistory,
(profileCertificateHistory) => profileCertificateHistory.histories, (profileCertificateHistory) => profileCertificateHistory.histories,

View file

@ -58,6 +58,13 @@ export class ProfileCertificateHistory extends EntityBase {
}) })
profileCertificateId: string; profileCertificateId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne( @ManyToOne(
() => ProfileCertificate, () => ProfileCertificate,
(profileCertificate) => profileCertificate.profileCertificateHistories, (profileCertificate) => profileCertificate.profileCertificateHistories,

View file

@ -77,6 +77,13 @@ export class ProfileChangeName extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany( @OneToMany(
() => ProfileChangeNameHistory, () => ProfileChangeNameHistory,
(profileChangeNameHistory) => profileChangeNameHistory.histories, (profileChangeNameHistory) => profileChangeNameHistory.histories,

View file

@ -60,6 +60,13 @@ export class ProfileChangeNameHistory extends EntityBase {
}) })
profileChangeNameId: string; profileChangeNameId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne( @ManyToOne(
() => ProfileChangeName, () => ProfileChangeName,
(profileChangeName) => profileChangeName.profileChangeNameHistories, (profileChangeName) => profileChangeName.profileChangeNameHistories,

View file

@ -72,6 +72,13 @@ export class ProfileChildren extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => Profile, (Profile) => Profile.profileChildrens) @ManyToOne(() => Profile, (Profile) => Profile.profileChildrens)
@JoinColumn({ name: "profileId" }) @JoinColumn({ name: "profileId" })
profile: Profile; profile: Profile;

View file

@ -55,6 +55,13 @@ export class ProfileChildrenHistory extends EntityBase {
}) })
profileChildrenId: string; profileChildrenId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
// @ManyToOne(() => ProfileChildren, (profileChildren) => profileChildren.profileChildrenHistories) // @ManyToOne(() => ProfileChildren, (profileChildren) => profileChildren.profileChildrenHistories)
// @JoinColumn({ name: "profileChildrenId" }) // @JoinColumn({ name: "profileChildrenId" })
// histories: ProfileChildren; // histories: ProfileChildren;

View file

@ -82,6 +82,13 @@ export class ProfileDiscipline extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany( @OneToMany(
() => ProfileDisciplineHistory, () => ProfileDisciplineHistory,
(profileDisciplineHistory) => profileDisciplineHistory.histories, (profileDisciplineHistory) => profileDisciplineHistory.histories,

View file

@ -65,6 +65,13 @@ export class ProfileDisciplineHistory extends EntityBase {
}) })
isUpload: boolean; isUpload: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne( @ManyToOne(
() => ProfileDiscipline, () => ProfileDiscipline,
(profileDiscipline) => profileDiscipline.profileDisciplineHistories, (profileDiscipline) => profileDiscipline.profileDisciplineHistories,

View file

@ -82,6 +82,13 @@ export class ProfileDuty extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany(() => ProfileDutyHistory, (profileDutyHistory) => profileDutyHistory.histories) @OneToMany(() => ProfileDutyHistory, (profileDutyHistory) => profileDutyHistory.histories)
profileDutyHistories: ProfileDutyHistory[]; profileDutyHistories: ProfileDutyHistory[];

View file

@ -66,6 +66,13 @@ export class ProfileDutyHistory extends EntityBase {
}) })
profileDutyId: string; profileDutyId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileDuty, (profileDuty) => profileDuty.profileDutyHistories) @ManyToOne(() => ProfileDuty, (profileDuty) => profileDuty.profileDutyHistories)
@JoinColumn({ name: "profileDutyId" }) @JoinColumn({ name: "profileDutyId" })
histories: ProfileDuty; histories: ProfileDuty;

View file

@ -196,6 +196,13 @@ export class ProfileEducation extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany( @OneToMany(
() => ProfileEducationHistory, () => ProfileEducationHistory,
(profileEducationHistory) => profileEducationHistory.histories, (profileEducationHistory) => profileEducationHistory.histories,

View file

@ -166,6 +166,13 @@ export class ProfileEducationHistory extends EntityBase {
}) })
profileEducationId: string; profileEducationId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne( @ManyToOne(
() => ProfileEducation, () => ProfileEducation,
(profileEducation) => profileEducation.profileEducationHistories, (profileEducation) => profileEducation.profileEducationHistories,

View file

@ -89,6 +89,13 @@ export class ProfileHonor extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany(() => ProfileHonorHistory, (profileHonorHistory) => profileHonorHistory.histories) @OneToMany(() => ProfileHonorHistory, (profileHonorHistory) => profileHonorHistory.histories)
profileHonorHistories: ProfileHonorHistory[]; profileHonorHistories: ProfileHonorHistory[];

View file

@ -73,6 +73,13 @@ export class ProfileHonorHistory extends EntityBase {
}) })
isUpload: boolean; isUpload: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileHonor, (profileHonor) => profileHonor.profileHonorHistories) @ManyToOne(() => ProfileHonor, (profileHonor) => profileHonor.profileHonorHistories)
@JoinColumn({ name: "profileHonorId" }) @JoinColumn({ name: "profileHonorId" })
histories: ProfileHonor; histories: ProfileHonor;

View file

@ -137,6 +137,13 @@ export class ProfileInsignia extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => Insignia, (v) => v.profileInsignias) @ManyToOne(() => Insignia, (v) => v.profileInsignias)
insignia: Insignia; insignia: Insignia;

View file

@ -65,6 +65,13 @@ export class ProfileInsigniaHistory extends EntityBase {
}) })
profileInsigniaId: string; profileInsigniaId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileInsignia, (profileInsignia) => profileInsignia.profileInsigniaHistories) @ManyToOne(() => ProfileInsignia, (profileInsignia) => profileInsignia.profileInsigniaHistories)
@JoinColumn({ name: "profileInsigniaId" }) @JoinColumn({ name: "profileInsigniaId" })
histories: ProfileInsignia; histories: ProfileInsignia;

View file

@ -100,6 +100,13 @@ export class ProfileLeave extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany(() => ProfileLeaveHistory, (v) => v.profileLeave) @OneToMany(() => ProfileLeaveHistory, (v) => v.profileLeave)
histories: ProfileLeaveHistory[]; histories: ProfileLeaveHistory[];
@ -124,6 +131,13 @@ export class ProfileLeaveHistory extends ProfileLeave {
}) })
profileLeaveId: string; profileLeaveId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean = false;
@ManyToOne(() => ProfileLeave, (v) => v.histories) @ManyToOne(() => ProfileLeave, (v) => v.histories)
profileLeave: ProfileLeave; profileLeave: ProfileLeave;
} }

View file

@ -74,6 +74,13 @@ export class ProfileNopaid extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany(() => ProfileNopaidHistory, (profileNopaidHistory) => profileNopaidHistory.histories) @OneToMany(() => ProfileNopaidHistory, (profileNopaidHistory) => profileNopaidHistory.histories)
profileNopaidHistories: ProfileNopaidHistory[]; profileNopaidHistories: ProfileNopaidHistory[];

View file

@ -58,6 +58,13 @@ export class ProfileNopaidHistory extends EntityBase {
}) })
profileNopaidId: string; profileNopaidId: string;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileNopaid, (profileNopaid) => profileNopaid.profileNopaidHistories) @ManyToOne(() => ProfileNopaid, (profileNopaid) => profileNopaid.profileNopaidHistories)
@JoinColumn({ name: "profileNopaidId" }) @JoinColumn({ name: "profileNopaidId" })
histories: ProfileNopaid; histories: ProfileNopaid;

View file

@ -44,6 +44,13 @@ export class ProfileOther extends EntityBase {
}) })
isEntry: boolean; isEntry: boolean;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@OneToMany(() => ProfileOtherHistory, (profileOtherHistory) => profileOtherHistory.histories) @OneToMany(() => ProfileOtherHistory, (profileOtherHistory) => profileOtherHistory.histories)
profileOtherHistories: ProfileOtherHistory[]; profileOtherHistories: ProfileOtherHistory[];

View file

@ -28,6 +28,13 @@ export class ProfileOtherHistory extends EntityBase {
}) })
date: Date; date: Date;
@Column({
nullable: false,
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileOther, (profileOther) => profileOther.profileOtherHistories) @ManyToOne(() => ProfileOther, (profileOther) => profileOther.profileOtherHistories)
@JoinColumn({ name: "profileOtherId" }) @JoinColumn({ name: "profileOtherId" })
histories: ProfileOther; histories: ProfileOther;

View file

@ -22,3 +22,23 @@ export interface AllOrgMappings {
orgChild3: OrgIdMapping; orgChild3: OrgIdMapping;
orgChild4: OrgIdMapping; orgChild4: OrgIdMapping;
} }
export interface SavePosMasterHistory {
prefix: string | null;
firstName: string | null;
lastName: string | null;
position: string | null;
posType: string | null;
posLevel: string | null;
posExecutive: string | null;
profileId: string | null;
rootDnaId: string | null;
child1DnaId: string | null;
child2DnaId: string | null;
child3DnaId: string | null;
child4DnaId: string | null;
shortName: string | null;
posMasterNoPrefix: string | null;
posMasterNo: string | null;
posMasterNoSuffix: string | null;
}

View file

@ -100,6 +100,52 @@ class CallAPI {
} }
} }
// Put
public async PutData(request: any, @Path() path: any, sendData: any, log = true) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
const url = process.env.API_URL + path;
try {
const response = await axios.put(url, sendData, {
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
api_key: process.env.API_KEY,
},
});
if (log)
addLogSequence(request, {
action: "request",
status: "success",
description: "connected",
request: {
method: "PUT",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(response.data.result),
},
});
return response.data.result;
} catch (error) {
if (log)
addLogSequence(request, {
action: "request",
status: "error",
description: "unconnected",
request: {
method: "PUT",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(error),
},
});
throw error;
}
}
//Delete File //Delete File
public async DeleteFile(request: any, @Path() path: any) { public async DeleteFile(request: any, @Path() path: any) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");

View file

@ -0,0 +1,74 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddFieldsIsDeleted1770870836370 implements MigrationInterface {
name = 'AddFieldsIsDeleted1770870836370'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileCertificateHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileCertificate\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileInsigniaHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileInsignia\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileHonorHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileHonor\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileAssessmentHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileAssessment\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileLeave\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileLeaveHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileDutyHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileDuty\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileNopaidHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileNopaid\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileDisciplineHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileDiscipline\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileChangeNameHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileChangeName\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileEducationHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileEducation\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileAbilityHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileAbility\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileOtherHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileOther\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileChildren\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileAssistanceHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileAssistance\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileSalaryBackup\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalaryBackup\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileAssistance\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileAssistanceHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileChildren\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileOther\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileOtherHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileAbility\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileAbilityHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileEducation\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileEducationHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileChangeName\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileChangeNameHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileDiscipline\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileDisciplineHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileNopaid\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileNopaidHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileDuty\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileDutyHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileLeaveHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileLeave\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileAssessment\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileAssessmentHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileHonor\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileHonorHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileInsignia\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileInsigniaHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileCertificate\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileCertificateHistory\` DROP COLUMN \`isDeleted\``);
}
}

View file

@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class MoveFieldsIsDeletedInTablesProfileSalary1770872734016 implements MigrationInterface {
name = 'MoveFieldsIsDeletedInTablesProfileSalary1770872734016'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`isDeleted\``);
await queryRunner.query(`ALTER TABLE \`profileSalaryBackup\` DROP COLUMN \`isDeleted\``);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalaryBackup\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT '0'`);
}
}

View file

@ -0,0 +1,62 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddIndexesForPerformance1770875727560 implements MigrationInterface {
name = "AddIndexesForPerformance1770875727560";
public async up(queryRunner: QueryRunner): Promise<void> {
// Index for posMasterHistory lookups
await queryRunner.query(`
CREATE INDEX IDX_posMasterHistory_ancestorDNA
ON posMasterHistory(ancestorDNA, createdAt DESC)
`);
// Index for org tables lookups
await queryRunner.query(`
CREATE INDEX IDX_orgRoot_ancestorDNA_revision
ON orgRoot(ancestorDNA, orgRevisionId)
`);
await queryRunner.query(`
CREATE INDEX IDX_orgChild1_ancestorDNA_revision
ON orgChild1(ancestorDNA, orgRevisionId)
`);
await queryRunner.query(`
CREATE INDEX IDX_orgChild2_ancestorDNA_revision
ON orgChild2(ancestorDNA, orgRevisionId)
`);
await queryRunner.query(`
CREATE INDEX IDX_orgChild3_ancestorDNA_revision
ON orgChild3(ancestorDNA, orgRevisionId)
`);
await queryRunner.query(`
CREATE INDEX IDX_orgChild4_ancestorDNA_revision
ON orgChild4(ancestorDNA, orgRevisionId)
`);
// Index for posMaster lookups
await queryRunner.query(`
CREATE INDEX IDX_posMaster_revision_org
ON posMaster(orgRevisionId, orgRootId, orgChild1Id, orgChild2Id, orgChild3Id, orgChild4Id)
`);
await queryRunner.query(`
CREATE INDEX IDX_posMaster_ancestorDNA
ON posMaster(ancestorDNA)
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX IDX_position_posMasterId ON position`);
await queryRunner.query(`DROP INDEX IDX_posMaster_ancestorDNA ON posMaster`);
await queryRunner.query(`DROP INDEX IDX_posMaster_revision_org ON posMaster`);
await queryRunner.query(`DROP INDEX IDX_orgChild4_ancestorDNA_revision ON orgChild4`);
await queryRunner.query(`DROP INDEX IDX_orgChild3_ancestorDNA_revision ON orgChild3`);
await queryRunner.query(`DROP INDEX IDX_orgChild2_ancestorDNA_revision ON orgChild2`);
await queryRunner.query(`DROP INDEX IDX_orgChild1_ancestorDNA_revision ON orgChild1`);
await queryRunner.query(`DROP INDEX IDX_orgRoot_ancestorDNA_revision ON orgRoot`);
await queryRunner.query(`DROP INDEX IDX_posMasterHistory_ancestorDNA ON posMasterHistory`);
}
}

View file

@ -1,3 +1,5 @@
import { In } from "typeorm";
import { SavePosMasterHistory } from "./../interfaces/OrgMapping";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
@ -44,9 +46,9 @@ export async function CreatePosMasterHistoryOfficer(
where: { where: {
id: pm.orgRevisionId, id: pm.orgRevisionId,
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
orgRevisionIsDraft: false orgRevisionIsDraft: false,
} },
}) });
const _null: any = null; const _null: any = null;
const h = new PosMasterHistory(); const h = new PosMasterHistory();
const selectedPosition = const selectedPosition =
@ -260,3 +262,144 @@ export async function getTopDegrees(educations: ProfileEducation[]): Promise<str
.filter(Boolean) .filter(Boolean)
.join("\n"); .join("\n");
} }
export async function SavePosMasterHistoryOfficer(
queryRunner: any,
posMasterDnaId: string,
profileId: string | null,
pm: SavePosMasterHistory | null,
): Promise<boolean> {
try {
// Type workaround: entity columns are nullable but types don't reflect it
const _null: any = null;
const repoPosMasterHistory = queryRunner.manager.getRepository(PosMasterHistory);
const pmh = await repoPosMasterHistory.findOne({
where: {
ancestorDNA: posMasterDnaId,
},
order: { createdAt: "DESC" },
});
// Check if we need to insert a new history record
const shouldInsert = !pmh && profileId && pm;
const profileChanged = pmh && pmh.profileId !== profileId;
if (shouldInsert || profileChanged) {
// insert new record
const newPmh = new PosMasterHistory();
newPmh.ancestorDNA = posMasterDnaId;
newPmh.prefix = pm?.prefix ?? _null;
newPmh.firstName = pm?.firstName ?? _null;
newPmh.lastName = pm?.lastName ?? _null;
newPmh.position = pm?.position ?? _null;
newPmh.posType = pm?.posType ?? _null;
newPmh.posLevel = pm?.posLevel ?? _null;
newPmh.posExecutive = pm?.posExecutive ?? _null;
newPmh.profileId = profileId ?? _null;
newPmh.rootDnaId = pm?.rootDnaId ?? _null;
newPmh.child1DnaId = pm?.child1DnaId ?? _null;
newPmh.child2DnaId = pm?.child2DnaId ?? _null;
newPmh.child3DnaId = pm?.child3DnaId ?? _null;
newPmh.child4DnaId = pm?.child4DnaId ?? _null;
newPmh.shortName = pm?.shortName ?? _null;
newPmh.posMasterNoPrefix = pm?.posMasterNoPrefix ?? _null;
newPmh.posMasterNo = pm?.posMasterNo ?? _null;
newPmh.posMasterNoSuffix = pm?.posMasterNoSuffix ?? _null;
// Add audit fields for data integrity
newPmh.createdUserId = "system";
newPmh.createdFullName = "system";
newPmh.lastUpdateUserId = "system";
newPmh.lastUpdateFullName = "system";
newPmh.createdAt = new Date();
newPmh.lastUpdatedAt = new Date();
await queryRunner.manager.save(PosMasterHistory, newPmh);
return true;
}
return true;
} catch (err) {
console.error("SavePosMasterHistoryOfficer error:", err);
return false;
}
}
export interface BatchPosMasterHistoryOperation {
posMasterDnaId: string;
profileId: string | null;
pm: SavePosMasterHistory | null;
}
export async function BatchSavePosMasterHistoryOfficer(
queryRunner: any,
operations: BatchPosMasterHistoryOperation[],
): Promise<boolean> {
if (operations.length === 0) return true;
try {
const repoPosMasterHistory = queryRunner.manager.getRepository(PosMasterHistory);
const dnaIds = operations.map((op) => op.posMasterDnaId);
// Fetch all existing history records in ONE query
const existingHistory = await repoPosMasterHistory.find({
where: { ancestorDNA: In(dnaIds) },
order: { createdAt: "DESC" },
});
// Build lookup map
const historyByDna = new Map<string, PosMasterHistory[]>();
for (const h of existingHistory) {
if (!historyByDna.has(h.ancestorDNA)) {
historyByDna.set(h.ancestorDNA, []);
}
historyByDna.get(h.ancestorDNA)!.push(h);
}
// Process operations and collect new records
const newRecords: PosMasterHistory[] = [];
const _null: any = null;
for (const op of operations) {
const existing = historyByDna.get(op.posMasterDnaId)?.[0];
const shouldInsert = !existing && op.profileId && op.pm;
const profileChanged = existing && existing.profileId !== op.profileId;
if (shouldInsert || profileChanged) {
const newPmh = new PosMasterHistory();
newPmh.ancestorDNA = op.posMasterDnaId;
newPmh.prefix = op.pm?.prefix ?? _null;
newPmh.firstName = op.pm?.firstName ?? _null;
newPmh.lastName = op.pm?.lastName ?? _null;
newPmh.position = op.pm?.position ?? _null;
newPmh.posType = op.pm?.posType ?? _null;
newPmh.posLevel = op.pm?.posLevel ?? _null;
newPmh.posExecutive = op.pm?.posExecutive ?? _null;
newPmh.profileId = op.profileId ?? _null;
newPmh.rootDnaId = op.pm?.rootDnaId ?? _null;
newPmh.child1DnaId = op.pm?.child1DnaId ?? _null;
newPmh.child2DnaId = op.pm?.child2DnaId ?? _null;
newPmh.child3DnaId = op.pm?.child3DnaId ?? _null;
newPmh.child4DnaId = op.pm?.child4DnaId ?? _null;
newPmh.shortName = op.pm?.shortName ?? _null;
newPmh.posMasterNoPrefix = op.pm?.posMasterNoPrefix ?? _null;
newPmh.posMasterNo = op.pm?.posMasterNo ?? _null;
newPmh.posMasterNoSuffix = op.pm?.posMasterNoSuffix ?? _null;
newPmh.createdUserId = "system";
newPmh.createdFullName = "system";
newPmh.lastUpdateUserId = "system";
newPmh.lastUpdateFullName = "system";
newPmh.createdAt = new Date();
newPmh.lastUpdatedAt = new Date();
newRecords.push(newPmh);
}
}
// Batch insert all new records
if (newRecords.length > 0) {
await queryRunner.manager.save(PosMasterHistory, newRecords);
}
return true;
} catch (err) {
console.error("BatchSavePosMasterHistoryOfficer error:", err);
return false;
}
}