Skip to content

Commit

Permalink
Merge pull request #46 from gelic-idealab/dev
Browse files Browse the repository at this point in the history
modify sql method of getting all data requests and build capture access api
  • Loading branch information
parseccentric authored Dec 14, 2021
2 parents 9a8f612 + eb3285d commit 21aeb50
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
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
Expand Down Expand Up @@ -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
Expand Up @@ -92,7 +92,12 @@ FROM KP_Semester;
const deleteCourseQuery = `
DELETE FROM KP_Course
WHERE course_id = ?;
`;
`
const getCourseAccessByCouseId = `
SELECT client_id FROM can_access_capture_files
WHERE couse_id = ?
`

module.exports = {
getCourseList,
getCourseListByInstructor,
Expand All @@ -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
Expand Up @@ -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: {courseId: courseId, accessList: accessList}
};
};

module.exports = {
getCourseList,
getCourseListByInstructor,
Expand All @@ -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
Expand Up @@ -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) => {
Expand Down

0 comments on commit 21aeb50

Please sign in to comment.