This API is built with NestJS and PostgreSQL to manage gym memberships, including different billing structures and the ability to send email reminders for upcoming payments using Gmail's SMTP service.
- CRUD operations for managing gym memberships
- Scheduled email reminders for upcoming payments
- Manual trigger for sending reminder emails
- Node.js
- PostgreSQL
- Gmail account for sending emails
-
Clone the repository:
git clone https://github.com/joshualine/fitness-plus.git cd fitness-plus -
Install the dependencies:
npm install
-
Create a
.envfile in the root directory with the following content, replacing placeholder values with your actual configuration:DATABASE_HOST=localhost DATABASE_USERNAME=your_db_username DATABASE_PASSWORD=your_db_password DATABASE_NAME=your_db_name SMTP_HOST=your_smtp_server SMTP_PORT=587 SMTP_USER=your_email@example.com SMTP_PASS=your_email_password
-
Ensure your PostgreSQL server is running and the database specified in your
.envfile is created. -
Run the database migrations:
npm run typeorm migration:run
-
Start the application:
npm run start
The API will be running at
http://localhost:3000.
-
Endpoint:
POST /membership -
Description: Creates a new gym membership.
-
Request Body:
{ "firstName": "Chinedu", "lastName": "Okafor", "membershipType": "Annual Basic", "startDate": "2024-01-01", "dueDate": "2025-01-01", "totalAmount": 500.00, "monthlyAmount": 0, "email": "user1@yopmail.com", "isFirstMonth": true } -
Response:
-
Status:
201 Created -
Body:
{ "id": 1, "firstName": "Chinedu", "lastName": "Okafor", "membershipType": "Annual Basic", "startDate": "2024-01-01", "dueDate": "2025-01-01", "totalAmount": 500.00, "monthlyAmount": 0, "email": "user1@yopmail.com", "isFirstMonth": true }
-
- Endpoint:
GET /membership - Description: Retrieves a list of all gym memberships.
- Response:
-
Status:
200 OK -
Body:
[ { "id": 1, "firstName": "Chinedu", "lastName": "Okafor", "membershipType": "Annual Basic", "startDate": "2024-01-01", "dueDate": "2025-01-01", "totalAmount": 500.00, "monthlyAmount": 0.00, "email": "user1@yopmail.com", "isFirstMonth": true }, { "id": 2, "firstName": "Aisha", "lastName": "Abubakar", "membershipType": "Monthly Premium", "startDate": "2024-03-15", "dueDate": "2024-04-15", "totalAmount": 50.00, "monthlyAmount": 50.00, "email": "user2@yopmail.com", "isFirstMonth": true }, { "id": 3, "firstName": "Femi", "lastName": "Adeyemi", "membershipType": "Annual Premium", "startDate": "2024-05-01", "dueDate": "2025-05-01", "totalAmount": 800.00, "monthlyAmount": 0.00, "email": "user3@yopmail.com", "isFirstMonth": true }, { "id": 4, "firstName": "Nneka", "lastName": "Nwosu", "membershipType": "Monthly Basic", "startDate": "2024-06-01", "dueDate": "2025-07-01", "totalAmount": 0.00, "monthlyAmount": 30.00, "email": "user4@yopmail.com", "isFirstMonth": false } ]
-
- Endpoint:
GET /membership/:id - Description: Retrieves details of a specific gym membership by ID.
- Response:
-
Status:
200 OK -
Body:
{ "id": 1, "firstName": "Chinedu", "lastName": "Okafor", "membershipType": "Annual Basic", "startDate": "2024-01-01", "dueDate": "2025-01-01", "totalAmount": 500.00, "monthlyAmount": 0, "email": "user1@yopmail.com", "isFirstMonth": true }
-
-
Endpoint:
PUT /membership/:id -
Description: Updates the details of a specific gym membership by ID.
-
Request Body (Partial or Full Update):
{ "lastName": "Nwafor", "membershipType": "Monthly Basic", "monthlyAmount": 20.00, "isFirstMonth": false } -
Response:
-
Status:
200 OK -
Body:
{ "id": 1, "firstName": "Chinedu", "lastName": "Nwafor", "membershipType": "Monthly Basic", "startDate": "2024-01-01", "dueDate": "2025-01-01", "totalAmount": 500.00, "monthlyAmount": 20.00, "email": "user1@yopmail.com", "isFirstMonth": false }
-
- Endpoint:
DELETE /membership/:id - Description: Deletes a specific gym membership by ID.
- Response:
- Status:
204 No Content - Body: None
- Status:
- Endpoint:
POST /membership/:id/send-reminder - Description: Sends a reminder email to the specified membership.
- Response:
- Status:
200 OK - Body: None
- Status:
- Error Response:
-
Status:
404 Not Found -
Body:
{ "statusCode": 404, "message": "Membership not found", "error": "Not Found" }
-
The application is configured using environment variables defined in a .env file. The variables include database connection details and SMTP server details for sending emails.
To run the tests, use the following command:
npm run start:dev