Fitness-plus offers gym memberships with various billing structures. This backend system manages memberships, including annual and monthly billing, as well as optional add-on services such as personal training sessions and towel rentals. The API also handles invoicing for new members, sends email reminders for upcoming payments, and includes a cron job to check for upcoming membership fees.
- Manage memberships with annual and monthly billing.
- Handle optional add-on services with separate monthly charges.
- Combine the annual membership fee with the first month's add-on service charges for new members.
- Send email reminders for upcoming payments.
- Cron job to check for upcoming membership fees and send reminders.
- Node.js and npm installed
- PostgreSQL database setup
- Gmail account for sending emails
-
Clone the repository:
git clone https://github.com/NuelUzoma/fitness-plus.git cd fitness-plus
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root directory and add the following variables:DB_HOST=localhost DB_PORT=5432 DB_USERNAME=your_db_username DB_PASSWORD=your_db_password DB_DATABASE=fitness_plus MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USER=your_gmail_username MAIL_PASS=your_gmail_password
-
Run the database migration to set up the database schema:
npm run typeorm migration:run
-
Start the Nest.js server:
npm run start
-
Create a new membership
POST /api/memberships
Request Body:
{ "firstName": "Kelechi", "lastName": "Ogu", "membershipType": "Annual Basic", "email": "[email protected]", "isFirstMonth": true }
Response:
{ "firstName": "Kelechi", "lastName": "Ogu", "membershipType": "Annual Basic", "email": "[email protected]", "isFirstMonth": true, "startDate": "2024-06-11T20:16:26.217Z", "dueDate": "2025-06-10T23:00:00.000Z", "totalAmount": 500, "id": 22 }
-
Get all memberships
GET /api/memberships
-
Update membership details
PUT /api/memberships
-
Create a new add-on service
POST /api/addons
Request Body:
{ "serviceName": "Personal Training" }
Response:
{ "serviceName": "Personal Training", "dueDate": "2024-07-10T23:00:00.000Z", "monthlyAmount": 100, "id": 21 }
-
Get all add-on services
GET /api/addons
Emails are sent using NodeMailer configured with a Gmail SMTP server. Ensure that your Gmail account allows less secure apps or generate an app-specific password for better security.
A cron job runs daily at midnight to check for upcoming membership fees and send reminders.