Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - Add list of students #185

Merged
merged 4 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions back-end/src/base/calls/calls.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ export class CallsController {
const actualCourse = await this.callsService.getActualCourse(userId);
return res.status(201).json({ status: 'ok', actualCourse: actualCourse });
}

@Get('/student_list/:courseId')
@UseGuards(JwtAuthGuard)
async studentList(@Param() courseId: CourseIdObject, @Res() res: Response) {
const studentIdList = await this.callsService.getStudentList(courseId);
const studentList = await Promise.all(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using Promise.all(...)
You can do : collection.find( { _id: { $in: [ObjectId("id"),...,...] } }).toArray()

studentIdList.map(async (studentId) => {
const student = await this.callsService.usersRepository.findOne({ _id: studentId });
return student;
}),
);
return res.status(201).json({ status: 'ok', studentList: studentList });
}
}
10 changes: 9 additions & 1 deletion back-end/src/base/calls/calls.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export class CallsRepository {
message: 'User presence updated successfully',
};
}

isStudentLate(period, timeOfScan) {
if (period === 'arrival') {
const fakeDate = new Date('2023-03-23T08:00:00.105Z');
Expand Down Expand Up @@ -139,4 +138,13 @@ export class CallsRepository {
});
return studentClass ? studentClass._id : null;
}

async getStudentList(courseId: string) {
const courseObjectId = new ObjectId(courseId);
const course = await this.db.collection('courses').findOne({ _id: courseObjectId });
const classId = course.classId;
const classroom = await this.db.collection('classes').findOne({ _id: classId });

return classroom.students;
}
}
6 changes: 5 additions & 1 deletion back-end/src/base/calls/calls.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CallsService {
constructor(
@Inject(forwardRef(() => UsersRepository))
@Inject(forwardRef(() => CallsRepository))
private usersRepository: UsersRepository,
public usersRepository: UsersRepository,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.

private callsRepository: CallsRepository,
private jwtTokenService: JwtService,
) {}
Expand Down Expand Up @@ -42,4 +42,8 @@ export class CallsService {
const actualCourse = await this.callsRepository.getActualCourse(userId);
return actualCourse;
}

getStudentList(courseId: CourseIdObject) {
return this.callsRepository.getStudentList(courseId.courseId);
}
}
14 changes: 14 additions & 0 deletions front-end/src/components/RollCallComponents/QrCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<div v-else>
<p>{{ message }}</p>
</div>
<div v-if="studentList">
<div v-for="student in studentList" :key="student.id">
<p>{{ student.profile.firstName }} {{ student.profile.lastName }}</p>
</div>
</div>
</div>
</template>

Expand All @@ -14,6 +19,7 @@ import { http } from '@/api/network/axios';
let url = '';
let courseId = '';
let message = '';
let studentList = [];

export default {
name: 'QrCode',
Expand All @@ -25,6 +31,7 @@ export default {
url,
courseId,
message,
studentList,
QrGen: '',
};
},
Expand Down Expand Up @@ -54,11 +61,18 @@ export default {
isThereCourse() {
if (this.courseId) {
this.getQrCode();
this.getStudentList();
this.message = '';
} else {
this.message = "Vous n'avez pas de cours aujourd'hui";
}
},

getStudentList() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use -> getStudentList: withErrorHandler(async function() {
...
})

If the call return an error, your page crash.

http.get(`/calls/student_list/${this.courseId}`).then((response) => {
this.studentList = response.data.studentList;
});
},
},
};
</script>