# Fix It Auto Care API

Express + MySQL REST API (`/api/...`) using Sequelize models.

## Setup

1. Copy `.env.example` to `.env` and set `MYSQL_*` and `JWT_SECRET`.
2. Install dependencies:

   ```bash
   npm install
   ```

3. Start the server:

   ```bash
   npm run dev
   ```

On startup, the app runs:

- `sequelize.authenticate()`
- `sequelize.sync()`

This auto-creates required tables from model definitions.

Optional: run `npm run db:init` if you want to reset and seed from `schema.sql` for test data.
If your DB already exists and you want at-home booking fields, run:

```bash
npm run db:add-home-booking-fields
```

Health check: `GET http://localhost:3000/api/health`

Uploaded task images are served from `GET /uploads/<filename>`.

## Deploy on cPanel (Node.js App)

1. In cPanel, open **Setup Node.js App** and create an app:
   - Node version: current LTS (18+ recommended)
   - Application root: folder where this backend is uploaded
   - Application startup file: `src/server.js`
2. In the app environment variables, set:
   - `NODE_ENV=production`
   - `AUTO_START=true`
   - `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_DATABASE`
   - `JWT_SECRET`, `JWT_EXPIRES_IN`
3. Open the app terminal in cPanel and install dependencies:
   ```bash
   npm install
   ```
4. Restart the Node.js app from cPanel.
5. Verify deployment:
   - `GET https://<your-domain>/api/health`

### Notes

- The server binds to `process.env.PORT` automatically (required for cPanel).
- Set `AUTO_START=false` only for serverless-style runtimes where another platform manages the request lifecycle.
