# Bass Resort backend setup

The website now uses MongoDB Atlas for reservations, rooms, menu management, restaurant tables, waiter calls, and popup/settings data.

## MongoDB Atlas

Create a MongoDB Atlas project, then create a database user and allow your hosting server IP in **Network Access**. For shared cPanel hosting, you may need to temporarily allow `0.0.0.0/0` if the host cannot provide a stable outbound IP.

The app creates collections and indexes automatically on first run. If menu or room collections are empty, the bundled website data is seeded automatically.

No phpMyAdmin import is required for MongoDB Atlas.

## Environment variables

Copy `.env.example` to `.env.local` and update the values.

The local development admin password defaults to `admin123` only when `ADMIN_PASSWORD` is missing. Always define a strong password in production.

Keep `ADMIN_COOKIE_SECURE=false` for local HTTP. Set it to `true` after deploying behind HTTPS.

### cPanel database settings

In cPanel **Setup Node.js App**, add these environment variables:

```env
MONGODB_URI=mongodb+srv://user:password@cluster0.xxxxx.mongodb.net/bassrestaurant?retryWrites=true&w=majority
MONGODB_DB=bassrestaurant
```

Restart the Node.js app after changing environment variables. Visit `/api/health/db`; it should return `"ok": true` and `"provider": "mongodb"`.

## Reservation email

Email uses SMTP. For Gmail, create an App Password and configure:

```env
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-16-character-app-password
SMTP_FROM="Bass Resort <your-email@gmail.com>"
RESERVATION_EMAIL=the-address-that-receives-reservations@example.com
```

Every reservation is saved to MongoDB even if SMTP is unavailable. When SMTP is configured, the hotel receives a notification and guests who provide an email receive a confirmation copy.

## Admin panel

Open `/admin`, sign in, and use:

- Overview: reservation and menu totals
- Reservations: notifications, search, filters, details, read tracking, and status changes
- Menu Manager: add, edit, hide, or delete categories and items

Changes to the menu appear on `/menu` and in the homepage featured menu.

### Dashboard notifications

The sidebar shows live badges for:

- Unread reservations
- Unacknowledged waiter calls
- The combined count on Overview

Reservations remain unread until **View Details** is opened, their status is changed, or **Mark all read** is used. The reservation list can be filtered by status, read/unread state, and arrival date range.

The detail panel shows guest contact information, room, stay dates, payment choice, estimated total, notes, creation time, and status controls.

## Room management

Open **Rooms** in `/admin` to:

- Add room codes, names, types, capacity, beds, baths, and nightly prices
- Set status to Available, Few Left, Sold Out, or Maintenance
- Choose an existing image path or enter another public/hosted image URL
- Upload JPG, PNG, WebP, or GIF room images directly from the admin editor
- Manage comma-separated amenities
- Hide a room from the website without deleting it
- Edit or permanently delete rooms

The homepage, `/rooms`, booking form, price estimate, and reservation API all read from this MongoDB inventory. Sold-out, maintenance, hidden, or deleted rooms cannot accept new reservations.

Uploaded images are stored in MongoDB (GridFS bucket `uploads`) and served from `/api/uploads/<id>`. The maximum upload size is 8 MB.

## Restaurant tables and QR service

Open **Tables & QR** in `/admin` to:

- Add a table number, table type, capacity, and location note
- Download a unique PNG QR code for each table
- Open and test the guest table page
- Disable a QR without deleting the table
- Edit or delete tables

Each QR opens `/table/{unique-token}`. Guests can:

- Open the restaurant menu
- Call a waiter

The system does not accept food orders. It only identifies the table and sends a service alert.

The admin dashboard polls for waiter calls every four seconds. New calls appear in the red alert panel. Click **Siren Off** once to enable browser audio, then use:

- **Acknowledge** when a staff member accepts the call
- **Resolved** after the table has been served

If a table already has an active or acknowledged call, repeated guest taps reuse that call instead of creating duplicates.

Use the **Customer Call Waiter: On/Off** switch in the alert panel to control the feature globally. When off:

- The call button is hidden from customer table and menu pages
- The waiter-call API rejects customer requests
- Menu browsing remains available
