Skip to content

Commit

Permalink
Merge branch 'tekdi:release-2.1.0' into release-2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PrasadAthani authored Apr 23, 2024
2 parents 001c499 + 6e79439 commit d74b5b1
Show file tree
Hide file tree
Showing 12 changed files with 652 additions and 66 deletions.
2 changes: 2 additions & 0 deletions src/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { UserauthModule } from './userauth/userauth.module';
import { BoardModule } from './modules/board/board.module';
import { OrganisationModule } from './organisation/organisation.module';
import { ObservationsModule } from './observations/observations.module';
import { ExamModule } from './exam/exam.module';
@Module({
imports: [
ScheduleModule.forRoot(),
Expand Down Expand Up @@ -89,6 +90,7 @@ import { ObservationsModule } from './observations/observations.module';
UserauthModule,
OrganisationModule,
ObservationsModule,
ExamModule,
],
controllers: [],
providers: [CacheCleanerProvider],
Expand Down
11 changes: 9 additions & 2 deletions src/src/attendances/attendances.core.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,22 @@ export class AttendancesCoreService {
return result;
}

async getUserAttendancePresentList(user_id, context, context_id) {
async getUserAttendancePresentList({
user_id,
context,
context_id,
event_end_date,
event_start_date,
}) {
const query = `query MyQuery {
attendance(where: {user_id: {_eq: ${user_id}}, context: {_eq: ${context}}, context_id: {_eq:${context_id}}, status: {_eq: "present"}}) {
attendance(where: {user_id: {_eq: ${user_id}}, context: {_eq: ${context}}, context_id: {_eq:${context_id}}, status: {_eq: "present"}, date_time: {_gte: "${event_start_date}", _lte: "${event_end_date}"}}, distinct_on: date_time) {
id
status
context
context_id
}
}`;

try {
const result_response =
await this.hasuraServiceFromServices.getData({ query });
Expand Down
1 change: 1 addition & 0 deletions src/src/camp/camp.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Req,
Res,
Response,
Request,
UseGuards,
UsePipes,
ValidationPipe,
Expand Down
47 changes: 34 additions & 13 deletions src/src/cron/prepareCertificateHtml.cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { html_code } from 'src/lms/certificate_html';
import { LMSCertificateDto } from 'src/lms/dto/lms-certificate.dto';
import { UserService } from 'src/user/user.service';
import { HasuraService } from '../services/hasura/hasura.service';
import { json } from 'stream/consumers';

const moment = require('moment');
const qr = require('qrcode');
Expand Down Expand Up @@ -71,21 +72,35 @@ export class PrepareCertificateHtmlCron {

//get attendance status
let attendance_valid = false;
const startMoment = moment(
userTestData?.events?.[0]?.start_date,
);
const endMoment = moment(userTestData?.events?.[0]?.end_date);
let datesD = [];
while (startMoment.isSameOrBefore(endMoment)) {
datesD.push(startMoment.format('YYYY-MM-DD'));
startMoment.add(1, 'day');
}

let usrAttendanceList =
await this.attendanceCoreService.getUserAttendancePresentList(
user_id,
context,
context_id,
{
user_id,
context,
context_id,
event_start_date: `${userTestData?.events?.[0]?.start_date}T00:00:00`,
event_end_date: `${userTestData?.events?.[0]?.end_date}T23:59:59`,
},
);

console.log('usrAttendanceList list', usrAttendanceList);
let minAttendance = parseInt(
this.configService.get<string>(
'LMS_CERTIFICATE_ISSUE_MIN_ATTENDANCE',
),
);
console.log('events-dates', JSON.stringify(datesD));
let minAttendance = datesD.length;

if (usrAttendanceList.length >= minAttendance) {
attendance_valid = true;
}

//check certificate criteria
if (userTestData?.score >= minPercentage && attendance_valid) {
issue_status = 'true';
Expand Down Expand Up @@ -217,10 +232,19 @@ export class PrepareCertificateHtmlCron {
if (issue_status == 'true') {
testTrackingUpdateData['certificate_status'] = issue_status;
}
await this.updateTestTrackingData(
const result = await this.updateTestTrackingData(
userTestData?.id,
testTrackingUpdateData,
);
if (issue_status === 'false') {
console.log(
`user_id ${user_id} name ${user_name} testID ${test_id} Not Genrated event date count ${minAttendance} attendance count ${usrAttendanceList.length}`,
);
} else if (result) {
console.log(
`user_id ${user_id} name ${user_name} testID ${test_id} Certificate Genrated Sucssefully`,
);
}
}
}
}
Expand Down Expand Up @@ -278,10 +302,9 @@ export class PrepareCertificateHtmlCron {
}
}
`;
console.log('fetchTestTrackingData query', query);

try {
const result_query = await this.hasuraService.getData({ query });
console.log('result_query', result_query);
const data_list = result_query?.data?.lms_test_tracking;
if (data_list) {
return data_list;
Expand Down Expand Up @@ -382,8 +405,6 @@ export class PrepareCertificateHtmlCron {
}
}
async updateTestTrackingData(id, testTrackingUpdateData) {
console.log('id', id);
console.log('testTrackingUpdateData', testTrackingUpdateData);
let setQuery = ``;
if (testTrackingUpdateData?.certificate_status) {
setQuery += `certificate_status: ${testTrackingUpdateData.certificate_status}`;
Expand Down
10 changes: 10 additions & 0 deletions src/src/events/events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,14 @@ export class EventsController {
) {
return this.eventsService.campParamsCross(id, body, request, response);
}

@Patch('/admin/:id/start-exam')
@UseGuards(new AuthGuard())
eventStartExam(
@Param('id') id: any,
@Req() request: any,
@Res() response: any,
) {
return this.eventsService.eventStartExam(id, request, response);
}
}
129 changes: 105 additions & 24 deletions src/src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,13 @@ export class EventsService {
);

if (body?.start_date) {
filter.push(`start_date: {_eq:"${body?.start_date}"}`);
filter.push(`start_date: {_gte:"${body?.start_date}"}`);
}

if (body?.end_date) {
filter.push(`end_date: {_eq:"${body?.end_date}"}`);
filter.push(`end_date: {_lte:"${body?.end_date}"}`);
} else if (body?.start_date) {
filter.push(`end_date: {_lte:"${body?.start_date}"}`);
}

const allIpList = getIps?.data?.users.map((curr) => curr.id);
Expand Down Expand Up @@ -342,28 +344,6 @@ export class EventsService {
created_by
updated_by
user_id
attendances {
context
context_id
created_by
date_time
id
lat
long
rsvp
status
updated_by
user_id
user {
first_name
id
last_name
middle_name
profile_url
aadhar_verified
aadhaar_verification_mode
}
}
}
}`,
};
Expand Down Expand Up @@ -435,6 +415,27 @@ export class EventsService {
try {
const userDetail = await this.userService.ipUserInfo(header);
const user_id = userDetail.data.id;
let data = {
query: `query MyQuery {
events_by_pk(id: ${id}) {
id
params
}
}`,
};

const result = await this.hasuraServiceFromServices.getData(data);
const event_res = result?.data?.events_by_pk;
const check_params = event_res?.params;
if (check_params?.start_exam === 'yes') {
return resp.status(422).send({
success: false,
message:
'Event Can Not Edited As Event Exam has already started!',
data: {},
});
}

// Validate start date
const daysDiff = moment
.utc(req.end_date)
Expand Down Expand Up @@ -1138,4 +1139,84 @@ export class EventsService {
return response.status(400).json({ message: e.message });
}
}

public async eventStartExam(id: number, req: any, resp: any) {
const user_id = req?.mw_userid;
const role = req?.mw_roles;
const academic_year_id = req?.mw_academic_year_id;
const program_id = req?.mw_program_id;

let data = {
query: `query MyQuery {
events(where: {id: {_eq: ${id}},academic_year_id: {_eq: ${academic_year_id}}, program_id: {_eq: ${program_id}}}) {
id
params
created_by
}
}`,
};
const result = await this.hasuraServiceFromServices.getData(data);
const event_res = result?.data?.events?.[0];
const check_params = event_res?.params;
const created_by = event_res?.created_by;

//if params already have exam started
if (
check_params?.do_id &&
check_params.do_id.length > 0 &&
check_params?.start_exam === 'yes'
) {
return resp.status(422).send({
success: false,
message: 'Event exam has already started!',
data: {},
});
}
if (!event_res || event_res === '') {
return resp.status(422).send({
success: false,
message: 'Event Does Not Exist!',
data: {},
});
} else if (!check_params || check_params === '') {
return resp.status(422).send({
success: false,
message: 'Does Not Have Exam IDS',
data: {},
});
}

//if role is not equal to PO admin
if (!role.includes('program_owner') && created_by != user_id) {
//IS created by IP user check with created by id
return resp.status(422).send({
success: false,
message: 'Admin Dont have access to Start Exam of this Event!',
data: {},
});
}

// Update the params object with start_exam: "yes"
const eventResult = await this.hasuraService.updateWithVariable(
id,
'events',
{ params: { ...check_params, start_exam: 'yes' } },
[],
['id', 'params'],
{
variable: [
{
key: 'params',
type: 'json',
},
],
},
);

return resp.status(200).send({
success: true,
message: 'Exam Started!',
data: eventResult,
});
}
}
18 changes: 18 additions & 0 deletions src/src/exam/exam.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ExamController } from './exam.controller';

describe('ExamController', () => {
let controller: ExamController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ExamController],
}).compile();

controller = module.get<ExamController>(ExamController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Loading

0 comments on commit d74b5b1

Please sign in to comment.