# Lebaan Closet — Backend deploy (cPanel / Node.js Selector)

App: `https://backend.lebaancloset.com` · cPanel home: `/home2/lebaancl` ·
App dir: `/home2/lebaancl/backend.lebaancloset.com` · Node 22.

This package = the API source (`server/`), the dependency manifest, a
production `server/.env` (DB + SMTP creds already filled in), and the
sequelize config. **Not included:** `node_modules` and `server/public/uploads`
(install deps on the host; keep the server's existing uploaded images).

## This release adds

- **Staff shift scheduling (roster).** Admins & managers create named shifts
  per branch (e.g. Morning 08:00–14:00) and assign branch staff to them.
  New API under `/api/shifts`, backed by **two new tables**:
  `Shifts` and `ShiftAssignments` (created by the one-time `DB_SYNC=alter`
  boot in step 2 — nothing manual).
- **Excel product import on the Products screen.** Uses the existing
  `/api/products/import` + `/api/products/import-template` endpoints (no new
  backend dependencies).

No new npm packages are required for this release, but running
`npm install --omit=dev` is still safe and ensures deps are present.

## Deploy — File Manager + Terminal

### 1. Upload the code
- cPanel → **File Manager** → go to `/home2/lebaancl/backend.lebaancloset.com`.
- Upload this zip, then **Extract** it there (it lays down `server/`,
  `package.json`, `package-lock.json`, `.sequelizerc`).
- It overwrites the old `server/` code. `server/public/uploads` is NOT in the
  zip, so existing product images are left in place.

### 2. Install deps + create the new tables + restart  (cPanel → Terminal)
Paste these in order:

```bash
source /home2/lebaancl/nodevenv/backend.lebaancloset.com/22/bin/activate && cd /home2/lebaancl/backend.lebaancloset.com

# Ensure dependencies are present
npm install --omit=dev

# Create the new Shifts / ShiftAssignments tables. DB_SYNC=alter reconciles the
# live tables to the models in one pass (creates the two missing tables; leaves
# existing tables intact), then we turn it back off.
DB_SYNC=alter node server/server.js &     # let it boot, print "synchronized", then:
sleep 25 && kill %1                        # stop this temporary boot
```

The shipped `server/.env` keeps `DB_SYNC=none`, so the normal app boot stays
fast. The line above only sets `alter` for that single temporary boot.

### 3. Restart the app
cPanel → **Setup Node.js App** → your app → **Restart**
(or `touch /home2/lebaancl/backend.lebaancloset.com/tmp/restart.txt`).

### 4. Verify
- `https://backend.lebaancloset.com/api/shifts?storeId=1` with an admin Bearer
  token → `{"success":true,"data":[...]}` (not a 500).
- In the app: **Admin → Staff Shifts** loads, you can create a shift and assign
  staff; **Products → Import Excel** downloads the template and imports a file.

## Notes
- `server/.env` already has DB (`lebaancl_*`), SMTP (`clients@lebaancloset.com`),
  `JWT_SECRET`, and `PUBLIC_BASE_URL=https://backend.lebaancloset.com`.
- The new shift endpoints are admin/manager-gated and branch-scoped (managers
  only see/manage their own branch; org admins can pick any branch).
- `server/scripts/fix-image-urls.js` ships in the zip from the prior release —
  only re-run it if broken `https//…` image URLs reappear; it's idempotent.
- Pre-existing console items unrelated to this release: `wss://…/socket.io`
  falling back to polling (Passenger doesn't upgrade WebSockets) and an
  occasional `401` on `/transactions/sync/catalog`.
