Skip to content

Commit

Permalink
modify how sql get all data request history, add api for getting acce…
Browse files Browse the repository at this point in the history
…ss list of capture
  • Loading branch information
ho-yi-shiuan committed Dec 14, 2021
1 parent f50c109 commit ccb5370
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 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 * 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: {accessList}
};
};

module.exports = {
getCourseList,
getCourseListByInstructor,
Expand All @@ -151,5 +160,6 @@ module.exports = {
editCourse,
editMultipleCourse,
getAllSemesters,
deleteCourse
deleteCourse,
getCourseAccess
};
17 changes: 12 additions & 5 deletions backend/service/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ const exportMetricCsv = async(data) => {
const getAllCsvExport = async(data) => {
let userId = data.userId;
results = await pool.query(dataQuery.getAllDataRequest,userId);
for(i=0;i<results[0].length;i++){
results[0][i].message = JSON.parse(results[0][i].message);
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 ccb5370

Please sign in to comment.