Coder Social home page Coder Social logo

nodejs-test-task's Introduction

Description

This is simple CRUD API for managing users entities.

Installation

You need to clone or fork this repository and run:

npm install

to install all dependencies.

Install DB PostgreSQL on your machine or use a free web hosting services for PostgreSQL (https://www.heroku.com/postgres or https://www.elephantsql.com/plans.html).

Rename .env.example file to .env. You need to change .env file and provide your PostgreSQL database credentials.

To create database you can run :

npm run db:create

Running the app

# development
npm run start:dev

# production
npm run start:prod

# build
npm run build

Application starts on PORT 3000 (you can change this in .env file), default URL http://localhost:3000

Usage

You can use Postman to send requests to server. All endpoints (except POST /v1/auth/login and POST /v1/users) are protected, that means you need authorize (login) and provide token with "Authorization": "Bearer ${token}" header.

Auth endpoints

POST /v1/auth/login

Login user. Request should contain body in JSON format. Request body example:

{
  "email": "[email protected]",
  "password": "12345678qwe"
}

Response example:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5YjFkZWI0ZC0zYjdkLTRiYWQtOWJkZC0yYjBkN2IzZGNiNmQiLCJpYXQiOjE1MTYyMzkwMjJ9.A7RPWdhfOusPgTTbdZSskLRezAHR4yDzoa2Enyxhwlc"
}
Users endpoints

POST /v1/users

Create user. Request should contain form-data with fields:

email: string firstName: string lastName: string password: string image: (mime-types for image is PNG, JPG)

Response example:

{
  "email": "[email protected]",
  "firstName": "Sergey",
  "lastName": "Serzhan",
  "image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
  "pdf": null || Buffer
}

GET /v1/users/

Get all users. Response example:

[
  {
  "email": "[email protected]",
  "firstName": "Sergey",
  "lastName": "Serzhan",
  "image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
  "pdf": null || Buffer
  }
]

GET /v1/users/email

Get user by email. Request should contain body in JSON format:

{
  "email": "[email protected]"
}

Response example:

{
  "email": "[email protected]",
  "firstName": "Sergey",
  "lastName": "Serzhan",
  "image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
  "pdf": null || Buffer
}

PATCH /v1/users/

Update existing user by email. Request should contain form-data with fields:

updatedEmail: string

(Notice: all fields above not required)

email: string firstName: string lastName: string password: string image: (mime-types for image is PNG, JPG)

Response example:

{
  "email": "[email protected]",
  "firstName": "Sergey",
  "lastName": "Serzhan",
  "image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
  "pdf": null || Buffer
}

DELETE /v1/users/

Delete user by email. Request should contain body in JSON format:

{
  "email": "[email protected]"
}

Response with 204 status code No-Content.

POST /v1/users/pdf

Generate pdf for provided user. Request should contain body in JSON format:

{
  "email": "[email protected]"
}

Response example:

{
  "result": true;
}

nodejs-test-task's People

Contributors

sergeyserzhan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.