A progressive Node.js framework for building efficient and scalable server-side applications.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This project is a demo backend for employee management built with NestJs framework
- 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
The project was built natively with the following technologies
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
***Base API: http://localhost:3000/
$ npm install
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
}
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
}
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
}
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
}
]
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
}
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
}, ...
]
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
See the open issues for a list of proposed features (and known issues).
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is GNU-V3.
Nest is MIT licensed.