This is a submission for a take home test
- Hosted with render at https://room-filter-api.onrender.com/api/
- Local host at
http://localhost:4000/api/
Clone the project
Install dependencies
npm install
Create a .env
file and add your localhost postgress database name and password
DATABASE: ''
LOCAL_PASSWORD: ''
Start the server
npm run start
or
Start the server in watch mode
npm run start:dev
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
GET: /api/rooms
GET: /api/rooms?page=0&limit=10
GET: /api/rooms?sort=[{feild:"feild-to-sort-by", order:"ASC or DESC"}]
GET: /api/rooms?filter=[{"field":"userId","value":1,"operator":"equals"}]
GET: /api/rooms/${id}
POST: /api/rooms/
Import filter utility in a service and call the needed functions on
- FilterUtil.paginate() This is a utility function that paginates results from a query, it takes three parameters and returns the paginated query builder
- qb: SelectQueryBuilder
- page: number
- limit: number
- FilterUtil.sortBy() This is a utility function that sorts the given table in ascending or descending order, it takes three parameters and returns a sorted QueryBuilder
- qb: SelectQueryBuilder
- sort: Sort[],
- tableName: string
- FilterUtil.filter()
This is a utility function that filter the given table based on filter operators such as:
gt (greater than)
,lt (less than)
and more. It takes three parameters and returns a filtered queryBulder
- qb: SelectQueryBuilder
- filters: Filter[]
- tableName: string
Nest is MIT licensed.