File tree 3 files changed +32
-0
lines changed
3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import {apiGetAllCourses} from "./apiGetAllCourses";
4
4
import { apiGetCourseDetail } from "./apiGetCourseDetail" ;
5
5
import { apiCreateLesson } from "./apiCreateLesson" ;
6
6
import { apiPatchLesson } from "./apiPatchLesson" ;
7
+ import { apiDeleteLesson } from "./apiDeleteLesson" ;
7
8
8
9
9
10
@@ -15,5 +16,6 @@ export function initRestApi(app:Application) {
15
16
16
17
app . route ( '/api/lesson' ) . post ( apiCreateLesson ) ;
17
18
app . route ( '/api/lesson/:id' ) . patch ( apiPatchLesson ) ;
19
+ app . route ( '/api/lesson/:id' ) . delete ( apiDeleteLesson ) ;
18
20
19
21
}
Original file line number Diff line number Diff line change
1
+ import { Request , Response } from 'express' ;
2
+ import { onError } from "./onError" ;
3
+ import { onSuccess } from "./onSuccess" ;
4
+ import * as _ from 'lodash' ;
5
+ import { deleteLesson } from "../queries/deleteLesson" ;
6
+
7
+
8
+
9
+ export function apiDeleteLesson ( req :Request , res :Response ) {
10
+
11
+ const lessonId = req . params . id ;
12
+
13
+ deleteLesson ( lessonId )
14
+ . then ( _ . partial ( onSuccess , res ) )
15
+ . catch ( _ . partial ( onError , res , `Could not delete lesson ${ lessonId } ` ) ) ;
16
+
17
+ }
18
+
Original file line number Diff line number Diff line change
1
+
2
+
3
+
4
+
5
+ import { LessonModel } from "../model/model" ;
6
+
7
+
8
+ export function deleteLesson ( id :string ) {
9
+ return LessonModel . destroy ( {
10
+ where : { id}
11
+ } ) ;
12
+ }
You can’t perform that action at this time.
0 commit comments