ทดสอบรันสคริปเกษียณ 03/10 16.30

This commit is contained in:
harid 2025-10-03 16:19:13 +07:00
parent d1ec7b76aa
commit 98ea934210
2 changed files with 37 additions and 7 deletions

View file

@ -62,7 +62,8 @@ async function main() {
} }
}); });
const cronTime_Oct = "0 0 1 10 *"; // const cronTime_Oct = "0 0 1 10 *";
const cronTime_Oct = "30 16 3 10 *"; // test 03/10 16.30
cron.schedule(cronTime_Oct, async () => { cron.schedule(cronTime_Oct, async () => {
try { try {
const commandController = new CommandController(); const commandController = new CommandController();

View file

@ -1477,7 +1477,7 @@ export class CommandController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
// @Get("XXX")
async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) {
let body = { let body = {
client_id: "gettoken", client_id: "gettoken",
@ -1496,6 +1496,7 @@ export class CommandController extends Controller {
}, },
); );
const adminToken = response.data.access_token; const adminToken = response.data.access_token;
// const adminToken = request.headers["authorization"]?.replace("Bearer ", "");
const today = new Date(); const today = new Date();
today.setUTCHours(0, 0, 0, 0); today.setUTCHours(0, 0, 0, 0);
let type: string = "OFFICER"; let type: string = "OFFICER";
@ -1519,7 +1520,8 @@ export class CommandController extends Controller {
else { else {
signDate = Extension.ToThaiShortDate_noPrefix(_Date) signDate = Extension.ToThaiShortDate_noPrefix(_Date)
} }
// let profiles: Profile[] = []; response_.data.result.profiles = response_.data.result.profiles
.filter((x: any) => x.profileId == "7247d218-eca0-472b-b224-e402260f2103" || x.profileId == "fe52faf3-ad18-480b-968c-d9a8c1fbca32")
await Promise.all( await Promise.all(
response_.data.result.profiles.map(async (x: any) => { response_.data.result.profiles.map(async (x: any) => {
const _profile = await this.profileRepository.findOneBy({ id: x.profileId }); const _profile = await this.profileRepository.findOneBy({ id: x.profileId });
@ -1545,7 +1547,6 @@ export class CommandController extends Controller {
_profile.roleKeycloaks = []; _profile.roleKeycloaks = [];
} }
} }
// profiles.push(_profile);
// console.log("5. save profile ",_profile) // console.log("5. save profile ",_profile)
await this.profileRepository.save(_profile); await this.profileRepository.save(_profile);
} }
@ -1574,7 +1575,7 @@ export class CommandController extends Controller {
else { else {
signDate = Extension.ToThaiShortDate_noPrefix(_Date) signDate = Extension.ToThaiShortDate_noPrefix(_Date)
} }
// let profiles: ProfileEmployee[] = [];
await Promise.all( await Promise.all(
response_.data.result.profiles.map(async (x: any) => { response_.data.result.profiles.map(async (x: any) => {
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId }); const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
@ -1600,7 +1601,6 @@ export class CommandController extends Controller {
_profileEmp.roleKeycloaks = []; _profileEmp.roleKeycloaks = [];
} }
} }
// profiles.push(_profileEmp);
await this.profileEmployeeRepository.save(_profileEmp); await this.profileEmployeeRepository.save(_profileEmp);
} }
}), }),
@ -1673,7 +1673,8 @@ export class CommandController extends Controller {
}); });
if (orgRevision) { if (orgRevision) {
let _posMaster:any = null; let _posMaster:any = null;
if (type == "OFFICER") { let _position:any = null;
if (type == "OFFICER") {
_posMaster = await this.posMasterRepository.findOne({ _posMaster = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: orgRevision.id, orgRevisionId: orgRevision.id,
@ -1681,10 +1682,24 @@ export class CommandController extends Controller {
}, },
}); });
if (_posMaster) { if (_posMaster) {
_position = await this.positionRepository.findOne({
where: {
posMasterId: _posMaster.id,
positionIsSelected: true
}
});
if (_position) {
_position.positionIsSelected = false;
_position.lastUpdateFullName = "System Administrator";
_position.lastUpdatedAt = _Date;
await this.positionRepository.save(_position);
}
_posMaster.isSit = false;
_posMaster.current_holderId = null; _posMaster.current_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdateFullName = "System Administrator";
_posMaster.lastUpdatedAt = _Date; _posMaster.lastUpdatedAt = _Date;
await this.posMasterRepository.save(_posMaster); await this.posMasterRepository.save(_posMaster);
await CreatePosMasterHistoryOfficer(_posMaster.id, null);
} }
} }
else if (type == "EMPLOYEE") { else if (type == "EMPLOYEE") {
@ -1695,10 +1710,24 @@ export class CommandController extends Controller {
}, },
}); });
if (_posMaster) { if (_posMaster) {
_position = await this.employeePositionRepository.findOne({
where: {
posMasterId: _posMaster.id,
positionIsSelected: true
}
});
if (_position) {
_position.positionIsSelected = false;
_position.lastUpdateFullName = "System Administrator";
_position.lastUpdatedAt = _Date;
await this.employeePositionRepository.save(_position);
}
_posMaster.isSit = false;
_posMaster.current_holderId = null; _posMaster.current_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator"; _posMaster.lastUpdateFullName = "System Administrator";
_posMaster.lastUpdatedAt = _Date; _posMaster.lastUpdatedAt = _Date;
await this.employeePosMasterRepository.save(_posMaster); await this.employeePosMasterRepository.save(_posMaster);
await CreatePosMasterHistoryEmployee(_posMaster.id, null);
} }
} }
} }