Skip to content

Commit 7891406

Browse files
Merge pull request #1022 from tekdi/feat-event
Merge `Feat event` into `Release 2.0.0`
2 parents 62fd3c7 + 53a5b14 commit 7891406

File tree

2 files changed

+360
-211
lines changed

2 files changed

+360
-211
lines changed

src/src/cron/prepareCertificateHtml.cron.ts

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class PrepareCertificateHtmlCron {
2626
@Cron(CronExpression.EVERY_5_MINUTES)
2727
async prepareCertificateHtml() {
2828
console.log('cron job: issueCertificate started at time ' + new Date());
29+
2930
//fetch all test tracking data which has certificate_status null
3031
const userForIssueCertificate = await this.fetchTestTrackingData(
3132
parseInt(
@@ -48,25 +49,26 @@ export class PrepareCertificateHtmlCron {
4849
let test_id = userTestData?.test_id;
4950
let context = userTestData?.context;
5051
let context_id = userTestData?.context_id;
51-
let getUserList = await this.userService.getUserName(user_id);
52-
let user_name = '';
53-
if (getUserList.length > 0) {
54-
user_name += getUserList[0]?.first_name
55-
? (await this.method.CapitalizeEachWord(
56-
getUserList[0].first_name,
57-
)) + ' '
58-
: '';
59-
user_name += getUserList[0]?.middle_name
60-
? (await this.method.CapitalizeEachWord(
61-
getUserList[0].middle_name,
62-
)) + ' '
63-
: '';
64-
user_name += getUserList[0]?.last_name
65-
? (await this.method.CapitalizeEachWord(
66-
getUserList[0].last_name,
67-
)) + ' '
68-
: '';
69-
}
52+
53+
const user_name = await this.method.CapitalizeEachWord(
54+
[
55+
userTestData?.user?.first_name,
56+
userTestData?.user?.middle_name,
57+
userTestData?.user?.last_name,
58+
]
59+
.filter((e) => e)
60+
.join(' '),
61+
);
62+
63+
const event_start_date = moment(
64+
userTestData?.events?.[0]?.start_date,
65+
).format('DD MMM YYYY');
66+
const event_end_date = moment(
67+
userTestData?.events?.[0]?.end_date,
68+
).format('DD MMM YYYY');
69+
const academic_year =
70+
userTestData?.events?.[0]?.academic_year?.name;
71+
7072
//get attendance status
7173
let attendance_valid = false;
7274
let usrAttendanceList =
@@ -112,6 +114,18 @@ export class PrepareCertificateHtmlCron {
112114
let certificate_id = certificate_data?.id;
113115
let uid = 'P-' + certificate_id + '-' + user_id;
114116
//update html code
117+
certificateTemplate = certificateTemplate.replace(
118+
'{{academic_year}}',
119+
academic_year,
120+
);
121+
certificateTemplate = certificateTemplate.replace(
122+
'{{event_start_date}}',
123+
event_start_date,
124+
);
125+
certificateTemplate = certificateTemplate.replace(
126+
'{{event_end_date}}',
127+
event_end_date,
128+
);
115129
certificateTemplate = certificateTemplate.replace(
116130
'{{name}}',
117131
user_name,
@@ -247,6 +261,20 @@ export class PrepareCertificateHtmlCron {
247261
score
248262
context
249263
context_id
264+
user{
265+
first_name
266+
middle_name
267+
last_name
268+
}
269+
events(where:{context:{_eq:"events"}}){
270+
id
271+
start_date
272+
end_date
273+
academic_year{
274+
name
275+
}
276+
277+
}
250278
}
251279
}
252280
`;

0 commit comments

Comments
 (0)