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

modify sql method of getting all data requests and build capture access api #46

Merged
merged 3 commits into from
Dec 14, 2021
Merged
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
10 changes: 9 additions & 1 deletion backend/controller/course.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const express = require("express");
const { getCourseList, getCourseListByInstructor, getCourseDetail, getAllCourses, createCourse, editCourse, editMultipleCourse, getAllSemesters, deleteCourse } = require("../service/course");
const { getCourseList, getCourseListByInstructor, getCourseDetail, getAllCourses, createCourse, editCourse, editMultipleCourse, getAllSemesters, deleteCourse, getCourseAccess } = require("../service/course");
const courseController = express.Router();

// Query course list by user id
@@ -78,4 +78,12 @@ courseController.delete("/delete",
}
);

//get access list of courses by course id
courseController.get("/permissions/:courseId",
async (req, res) => {
const { courseId } = req.params;
const results = await getCourseAccess(courseId);
res.status(results.code || 200).json(results.data);
});

module.exports = courseController;
10 changes: 8 additions & 2 deletions backend/query/course.js
Original file line number Diff line number Diff line change
@@ -92,7 +92,12 @@ FROM KP_Semester;
const deleteCourseQuery = `
DELETE FROM KP_Course
WHERE course_id = ?;
`;
`
const getCourseAccessByCouseId = `
SELECT * FROM can_access_capture_files
WHERE couse_id = ?
`

module.exports = {
getCourseList,
getCourseListByInstructor,
@@ -106,5 +111,6 @@ module.exports = {
unregisterUser,
editMultipleCourses,
getSemestersQuery,
deleteCourseQuery
deleteCourseQuery,
getCourseAccessByCouseId
};
12 changes: 11 additions & 1 deletion backend/service/course.js
Original file line number Diff line number Diff line change
@@ -142,6 +142,15 @@ const deleteCourse = async({courseId}) => {
}
}

//get access list of courses by course id
const getCourseAccess = async courseId => {
const accessResults = await pool.execute(courseQuery.getCourseAccessByCouseId, [courseId]);
const accessList = accessResults[0];
return {
data: {accessList}
};
};

module.exports = {
getCourseList,
getCourseListByInstructor,
@@ -151,5 +160,6 @@ module.exports = {
editCourse,
editMultipleCourse,
getAllSemesters,
deleteCourse
deleteCourse,
getCourseAccess
};
19 changes: 13 additions & 6 deletions backend/service/data.js
Original file line number Diff line number Diff line change
@@ -54,13 +54,20 @@ const exportMetricCsv = async(data) => {

const getAllCsvExport = async(data) => {
let userId = data.userId;
results = await pool.execute(dataQuery.getAllDataRequest,[userId]);
for(i=0;i<results[0].length;i++){
results[0][i].message = JSON.parse(results[0][i].message);
results = await pool.query(dataQuery.getAllDataRequest,userId);
if(results[0].length > 0){
for(i=0;i<results[0].length;i++){
results[0][i].message = JSON.parse(results[0][i].message);
}
return {
data: results[0]
};
}else{
return {
data: []
}
}
return {
data: results[0]
};

}

const getDownloadLink = async(request) => {