Skip to content

Overk1lls/books-cms-api

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Description

Nest framework TypeScript starter repository.

Table of contents

  1. Project setup
  2. Compile and run the project
  3. Run tests
  4. Request examples
    1. Mutations
    2. Queries

Project setup

  • Prepare .env:

    • On Unix:
    cp .env.example .env
    • On Windows:
    copy .env.example .env
  • Install dependencies:

    yarn install
  • Start the Docker containers (docker-compose.yml):

    docker compose up -d
  • Migrate the database:

    yarn migrations:run

Compile and run the project

# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod

Run tests

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov

Request examples

Pay attention that you need a JWT to perform any query or mutation. The email below (test@gmail.com) will be an admin upon registration.

Mutations

Details

Users

  1. register():
mutation {
  register(input: {
    email: "test@gmail.com"
    password: "qwerty"
  }) {
    id
    email
    role
  }
}

The email must be unique.

  1. login():
mutation {
  login(input: {
    email: "test@gmail.com"
    password: "qwerty"
  }) {
    accessToken
  }
}

Get the JWT from response and add the Authorization header as Bearer token_here.

  1. makeUserAdmin():
mutation {
  makeUserAdmin(input: {
    userId: "111da7d6-330d-4eaa-b283-b81e5c00665b"
  }) {
    id
    email
    role
  }
}

You cannot make yourself an admin. You need to be admin to create/update/delete entities.

Authors

  1. createAuthor():
mutation {
  createAuthor(input: {
    name: "Test Author 1"
    biography: "Test biography"
  }) {
    id
    name
    biography
  }
}

Name must be unique.

  1. updateAuthor():
mutation {
  updateAuthor(id: "7a63b138-970e-4178-949c-3af099c3aac0", input: {
    name: "Test Author 1 Edited"
    biography: "Test biography edited"
  }) {
    id
    name
    biography 
  }
}
  1. deleteAuthor():
mutation {
  deleteAuthor(id: "7a63b138-970e-4178-949c-3af099c3aac0")
}

Books

  1. createBook():
mutation {
  createBook(input: {
    authorId: "de7d6b9e-210b-4247-8820-3127ae1e1074"
    title: "Test Book 1"
    publicationDate: "2025-04-24T15:16:50.814Z"
    genre: "Horror"
  }) {
    id
    title
    genre
    publicationDate
    author {
      id
      name
      biography
    }
  }
}
  1. updateBook():
mutation {
  updateBook(id: "fdce3070-93f3-4ae3-befd-0d1886c2d412", input: {
    title: "Test Book 1 Edited"
    genre: "Thriller"
  }) {
    id
    title
    genre
    publicationDate
    author {
      id
      name
      biography
    }
  }
}
  1. deleteBook():
mutation {
  deleteBook(id: "fdce3070-93f3-4ae3-befd-0d1886c2d412")
}

Queries

Details

Authors

  1. author():
query {
  author(id: "de7d6b9e-210b-4247-8820-3127ae1e1074") {
    id
    name
    biography
    booksCount
  }
}
  1. getAuthors():
query {
  getAuthors(input: {
    booksCount: 1
    name: "Test"
    sortBy: name
    sortOrder: "ASC"
    limit: 10
    page: 1
  }) {
    data {
      id
      name
      biography
      booksCount
    }
    page
    pageSize
    total
    totalPages
  }
}

Books

  1. book():
query {
  book(id: "a9c0cb45-fe75-4e66-9a57-43af53fd781e") {
    id
    title
    genre
    publicationDate
    author {
      id
      name
      biography
    }
  }
}
  1. getBooks():
query {
  getBooks(input: {
    author: "Test"
    title: "Test"
    publicationYear: 2025
    sortBy: title
    sortOrder: "ASC"
    limit: 10
    page: 1
  }) {
    data {
      id
      title
      genre
      publicationDate
      author {
        id
        name
        biography
      }
    }
    page
    pageSize
    total
    totalPages
  }
}

Users

  1. me():
query {
  me {
    id
    email
    role
  }
}
  1. getUser():
query {
  getUser(input: {
    id: "7c5ef962-3250-4d36-8aed-163d4b6e57d3"
    email: "test@gmail.com"
  }) {
    id
    email
    role
  }
}

By email or by ID.

License

Nest is MIT licensed.

About

A pet-project for a small test task

Topics

Resources

Stars

Watchers

Forks