This API allows for the management of shifts for healthcare professionals in different facilities.
change
- Node.js
- Express.js
- Sequelize
- Node.js
- yarn/npm
- The process of initializing the database is set up in a file located at
./models/index.js
.
Sequelize(`postgres://postgres:postgres@localhost:5432/postgres`, {
dialect: 'postgres',
logging: false
})
- Clone the repository
git clone https://github.com/anabaei/challenge
- Install dependencies
npm install
or
yarn install
-
Create a
.env
file based on the.env.example
file and set your own values for the environment variables. -
Start the application
yarn dev
or
npm run dev
- Are available at swagger
http://localhost:3000/api-docs
Retrieve all shifts within a start and end date for the which are available and not from the specific facility
Query parameters:
start_date
(required) - Start date for the range of shifts to retrieve (ISO 8601 format)end_date
(required) - End date for the range of shifts to retrieve (ISO 8601 format)
Request:
http://localhost:3000/shifts/available?facilityId=1&start_date=2023-01-07&end_date=2023-04-07&page=1&page_size=1
specific facility id = 1
Example response:
{
"2023-02-01": [
{
"id": 1597248,
"start": "2023-02-01T21:00:00.000Z",
"end": "2023-02-02T02:00:00.000Z",
"is_deleted": true,
"profession": "LVN"
},
{
"id": 1598695,
"start": "2023-02-01T21:00:00.001Z",
"end": "2023-02-02T02:00:00.001Z",
"is_deleted": true,
"profession": "RN"
},
]
}
Retrieve all shifts for a specific facility within a start and end date.
Query parameters:
start_date
(required) - Start date for the range of shifts to retrieve (ISO 8601 format)end_date
(required) - End date for the range of shifts to retrieve (ISO 8601 format)
Example Request:
GET http://localhost:3000/facilities/2/shifts?start_date=2021-01-07T12:00:00.201Z&end_date=2023-04-07T17:00:00.201Z
facility_id = 2
//as defualts
page=1
page_size =1
Example response:
{
"2023-03-01": [
{
"start": "2023-03-01T21:00:00.739Z",
"end": "2023-03-02T02:00:00.739Z"
},
{
"start": "2023-03-01T12:00:00.741Z",
"end": "2023-03-01T17:00:00.741Z"
},
]
}
Retrieve all available shifts for a specific facility within a start and end date which are not claimed
Query parameters:
facilityId
(required) - ID of the facility to retrieve shifts forstart_date
(required) - Start date for the range of shifts to retrieve (ISO 8601 format)end_date
(required) - End date for the range of shifts to retrieve (ISO 8601 format)
Request:
http://localhost:3000/shifts?start_date=2023-01-07T12:00:00.201Z&end_date=2023-04-07T17:00:00.201Z
Example response:
{
"2023-02-01": [
{
"id": 1597248,
"start": "2023-02-01T21:00:00.000Z",
"end": "2023-02-02T02:00:00.000Z",
"is_deleted": true,
"profession": "LVN"
},
{
"id": 1598695,
"start":
-
To increase performance there are several solutions like caching and pagination. I implemented pagination on all urls, if no
page
orpage_size
not assigned the default value is always1
-
Pagination
can reduce the amount of data that needs to be transferred over the network and improve the response time of the API.
- app
- controllers
- userController.js
- postController.js
- middlewares
- auth.js
- error.js
- models
- user.js
- post.js
- routes
- api
- user.js
- post.js
- index.js
- api
- services
- userService.js
- postService.js
- utils
- logger.js
- app.js
- config.js
- package.json
- controllers
Please review by @cbhrecruiters