Skip to content

Alejandbel/pixelplex_nodejs_course

Repository files navigation

Flashcards

Created by Aliaksandr Bahdanau

Api

Types

  • Language

      {
        id: number;
        title: string;
        code: string;
      }
  • Cards

      {
        id: number;
        nativeLanguageId: number;
        foreignLanguageId: number;
        nativeWord: string;
        foreignWord: string; 
      }
  • Task

      {
        id: number;
        word: string;
        foreignLanguageId: number;
        target: "to_foreign"|"to_native";
      }

Authorization

  • POST api/v1/auth/signup - endpoint for creating account:

    {
      username: string;
      email: string;
      password: string;
    }

    Returns:

    {
      token: string;
    }

    If Email is not unique:

    code: 400
    {
      message: "Email already exists";
    }

    If Password is not consist of at least 8 Latin characters of lower and upper case, at least one digit and at least one special character (!@#$%^&*()_+=):

    code: 400
    {
      message: "Invalid password format";
    }

    If length of username less than 5 or higher than 256:

    code: 400
    {
      message: "Invalid email length";
    }
  • POST api/v1/auth/login - endpoint for logging in:

    {
      email: string;
      password: string;
    }

    Returns:

    {
      token: string;
    }

    If user with this email does not exist:

    code: 404
    {
      message: "User with this email does not exists";
    }

    If password not match email:

    code: 401
    {
      message: "Wrong password";
    }

User

  • For all the rest endpoint if user is not authorized:

    code: 401
    {
      message: "You must be authorized to do this"
    }
  • PATCH api/v1/users/native-language - endpoint for editing native language:

    {
      languageId: number;
    }

    If language with this id does not exist:

    code: 404
    {
      message: "Language does not exist"
    }

Languages

  • POST api/v1/languages - endpoint for creating language:

    {
      title: string;
      code: string;
    }

    Returns Language;

    If language with this code already exist:

    code: 400
    {
      message: "Language with this code already exists"
    }

    If user is not admin:

    code: 403
    {
      message: "You are not allowed to do this"
    }
  • PATCH api/v1/languages/:id - endpoint for editing language:

    {
      title?: string;
      code?: string;
    }

    Returns Language;

    If language with this id does not exist:

    code: 404
    {
      message: "Language does not exist"
    }

    If user is not admin:

    code: 403
    {
      message: "You are not allowed to do this"
    }
  • DELETE api/v1/languages/:id - endpoint for deleting language.

    If language with this id does not exist:

    code: 404
    {
      message: "Language does not exist"
    }

    If user is not admin:

    code: 403
    {
      message: "You are not allowed to do this"
    }
  • GET api/v1/languages/:id - endpoint for receiving language:

    Returns Language;

    If language with this id does not exist:

    code: 404
    {
      message: "Language does not exist"
    }
  • GET api/v1/languages?limit=number&offset=number - endpoint for receiving languages with pagination.

    Supports:

    • orderBy={name, date}
    • sort={asc,desc}
    • search=string

    Returns:

    {
      items: Array<Language>;
      pagination: {
        offset: number;
        limit: number;
        total: number;
      };
    }

Cards

  • POST api/v1/cards - endpoint for creating card:

    {
      nativeLanguageId: number;
      foreignLanguageId: number;
      nativeWord: string;
      foreignWord: string; 
    }

    Returns: Card

    If word in card exists

    code: 400
    {
      message: "Word already exists";
    }
  • PATCH api/v1/cards/:id - endpoint for editing card:

    {
      nativeLanguageId?: number;
      foreignLanguagefId?: number;
      nativeWord?: string;
      foreignWord?: string; 
    }

    Returns Card

    If word in card exists

      code: 400
      {
        message: "Word already exists";
      }

    If card with this id does not exist

      code: 404
      {
        message: "Card does not exist";
      }

    If card was made by another user:

    code: 403
    {
      message: "You are not allowed to do this"
    }
  • DELETE api/v1/cards/:id - endpoint for deleting card.

    If card with this id does not exist

      code: 404
      {
        message: "Card does not exist";
      }
  • GET api/v1/cards/:id - endpoint for receiving card:

    Returns Card

    If card with this id does not exist

      code: 404
      {
        message: "Card does not exist";
      }
  • GET api/v1/cards?limit=Number&offset=Number - endpoint for receiving cards with pagination.

    Supports:

    • orderBy={foreign, native, date}
    • sort={asc,desc}
    • search{Foreign, Native}=string
    • languageId=number

    Returns:

    {
      items: Array<Card>;
      pagination: {
        offset: number;
        limit: number;
        total: number;
      };
    }

Task

  • POST api/v1/tasks - endpoint for creating task:

    {
      languageId: number;
      target: "to_foreign"|"to_native";
    }

    Returns Task:

    If language with specified id does not exist:

      code: 404
      {
        message: "Language does not exist";
      }
  • POST api/v1/tasks/:id - endpoint for completing task:

    {
      answer: string;
    }

    Returns:

    {
      result: "CORRECT"|"INCORRECT";
    }

    If task was made by another user:

    code: 403
    {
      message: "You are not allowed to do this"
    }

    If task does not exist:

    code: 404
    {
      message: "Task does not exist";
    }
  • GET api/v1/tasks/:id - endpoint for receiving task:

    Returns Task;

    If task was made by another user:

    code: 403
    {
      message: "You are not allowed to do this"
    }

    If task does not exist:

    code: 404
    {
      message: "Task does not exist";
    }
  • GET api/v1/tasks?limit=number&offset=number - endpoint for receiving uncompleted tasks with pagination. Sorting by date.

    Supports:

    • sort={asc,desc}
    • searchWord=string

    Returns:

    {
      items: Array<tasks>;
      pagination: {
        offset: number;
        limit: number;
        total: number;
      };
    }
  • GET api/v1/tasks/statistic - endpoint for receiving tasks statistic.

    Args:

    • dateBegin=Date
    • dateEnd=Date
    • languages=Array<id: number>

    Returns:

    {
      correct: number;
      incorrect: number;
    }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •