Skip to content

Commit bdcaab2

Browse files
author
Your Name
committed
typescript course ongoing
1 parent aa5f453 commit bdcaab2

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

server/api/api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {apiGetAllCourses} from "./apiGetAllCourses";
44
import {apiGetCourseDetail} from "./apiGetCourseDetail";
55
import {apiCreateLesson} from "./apiCreateLesson";
66
import {apiPatchLesson} from "./apiPatchLesson";
7+
import {apiDeleteLesson} from "./apiDeleteLesson";
78

89

910

@@ -15,5 +16,6 @@ export function initRestApi(app:Application) {
1516

1617
app.route('/api/lesson').post(apiCreateLesson);
1718
app.route('/api/lesson/:id').patch(apiPatchLesson);
19+
app.route('/api/lesson/:id').delete(apiDeleteLesson);
1820

1921
}

server/api/apiDeleteLesson.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+

server/queries/deleteLesson.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}

0 commit comments

Comments
 (0)