Skip to content

Commit b57b658

Browse files
author
Your Name
committed
typescript course ongoing
1 parent e33eeee commit b57b658

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

server/queries/findCourseDetail.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11

22

33
import {CourseModel, LessonModel} from "../model/model";
4+
import * as Bluebird from "bluebird";
5+
import {CourseDetail} from "../../shared/model/course-detail";
6+
import {createCourseDetail} from "../../shared/model/createCourseDetail";
47

5-
export function findCourseDetail(courseId:number) {
8+
9+
export function findCourseDetail(courseId:number): Bluebird<CourseDetail> {
610

711
return CourseModel.findById(courseId, {
812
include: [
913
{
1014
model: LessonModel
1115
}
1216
]
13-
});
17+
})
18+
.then(createCourseDetail);
1419
}

shared/model/createCourseDetail.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
3+
4+
import {CourseDetail} from "./course-detail";
5+
6+
7+
export function createCourseDetail({
8+
id,
9+
url,
10+
description,
11+
iconUrl,
12+
courseListIcon,
13+
seqNo,
14+
longDescription,
15+
comingSoon,
16+
isNew,
17+
isOngoing,
18+
Lessons}:any):CourseDetail {
19+
20+
return {
21+
id,
22+
url,
23+
description,
24+
iconUrl,
25+
courseListIcon,
26+
seqNo,
27+
longDescription,
28+
comingSoon,
29+
isNew,
30+
isOngoing,
31+
lessons: Lessons.map(createLessonFromDbModel)
32+
};
33+
34+
}
35+
36+
function createLessonFromDbModel({
37+
id,
38+
url,
39+
description,
40+
duration,
41+
seqNo,
42+
courseId,
43+
pro,
44+
tags
45+
}:any) {
46+
return {
47+
id,
48+
url,
49+
description,
50+
duration,
51+
seqNo,
52+
courseId,
53+
pro,
54+
tags
55+
}
56+
}
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+

shared/model/lesson.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ export interface Lesson {
88
courseId: string;
99
pro: boolean;
1010
tags?: string;
11-
}
11+
}
12+
13+
14+
15+

0 commit comments

Comments
 (0)