This NestJS application provides create,filter,sorting and pagination operations for user data using MySQL as the database with following fields:
- Id (integer)
- Name (string)
- Age (integer)
- Email (string)
- DateofBirth (date)
- Create a user record: Post [http://localhost:3000/api/user]
- filter records based on Name, Age, Email, Id, DateofBirth: Post [http://localhost:3000/api/user/find?Name=enter_any_name]
- Sort user records based on Name, Age, Email, Id, DateofBirth in ascending and descending order:
- Post [[http://localhost:3000/api/user/find?sortField=DateofBirth&sortOrder=DESC]]
- Post [[http://localhost:3000/api/user/find?sortField=DateofBirth&sortOrder=ASC]]
- Set the page size and retrieve a specific page of data:
- Post [[http://localhost:3000/api/user/find?page=1&pageSize=10]]
- an example of multi query [[http://localhost:3000/api/user/find?page=1&pageSize=10&sortField=Name&sortOrder=DESC]]
- Id (exact match only number allowed)
- Name (case-insensitive partial match only string allowed)
- Age (exact match only number allowed)
- Email (case-insensitive partial match)
- Date of Birth (From-To)
- DateofBirth (Exact YYY-MM-DD format)
Ensure you have the following software installed:
- Visual Studio Code
- MySQL with a database created for using
- DBeaver (optional) for database visualization -postman to test the api
- Create a
.envfile in the root directory and specify your MySQL connection variables and localhost port:
DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=your_db_port
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_DATABASE=your_database_name
DB_SYNCHRONIZE=true
PORT=port_on_which_you_want_to_run_your_server- run the following command to install the dependencies
$ cd project
$ npm install- run the following command to Generate a sample dataset containing 100 records
$ npm run seed- run the following command to regenerate records
$ npm run seed:refresh# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod