Skip to content

Commit

Permalink
Merge pull request #1022 from tekdi/feat-event
Browse files Browse the repository at this point in the history
Merge `Feat event` into `Release 2.0.0`
  • Loading branch information
sagarkoshti1990 authored Apr 18, 2024
2 parents 62fd3c7 + 53a5b14 commit 7891406
Show file tree
Hide file tree
Showing 2 changed files with 360 additions and 211 deletions.
66 changes: 47 additions & 19 deletions src/src/cron/prepareCertificateHtml.cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class PrepareCertificateHtmlCron {
@Cron(CronExpression.EVERY_5_MINUTES)
async prepareCertificateHtml() {
console.log('cron job: issueCertificate started at time ' + new Date());

//fetch all test tracking data which has certificate_status null
const userForIssueCertificate = await this.fetchTestTrackingData(
parseInt(
Expand All @@ -48,25 +49,26 @@ export class PrepareCertificateHtmlCron {
let test_id = userTestData?.test_id;
let context = userTestData?.context;
let context_id = userTestData?.context_id;
let getUserList = await this.userService.getUserName(user_id);
let user_name = '';
if (getUserList.length > 0) {
user_name += getUserList[0]?.first_name
? (await this.method.CapitalizeEachWord(
getUserList[0].first_name,
)) + ' '
: '';
user_name += getUserList[0]?.middle_name
? (await this.method.CapitalizeEachWord(
getUserList[0].middle_name,
)) + ' '
: '';
user_name += getUserList[0]?.last_name
? (await this.method.CapitalizeEachWord(
getUserList[0].last_name,
)) + ' '
: '';
}

const user_name = await this.method.CapitalizeEachWord(
[
userTestData?.user?.first_name,
userTestData?.user?.middle_name,
userTestData?.user?.last_name,
]
.filter((e) => e)
.join(' '),
);

const event_start_date = moment(
userTestData?.events?.[0]?.start_date,
).format('DD MMM YYYY');
const event_end_date = moment(
userTestData?.events?.[0]?.end_date,
).format('DD MMM YYYY');
const academic_year =
userTestData?.events?.[0]?.academic_year?.name;

//get attendance status
let attendance_valid = false;
let usrAttendanceList =
Expand Down Expand Up @@ -112,6 +114,18 @@ export class PrepareCertificateHtmlCron {
let certificate_id = certificate_data?.id;
let uid = 'P-' + certificate_id + '-' + user_id;
//update html code
certificateTemplate = certificateTemplate.replace(
'{{academic_year}}',
academic_year,
);
certificateTemplate = certificateTemplate.replace(
'{{event_start_date}}',
event_start_date,
);
certificateTemplate = certificateTemplate.replace(
'{{event_end_date}}',
event_end_date,
);
certificateTemplate = certificateTemplate.replace(
'{{name}}',
user_name,
Expand Down Expand Up @@ -247,6 +261,20 @@ export class PrepareCertificateHtmlCron {
score
context
context_id
user{
first_name
middle_name
last_name
}
events(where:{context:{_eq:"events"}}){
id
start_date
end_date
academic_year{
name
}
}
}
}
`;
Expand Down
Loading

0 comments on commit 7891406

Please sign in to comment.