@fellendorf/api-quiz-questions-module
TypeScript icon, indicating that this package has built-in type declarations

1.4.4 • Public • Published

Description

NestJS module containing Questions REST API endpoints for Quiz application.
Table of Contents:

API endpoints

How to use
How to develop


API endpoints

Retrieve a list of quiz questions

    ${\textsf{\color{lightgreen}GET}}$        https://{host}/quiz/questions

QUERY PARAMS

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

RESPONSE BODY

[
    {
        topic: string;
        text: string;
        code?: {
            text: string;
            language: 'typescript' | 'javascript' | 'html' | 'css';
        }
        options: string[];
        answer: {
            index: number;
            explanation?: string;
        };
        meta?: {
            reviewed?: boolean;
            difficult?: 'easy' | 'medium' | 'hard';
        }
    }
]

[!TIP] To filter by multiple topics, use a few "topics[]" query parameters. For example:

/quiz/questions?topics[]=HTML&topics[]=CSS

Retrieve a list of quiz topics

${\textsf{\color{lightgreen}GET}}$        https://{host}/quiz/topics

RESPONSE BODY

[
    {
        name: string;
        questionCount: number;
    }
]

Create a new quiz question


${\textsf{\color{orange}POST}}$        https://{host}/quiz/question

REQUEST BODY

{
    topic: string;
    text: string;
    code?: {
        text: string;
        language: 'typescript' | 'javascript' | 'html' | 'css';
    }
    options: string[];
    answer: {
        index: number;
        explanation?: string;
    };
    meta?: {
        reviewed?: boolean;
        difficult?: 'easy' | 'medium' | 'hard';
    }
}

Update a quiz question


${\textsf{\color{blue}PUT}}$        https://{host}/quiz/question

REQUEST BODY

{
    _id: string;
    topic: string;
    text: string;
    code?: {
        text: string;
        language: 'typescript' | 'javascript' | 'html' | 'css';
    }
    options: string[];
    answer: {
        index: number;
        explanation?: string;
    };
    meta?: {
        reviewed?: boolean;
        difficult?: 'easy' | 'medium' | 'hard';
    }
}

Delete a quiz question by id


${\textsf{\color{red}DELETE}}$        https://{host}/quiz/question

QUERY PARAMS

Param Type Required Description Example
id string true Question ID to delete 671438511204ca5ad9df5366

Create new quiz questions


${\textsf{\color{orange}POST}}$        https://{host}/quiz/questions

REQUEST BODY

[
    {
        topic: string;
        text: string;
        code?: {
            text: string;
            language: 'typescript' | 'javascript' | 'html' | 'css';
        }
        options: string[];
        answer: {
            index: number;
            explanation?: string;
        };
        meta?: {
            reviewed?: boolean;
            difficult?: 'easy' | 'medium' | 'hard';
        }
    }
]

How to use

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.


How to develop

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 or file://... path in pacakge.json brings some bugs.


App TODO:

  • TESTS

Readme

Keywords

none

Package Sidebar

Install

npm i @fellendorf/api-quiz-questions-module

Weekly Downloads

76

Version

1.4.4

License

ISC

Unpacked Size

225 kB

Total Files

24

Last publish

Collaborators

  • fellendorf