NestJS module containing Questions REST API endpoints for Quiz application.
Table of Contents:
- Retrieve a quiz question by id
- Create a new quiz question
- Update a quiz question
- Delete a quiz question by id
- Retrieve a list of quiz questions
- Retrieve a list of quiz topics
- Create new quiz questions
${\textsf{\color{lightgreen}GET}}$ https://{host}/quiz/question
Param | Type | Required | Description | Example |
---|---|---|---|---|
id | string | true | The question ID to get | 671d7510132024de0ed47304 |
{
_id: string;
topic: string;
subtopic?: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: Array<{
text: string;
isCorrect?: boolean;
}>;
explanation?: string;
links?: Array<string>;
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
createdAt: Date;
updatedAt: Date;
}
${\textsf{\color{orange}POST}}$ https://{host}/quiz/question
{
topic: string;
subtopic?: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: Array<{
text: string;
isCorrect?: boolean;
}>;
explanation?: string;
links?: Array<string>;
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
${\textsf{\color{blue}PUT}}$ https://{host}/quiz/question
{
_id: string;
topic: string;
subtopic?: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: Array<{
text: string;
isCorrect?: boolean;
}>;
explanation?: string;
links?: Array<string>;
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
${\textsf{\color{red}DELETE}}$ https://{host}/quiz/question
Param | Type | Required | Description | Example |
---|---|---|---|---|
id | string | true | Question ID to delete | 671438511204ca5ad9df5366 |
${\textsf{\color{lightgreen}GET}}$ https://{host}/quiz/questions
Param | Type | Required | Description | Example |
---|---|---|---|---|
topics[] | string | false | The topics to filter questions by | HTML |
count | number | false | The number of questions to retrieve | 10 |
[
{
_id: string;
topic: string;
subtopic?: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: Array<{
text: string;
isCorrect?: boolean;
}>;
explanation?: string;
links?: Array<string>;
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
createdAt: Date;
updatedAt: Date;
}
]
[!TIP] To filter by multiple topics, use a few "topics[]" query parameters. For example:
/quiz/questions?topics[]=HTML&topics[]=CSS
${\textsf{\color{lightgreen}GET}}$ https://{host}/quiz/topics
[
{
name: string;
questionCount: number;
}
]
${\textsf{\color{orange}POST}}$ https://{host}/quiz/questions
{
questions: [
{
topic: string;
subtopic?: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: Array<{
text: string;
isCorrect?: boolean;
}>;
explanation?: string;
links?: Array<string>;
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
]
}
Install the package to the main NestJS application and add it to the main module imports:
import { QuestionsModule } from '@fellendorf/api-quiz-questions-module';
@Module({
imports: [QuestionsModule],
controllers: [],
providers: [],
})
[!IMPORTANT] Main application must be connected to the MongoDB database.
Repository contains an app module (src/_dev-only
) just for development purposes. Additionally:
- command
npm run build
is set to use this main module to develop the "Questions" module; - the folder containing the main module will not be included in the npm package (see
.npmignore
file)
[!NOTE] Using
npm link
command orfile://...
path in pacakge.json brings some bugs.
- TESTS