Skip to content

This is a repository contains code that I wrote for practicing and exploring nestjs features.

Notifications You must be signed in to change notification settings

kamalahmed/nestjs-practice

Repository files navigation

Thank you for checking this out

This project shows the usage of nestjs to create a simple API.

Available routes

Home: http://localhost:3000

================================================================

Users REST API : available in the main branch. It uses pure nestjs features only.

Get All Users

GET /users

http://localhost:3000/users

Get All Users by a Role (subscriber or admin)

GET /users?role='admin|subscriber'

http://localhost:3000/users?role=admin

Get a User by ID

GET /users/:id

http://localhost:3000/users/1

Create a User

POST /users request body:

{name: string, email: string, role: string}

Update a User

PATCH /users/:id request body:

{name: string, email: string, role: string}

Delete a User by ID

DELETE /users/:id

================================================================

Employees API : available in the rest-api-prisma branch. It uses postgresql and prisma ORM

Setup

I have used postgressql service from neon.tech. Create free account and then copy paste your database information to /prisma/schema.prisma and rename .env-sample to .env and paste your env file infromation from neon.tech dashboard. You can test everything for free.

Once you have made the changes. then run the following command to run the database migration.

$ npx prisma migrate dev --name initial_migration

Then visits the create route from below to add some employees.

Get All Employees

GET /employees

http://localhost:3000/employees

Get All Employees by a Role (SUBSCRIBER or ADMIN)

GET /employees?role='ADMIN|SUBSCRIBER'

http://localhost:3000/employees?role=ADMIN

Get a Employee by ID

GET /employees/:id

http://localhost:3000/employees/1

Create a Employee

POST /employees request body:

{name: string, email: string, role: string}

Note: Role Shoulde be capitalized ADMIN or SUBSCRIBER

Update a Employee

PATCH /employees/:id request body:

{name: string, email: string, role: string}

Delete a Employee by ID

DELETE /employees/:id


Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

About

This is a repository contains code that I wrote for practicing and exploring nestjs features.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published