1
1
import { Router } from "express" ;
2
- import CourseService from "../services/implementations/courseService " ;
2
+ import CourseUnitService from "../services/implementations/courseUnitService " ;
3
3
import { getErrorMessage } from "../utilities/errorUtils" ;
4
4
import {
5
5
createCourseUnitDtoValidator ,
@@ -8,14 +8,14 @@ import {
8
8
import { isAuthorizedByRole } from "../middlewares/auth" ;
9
9
10
10
const courseRouter : Router = Router ( ) ;
11
- const courseService : CourseService = new CourseService ( ) ;
11
+ const courseUnitService : CourseUnitService = new CourseUnitService ( ) ;
12
12
13
13
courseRouter . get (
14
14
"/" ,
15
- isAuthorizedByRole ( new Set ( [ "Administrator" ] ) ) ,
15
+ isAuthorizedByRole ( new Set ( [ "Administrator" , "Facilitator" , "Learner" ] ) ) ,
16
16
async ( req , res ) => {
17
17
try {
18
- const courses = await courseService . getCourseUnits ( ) ;
18
+ const courses = await courseUnitService . getCourseUnits ( ) ;
19
19
res . status ( 200 ) . json ( courses ) ;
20
20
} catch ( e : unknown ) {
21
21
res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
@@ -29,7 +29,7 @@ courseRouter.post(
29
29
createCourseUnitDtoValidator ,
30
30
async ( req , res ) => {
31
31
try {
32
- const newCourse = await courseService . createCourseUnit ( {
32
+ const newCourse = await courseUnitService . createCourseUnit ( {
33
33
title : req . body . title ,
34
34
} ) ;
35
35
res . status ( 201 ) . json ( newCourse ) ;
@@ -40,13 +40,13 @@ courseRouter.post(
40
40
) ;
41
41
42
42
courseRouter . put (
43
- "/:id " ,
43
+ "/:unitId " ,
44
44
isAuthorizedByRole ( new Set ( [ "Administrator" ] ) ) ,
45
45
updateCourseUnitDtoValidator ,
46
46
async ( req , res ) => {
47
- const { id } = req . params ;
47
+ const { unitId } = req . params ;
48
48
try {
49
- const course = await courseService . updateCourseUnit ( id , {
49
+ const course = await courseUnitService . updateCourseUnit ( unitId , {
50
50
title : req . body . title ,
51
51
} ) ;
52
52
res . status ( 200 ) . json ( course ) ;
@@ -57,12 +57,14 @@ courseRouter.put(
57
57
) ;
58
58
59
59
courseRouter . delete (
60
- "/:id " ,
60
+ "/:unitId " ,
61
61
isAuthorizedByRole ( new Set ( [ "Administrator" ] ) ) ,
62
62
async ( req , res ) => {
63
- const { id } = req . params ;
63
+ const { unitId } = req . params ;
64
64
try {
65
- const deletedCourseUnitId = await courseService . deleteCourseUnit ( id ) ;
65
+ const deletedCourseUnitId = await courseUnitService . deleteCourseUnit (
66
+ unitId ,
67
+ ) ;
66
68
res . status ( 200 ) . json ( { id : deletedCourseUnitId } ) ;
67
69
} catch ( e : unknown ) {
68
70
res . status ( 500 ) . send ( getErrorMessage ( e ) ) ;
0 commit comments