Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop
This commit is contained in:
commit
c9e83aebc9
3 changed files with 151 additions and 54 deletions
10
src/app.ts
10
src/app.ts
|
|
@ -56,6 +56,16 @@ async function main() {
|
|||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
});
|
||||
|
||||
const cronTime_Oct = "0 0 1 10 *";
|
||||
cron.schedule(cronTime_Oct, async () => {
|
||||
try {
|
||||
const commandController = new CommandController();
|
||||
await commandController.cronjobUpdateRetirementStatus();
|
||||
} catch (error) {
|
||||
console.error("Error executing function from controller:", error);
|
||||
}
|
||||
});
|
||||
|
||||
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||
app.listen(
|
||||
|
|
|
|||
|
|
@ -1329,6 +1329,93 @@ export class CommandController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
async cronjobUpdateRetirementStatus() {
|
||||
let body = {
|
||||
client_id: "gettoken",
|
||||
client_secret: process.env.AUTH_ACCOUNT_SECRET,
|
||||
grant_type: "client_credentials",
|
||||
};
|
||||
const postData = querystring.stringify(body);
|
||||
const response = await axios.post(
|
||||
`${process.env.KC_URL}/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`,
|
||||
postData,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
},
|
||||
);
|
||||
const adminToken = response.data.access_token;
|
||||
const today = new Date();
|
||||
today.setUTCHours(0, 0, 0, 0);
|
||||
let type: string = "OFFICER"
|
||||
try {
|
||||
const response_ = await axios.get(
|
||||
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${adminToken}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (response && response_.data.result.length > 0) {
|
||||
let profiles: Profile[] = [];
|
||||
await Promise.all(
|
||||
response_.data.result.map(async (x:any) => {
|
||||
const _profile = await this.profileRepository.findOneBy({ id: x.profileId });
|
||||
if (_profile) {
|
||||
_profile.isRetirement = true;
|
||||
_profile.isLeave = true;
|
||||
_profile.leaveType = "RETIRE";
|
||||
_profile.leaveDate = new Date();
|
||||
_profile.dateLeave = new Date();
|
||||
_profile.lastUpdatedAt = new Date();
|
||||
profiles.push(_profile);
|
||||
}
|
||||
})
|
||||
);
|
||||
await this.profileRepository.save(profiles);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
type = "EMPLOYEE"
|
||||
try {
|
||||
const response_ = await axios.get(
|
||||
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${adminToken}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (response && response_.data.result.length > 0) {
|
||||
let profiles: ProfileEmployee[] = [];
|
||||
await Promise.all(
|
||||
response_.data.result.map(async (x:any) => {
|
||||
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
|
||||
if (_profileEmp) {
|
||||
_profileEmp.isRetirement = true;
|
||||
_profileEmp.isLeave = true;
|
||||
_profileEmp.leaveType = "RETIRE";
|
||||
_profileEmp.leaveDate = new Date();
|
||||
_profileEmp.dateLeave = new Date();
|
||||
_profileEmp.lastUpdatedAt = new Date();
|
||||
profiles.push(_profileEmp);
|
||||
}
|
||||
})
|
||||
);
|
||||
await this.profileEmployeeRepository.save(profiles);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการคำสั่ง tab4 คำสั่ง
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1160,59 +1160,59 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
return new HttpSuccess("Email verified successfully.");
|
||||
}
|
||||
|
||||
@Patch("retirement")
|
||||
public async updateStatusRetirement(
|
||||
@Body()
|
||||
body: {
|
||||
data: {
|
||||
profileId: string;
|
||||
}[];
|
||||
},
|
||||
) {
|
||||
let profiles: Profile[] = [];
|
||||
let _null: any = null;
|
||||
await Promise.all(
|
||||
body.data.map(async (item) => {
|
||||
const _profile = await this.profileRepo.findOneBy({ id: item.profileId });
|
||||
if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
_profile.isRetirement = true;
|
||||
_profile.isLeave = true;
|
||||
_profile.leaveType = "RETIRE";
|
||||
_profile.leaveDate = new Date();
|
||||
_profile.dateLeave = new Date();
|
||||
_profile.lastUpdatedAt = new Date();
|
||||
profiles.push(_profile);
|
||||
})
|
||||
);
|
||||
await this.profileRepo.save(profiles);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
// @Patch("retirement")
|
||||
// public async updateStatusRetirement(
|
||||
// @Body()
|
||||
// body: {
|
||||
// data: {
|
||||
// profileId: string;
|
||||
// }[];
|
||||
// },
|
||||
// ) {
|
||||
// let profiles: Profile[] = [];
|
||||
// let _null: any = null;
|
||||
// await Promise.all(
|
||||
// body.data.map(async (item) => {
|
||||
// const _profile = await this.profileRepo.findOneBy({ id: item.profileId });
|
||||
// if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// _profile.isRetirement = true;
|
||||
// _profile.isLeave = true;
|
||||
// _profile.leaveType = "RETIRE";
|
||||
// _profile.leaveDate = new Date();
|
||||
// _profile.dateLeave = new Date();
|
||||
// _profile.lastUpdatedAt = new Date();
|
||||
// profiles.push(_profile);
|
||||
// })
|
||||
// );
|
||||
// await this.profileRepo.save(profiles);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
@Patch("retirement-employee")
|
||||
public async updateStatusRetirementEmp(
|
||||
@Body()
|
||||
body: {
|
||||
data: {
|
||||
profileId: string;
|
||||
}[];
|
||||
},
|
||||
) {
|
||||
let profiles: ProfileEmployee[] = [];
|
||||
let _null: any = null;
|
||||
await Promise.all(
|
||||
body.data.map(async (item) => {
|
||||
const _profile = await this.profileEmpRepo.findOneBy({ id: item.profileId });
|
||||
if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
_profile.isRetirement = true;
|
||||
_profile.isLeave = true;
|
||||
_profile.leaveType = "RETIRE";
|
||||
_profile.leaveDate = new Date();
|
||||
_profile.dateLeave = new Date();
|
||||
_profile.lastUpdatedAt = new Date();
|
||||
profiles.push(_profile);
|
||||
})
|
||||
);
|
||||
await this.profileEmpRepo.save(profiles);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
// @Patch("retirement-employee")
|
||||
// public async updateStatusRetirementEmp(
|
||||
// @Body()
|
||||
// body: {
|
||||
// data: {
|
||||
// profileId: string;
|
||||
// }[];
|
||||
// },
|
||||
// ) {
|
||||
// let profiles: ProfileEmployee[] = [];
|
||||
// let _null: any = null;
|
||||
// await Promise.all(
|
||||
// body.data.map(async (item) => {
|
||||
// const _profile = await this.profileEmpRepo.findOneBy({ id: item.profileId });
|
||||
// if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// _profile.isRetirement = true;
|
||||
// _profile.isLeave = true;
|
||||
// _profile.leaveType = "RETIRE";
|
||||
// _profile.leaveDate = new Date();
|
||||
// _profile.dateLeave = new Date();
|
||||
// _profile.lastUpdatedAt = new Date();
|
||||
// profiles.push(_profile);
|
||||
// })
|
||||
// );
|
||||
// await this.profileEmpRepo.save(profiles);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue