- Project done for skill assessment at Siga Infotech
HataraShift is a simple shift booking system created with MERN Stack in typescript.
User registration and login is required for any of the operations.
The user can create shifts, view available shifts, book a shift, view booked shifts, cancel their booking, etc.
Instructions on how to run can be seen at bottom
-
User Registration
- Endpoint:
POST /api/auth/register
- Description: Registers a new user.
- Request Body:
{ name, email, password }
- Response:
{ success, ...userData }
- Endpoint:
-
User Login
- Endpoint:
POST /api/auth/login
- Description: Logs in an existing user.
- Request Body:
{ username, password }
- Response:
{ success, ...userData }
- Endpoint:
-
User Logout
- Endpoint:
POST /api/auth/logout
- Description: Logs out the authenticated user.
- Response:
{ success }
- Endpoint:
-
Create Shift
- Endpoint:
POST /api/shifts
- Description: Creates a new shift.
- Middleware:
authenticateJWT
(ensures the user is authenticated). - Request Body:
{ date, startTime, endTime, role }
- Response:
{ shiftId }
- Endpoint:
-
Get Available Shifts
- Endpoint:
GET /api/shifts/available
- Description: Retrieves a list of available shifts that have not been booked.
- Middleware:
authenticateJWT
- Response:
[ { shiftId, date, startTime, endTime, role } ]
- Endpoint:
-
Book Shift
- Endpoint:
POST /api/shifts/book/:shiftId
- Description: Books a shift specified by the
shiftId
. - Middleware:
authenticateJWT
- Response:
{ success, message, shiftId }
- Endpoint:
-
View Booked Shifts
- Endpoint:
GET /api/shifts/booked
- Description: Retrieves a list of shifts booked by the authenticated user.
- Middleware:
authenticateJWT
- Response:
[ { shiftId, date, startTime, endTime, role } ]
- Endpoint:
-
Cancel Booking
- Endpoint:
DELETE /api/shifts/book/:shiftId
- Description: Cancels a booking for a shift specified by the
shiftId
. - Middleware:
authenticateJWT
- Response:
{ success, message, shiftId }
- Endpoint:
-
You should have nodejs and npm installed.
-
Clone the repo, go to backend folder.
-
Install all the dependencies with
npm i
-
Create a
.env.backend
file in/backend/config
folder with the following information:PORT=3000 // Your desired port where server should listen MONGOURI="mongodb://localhost:27017/hatarashift" // either use the local MongoDB instance or use from atlas JWT_SECRET="YOURSECRET" // Your JWT Secret
-
After configuring environment variables, simply run the server by typing
npm run dev
, or if you want to build the server, then typenpm run build npm run start
This will compile the typescript files into javascript and produce the output at
./dist
folderNow you can test the APIs with any API client tools such as Postman, Insomnia, etc.
-
Go to
/frontend
folder and install the dependencies withnpm i
-
To run the frontend, simply type
npm run dev
or if you want to build the frontend for production, then typenpm run build
-
To run the production build, you can use a simple file server like
serve
Go to./dist
folder and then:npm i -g serve serve -s -l 5173