nwokoyepraise / employee-mgmt

Demonstrating a employee management backend service but inbuilt soft-delete feature. Built with NestJs, TypeScript and MongoDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Employee Management

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 Support us


Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. API Endpoints
  4. Test
  5. Roadmap
  6. Contributing
  7. License
  8. Contact
  9. Acknowledgements

About The Project

This project is a demo backend for employee management built with NestJs framework

Services Available on the Backend

  • Add employee
  • Retrieve all employees with optimized pagination
  • Update employee using custom in-built plugin
  • Soft-delete employee
  • Retrieve all soft-deleted employees
  • Restore soft-deleted employee

Built With

The project was built natively with the following technologies

Getting Started

To build the project locally, simply clone the github repository. Navigate to root project folder and run the following to install packages:

# Install packages
$ npm install

After packages have been installed. Proceed to run:

npm start

API Endpoint

***Base API: http://localhost:3000/

Installation

$ npm install

API Endpoints

Add Employee

This endpoint is used to add employee to the service

POST /employee
Host: localhost:3000
Content-Type: application/json

{
    "name": "name",
    "email": "email@email.com",
    "phone": "+2344444444",
    "homeAddress": {
        "city": "city",
        "zipCode": 1234,
        "addressLine1": "addressLine1",
        "addressLine2": "addressLine2",
        "_id": "6288b32656d92169f3e32ed9"
    },
    "dob": "1950-01-01T00:00:00.000Z",
    "doe": "2002-12-09T00:00:00.000Z"
}


Response:
{
    "name": "name",
    "email": "email@email.com",
    "phone": "+2344444444",
    "homeAddress": {
        "city": "city",
        "zipCode": 1234,
        "addressLine1": "addressLine1",
        "addressLine2": "addressLine2",
        "_id": "6288b32656d92169f3e32ed9"
    },
    "dob": "1950-01-01T00:00:00.000Z",
    "doe": "2002-12-09T00:00:00.000Z",
    "_id": "6288b32656d92169f3e32ed8",
    "isDeleted": false,
    "deletedAt": null,
    "createdAt": "2022-05-21T09:38:46.721Z",
    "updatedAt": "2022-05-21T09:38:46.721Z",
    "__v": 0
}

Update Employee

This endpoint is used to update employee using the ID in this case the Monoose Document ObjectId

PATCH /employee/:id
Host: localhost:3000
Content-Type: application/json

{
    "name": "name",
    "email": "email@email.com",
    "phone": "+2344444444",
    "homeAddress": {
        "city": "city",
        "zipCode": 1234,
        "addressLine1": "addressLine1",
        "addressLine2": "addressLine2",
        "_id": "6288b32656d92169f3e32ed9"
    },
    "dob": "1950-01-01T00:00:00.000Z",
    "doe": "2002-12-09T00:00:00.000Z"
}


Response:
{
    "name": "name",
    "email": "email@email.com",
    "phone": "+2344444444",
    "homeAddress": {
        "city": "city",
        "zipCode": 1234,
        "addressLine1": "addressLine1",
        "addressLine2": "addressLine2",
        "_id": "6288b32656d92169f3e32ed9"
    },
    "dob": "1950-01-01T00:00:00.000Z",
    "doe": "2002-12-09T00:00:00.000Z",
    "_id": "6288b32656d92169f3e32ed8",
    "isDeleted": false,
    "deletedAt": null,
    "createdAt": "2022-05-21T09:38:46.721Z",
    "updatedAt": "2022-06-21T09:38:46.721Z",
    "__v": 0
}

Soft-delete Employee

This endpoint is used to soft-delete employee using the ID in this case the Monoose Document ObjectId

DELETE /employee/:id
Host: localhost:3000
Content-Type: application/json

Response:
{
    "name": "name",
    "email": "email@email.com",
    "phone": "+2344444444",
    "homeAddress": {
        "city": "city",
        "zipCode": 1234,
        "addressLine1": "addressLine1",
        "addressLine2": "addressLine2",
        "_id": "6288b32656d92169f3e32ed9"
    },
    "dob": "1950-01-01T00:00:00.000Z",
    "doe": "2002-12-09T00:00:00.000Z",
    "_id": "6288b32656d92169f3e32ed8",
    "isDeleted": true,
    "deletedAt": "2022-06-21T09:38:46.721Z",
    "createdAt": "2022-05-21T09:38:46.721Z",
    "updatedAt": "2022-06-21T09:38:46.721Z",
    "__v": 0
}

Retrieve employees (Not soft-deleted)

This endpoint is used to retrieve employees who are not soft-deleted

GET /employee?createdBefore=2022-05-20T21:51:21.010Z
Host: localhost:3000
Content-Type: application/json

Response:
[
   {
      "name": "name",
      "email": "email@email.com",
      "phone": "+2344444444",
      "homeAddress": {
          "city": "city",
          "zipCode": 1234,
          "addressLine1": "addressLine1",
          "addressLine2": "addressLine2",
          "_id": "6288b32656d92169f3e32ed9"
      },
      "dob": "1950-01-01T00:00:00.000Z",
      "doe": "2002-12-09T00:00:00.000Z",
      "_id": "6288b32656d92169f3e32ed8",
      "isDeleted": true,
      "deletedAt": "2022-06-21T09:38:46.721Z",
      "createdAt": "2022-05-21T09:38:46.721Z",
      "updatedAt": "2022-06-21T09:38:46.721Z",
      "__v": 0
  }
]

Restore soft-deleted Employee

This endpoint is used to restore soft-deleted employee using the ID in this case the Monoose Document ObjectId

POST /employee/:id/restore
Host: localhost:3000
Content-Type: application/json

Response:
{
    "name": "name",
    "email": "email@email.com",
    "phone": "+2344444444",
    "homeAddress": {
        "city": "city",
        "zipCode": 1234,
        "addressLine1": "addressLine1",
        "addressLine2": "addressLine2",
        "_id": "6288b32656d92169f3e32ed9"
    },
    "dob": "1950-01-01T00:00:00.000Z",
    "doe": "2002-12-09T00:00:00.000Z",
    "_id": "6288b32656d92169f3e32ed8",
    "isDeleted": false,
    "deletedAt": null,
    "createdAt": "2022-05-21T09:38:46.721Z",
    "updatedAt": "2022-06-21T09:38:46.721Z",
    "__v": 0
}

Retrieve soft-delete Employees

This endpoint is used to retrieve soft-deleted employee using the ID in this case the Monoose Document ObjectId

GET /employee/deleted?createdBefore=2022-05-20T21:51:21.010Z
Host: localhost:3000
Content-Type: application/json

Response:
[
   {
      "name": "name",
      "email": "email@email.com",
      "phone": "+2344444444",
      "homeAddress": {
          "city": "city",
          "zipCode": 1234,
          "addressLine1": "addressLine1",
          "addressLine2": "addressLine2",
          "_id": "6288b32656d92169f3e32ed9"
      },
      "dob": "1950-01-01T00:00:00.000Z",
      "doe": "2002-12-09T00:00:00.000Z",
      "_id": "6288b32656d92169f3e32ed8",
      "isDeleted": true,
      "deletedAt": "2022-06-21T09:38:46.721Z",
      "createdAt": "2022-05-21T09:38:46.721Z",
      "updatedAt": "2022-06-21T09:38:46.721Z",
      "__v": 0
  }, ...
]

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

Screenshot from 2022-05-21 09-21-12

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Support

Stay in touch

License

This project is GNU-V3.

Nest is MIT licensed.

About

Demonstrating a employee management backend service but inbuilt soft-delete feature. Built with NestJs, TypeScript and MongoDB

License:GNU General Public License v3.0


Languages

Language:TypeScript 97.3%Language:JavaScript 2.6%Language:Procfile 0.1%