parent
423800b22f
commit
8502b302b2
5 changed files with 120 additions and 98 deletions
@ -1,7 +1,8 @@ |
||||
--- |
||||
title: Challenge 1 |
||||
description: Write a SQL query to find the total number of orders in the `orders` table. |
||||
order: 100 |
||||
order: 200 |
||||
type: challenge |
||||
defaultValue: SELECT * FROM orders; |
||||
initSteps: |
||||
- CREATE TABLE orders ( |
@ -0,0 +1,70 @@ |
||||
--- |
||||
import { |
||||
getAllCourses, |
||||
getChaptersByCourseId, |
||||
type CourseFileType, |
||||
type ChapterFileType, |
||||
type LessonFileType, |
||||
} from '../../../../lib/course'; |
||||
|
||||
interface Params extends Record<string, string | undefined> { |
||||
courseId: string; |
||||
chapterId: string; |
||||
lessonId: string; |
||||
} |
||||
|
||||
interface Props { |
||||
course: CourseFileType; |
||||
chapter: ChapterFileType; |
||||
lesson: LessonFileType; |
||||
} |
||||
|
||||
export async function getStaticPaths() { |
||||
const courses = await getAllCourses(); |
||||
const coursesWithChapters = await Promise.all( |
||||
courses.map(async (course) => { |
||||
const chapters = await getChaptersByCourseId(course.id); |
||||
return { |
||||
...course, |
||||
chapters, |
||||
}; |
||||
}), |
||||
); |
||||
|
||||
const paths: { |
||||
params: Params; |
||||
props: Props; |
||||
}[] = []; |
||||
|
||||
for (const course of coursesWithChapters) { |
||||
const courseId = course.id; |
||||
const courseChapters = course.chapters; |
||||
|
||||
for (const chapter of courseChapters) { |
||||
for (const lesson of chapter.lessons) { |
||||
paths.push({ |
||||
params: { |
||||
courseId, |
||||
chapterId: chapter.id, |
||||
lessonId: lesson.id, |
||||
}, |
||||
props: { |
||||
course, |
||||
chapter, |
||||
lesson, |
||||
}, |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return paths; |
||||
} |
||||
|
||||
const { courseId, chapterId } = Astro.params; |
||||
const { course, chapter, lesson } = Astro.props; |
||||
--- |
||||
|
||||
<pre> |
||||
{JSON.stringify(lesson, null, 2)} |
||||
</pre> |
@ -0,0 +1,31 @@ |
||||
--- |
||||
import { |
||||
getAllCourses, |
||||
getCourseById, |
||||
type CourseFileType, |
||||
} from '../../../lib/course'; |
||||
|
||||
export async function getStaticPaths() { |
||||
const courses = await getAllCourses(); |
||||
|
||||
return courses.map((course) => ({ |
||||
params: { courseId: course.id }, |
||||
props: { course }, |
||||
})); |
||||
} |
||||
|
||||
interface Params extends Record<string, string | undefined> { |
||||
courseId: string; |
||||
} |
||||
|
||||
interface Props { |
||||
course: CourseFileType; |
||||
} |
||||
|
||||
const { courseId } = Astro.params; |
||||
const { course } = Astro.props; |
||||
--- |
||||
|
||||
<pre> |
||||
{JSON.stringify(course, null, 2)} |
||||
</pre> |
Loading…
Reference in new issue