Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<img src="https://img.shields.io/badge/NestJS-framework-E0234E?logo=nestjs&logoColor=white" alt="NestJS" />
<img src="https://img.shields.io/badge/PostgreSQL-database-4169E1?logo=postgresql&logoColor=white" alt="PostgreSQL" />
<img src="https://img.shields.io/badge/License-Apache%202.0-blue" alt="Apache 2.0 License" />
<img src="https://img.shields.io/badge/Tests-1535%20passing-brightgreen" alt="1535 Tests Passing" /> <img src="https://img.shields.io/badge/AI%20Agents-12%20built--in-blueviolet" alt="12 AI Agents" />
<img src="https://img.shields.io/badge/Tests-1536%20passing-brightgreen" alt="1536 Tests Passing" /> <img src="https://img.shields.io/badge/AI%20Agents-12%20built--in-blueviolet" alt="12 AI Agents" />
</p>

<p align="center">
Expand Down Expand Up @@ -510,7 +510,7 @@ Operator notes for activating existing adapters, metasearch landings on the dire
| OTA Channels | Booking.com + Expedia (EQC) + SiteMinder + DerbySoft | Direct + aggregated OTA connectivity (ARI + content) |
| XML Processing | fast-xml-parser | Booking.com OTA XML protocol |
| Package Manager | pnpm workspaces | Monorepo management |
| Testing | Vitest (1535 tests across 217 test files) | Unit and integration tests || Build | tsup (packages) + Vite (dashboard) + nest build (API) | Fast builds |
| Testing | Vitest (1536 tests across 217 test files) | Unit and integration tests || Build | tsup (packages) + Vite (dashboard) + nest build (API) | Fast builds |
| Containers | Docker + docker-compose | Local dev and production deployment |
| CI/CD | GitHub Actions | Automated testing, builds, and releases |

Expand Down Expand Up @@ -642,7 +642,7 @@ Before going live, verify the items in [`docs/deployment.md`](./docs/deployment.
### Run tests

```bash
# All tests (1535 tests across 217 test files)
# All tests (1536 tests across 217 test files)

# API tests only
pnpm --filter @telivityhaip/api test
Expand Down Expand Up @@ -1190,7 +1190,7 @@ HAIP is built in public and contributions are welcome.
pnpm install # Install dependencies
pnpm build # Build all workspace packages
pnpm dev # Start API in dev mode (hot reload)
pnpm test # Run all tests (1535 tests, 217 files)
pnpm test # Run all tests (1536 tests, 217 files)
pnpm lint # ESLint
```

Expand Down
33 changes: 33 additions & 0 deletions apps/api/src/modules/reports/reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ describe('ReportsService', () => {
{ status: 'out_of_order', count: 5 },
{ status: 'out_of_service', count: 5 },
],
// occupied stay-window count (departure exclusive)
[{ count: 60 }],
// arrivals
[{ count: 8 }],
// departures
Expand Down Expand Up @@ -191,6 +193,7 @@ describe('ReportsService', () => {
{ status: 'out_of_order', count: 10 },
{ status: 'out_of_service', count: 5 },
],
[{ count: 20 }], // occupied stay-window
[{ count: 0 }], [{ count: 0 }], [{ count: 0 }], [{ count: 0 }], [{ count: 0 }],
]);
const module = await Test.createTestingModule({
Expand All @@ -207,6 +210,36 @@ describe('ReportsService', () => {
expect(result.occupancyRate).toBeCloseTo(0.5714, 3);
});

it('should ignore sticky room.status when stay window has no guests', async () => {
const db = createMockDb([
[{ totalRooms: 10 }],
[
{ status: 'occupied', count: 7 },
{ status: 'out_of_order', count: 1 },
{ status: 'vacant_clean', count: 2 },
],
[{ count: 0 }], // stay-window occupied = 0 (stale stayovers past departure)
[{ count: 0 }],
[{ count: 0 }],
[{ count: 0 }],
[{ count: 0 }],
[{ count: 0 }],
]);
const module = await Test.createTestingModule({
providers: [
ReportsService,
{ provide: DRIZZLE, useValue: db },
],
}).compile();
service = module.get(ReportsService);

const result = await service.getOccupancy('prop-001', '2026-08-20');
expect(result.occupiedRooms).toBe(0);
expect(result.availableRooms).toBe(9);
expect(result.occupancyRate).toBe(0);
expect(result.stayovers).toBe(0);
});

// --- Financial Summary ---

it('should calculate ADR correctly (revenue / rooms sold)', async () => {
Expand Down
27 changes: 22 additions & 5 deletions apps/api/src/modules/reports/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,29 @@ export class ReportsService {

let outOfOrder = 0;
let outOfService = 0;
let occupiedRooms = 0;
let occupiedFromRoomStatus = 0;
for (const row of roomStatusCounts) {
if (row.status === 'out_of_order') outOfOrder = row.count;
else if (row.status === 'out_of_service') outOfService = row.count;
else if (row.status === 'occupied') occupiedRooms = row.count;
else if (row.status === 'occupied') occupiedFromRoomStatus = row.count;
}

const availableRooms = totalRooms - outOfOrder - outOfService;

// Room-nights occupied on reportDate (departure exclusive). Prefer stay window
// over sticky room.status so stale demo stayovers past departure do not inflate %.
const [occupiedStayResult] = await this.db
.select({ count: sql<number>`count(*)::int` })
.from(reservations)
.where(
and(
eq(reservations.propertyId, propertyId),
sql`${reservations.status} in ('checked_in', 'stayover', 'due_out', 'checked_out')`,
lte(reservations.arrivalDate, reportDate),
sql`${reservations.departureDate} > ${reportDate}`,
),
);
const occupiedRooms = occupiedStayResult?.count ?? occupiedFromRoomStatus;
const occupancyRate = availableRooms > 0 ? occupiedRooms / availableRooms : 0;

// Arrivals (checked in today)
Expand All @@ -171,7 +186,7 @@ export class ReportsService {
),
);

// Stayovers (in-house continuing)
// Stayovers in-house continuing on reportDate (same stay-window as occupied)
const [stayoversResult] = await this.db
.select({ count: sql<number>`count(*)::int` })
.from(reservations)
Expand All @@ -180,6 +195,7 @@ export class ReportsService {
eq(reservations.propertyId, propertyId),
sql`${reservations.status} in ('stayover', 'checked_in', 'due_out')`,
lte(reservations.arrivalDate, reportDate),
sql`${reservations.departureDate} > ${reportDate}`,
),
);

Expand Down Expand Up @@ -303,15 +319,16 @@ export class ReportsService {
paymentsByMethod[row.method] = new Decimal(row.total).toNumber();
}

// Rooms sold
// Rooms sold — room-nights covering `date` (departure exclusive; matches occupancy trend)
const [roomsSoldResult] = await this.db
.select({ count: sql<number>`count(*)::int` })
.from(reservations)
.where(
and(
eq(reservations.propertyId, propertyId),
sql`${reservations.status} in ('checked_in', 'stayover', 'due_out')`,
sql`${reservations.status} in ('checked_in', 'stayover', 'due_out', 'checked_out')`,
lte(reservations.arrivalDate, date),
sql`${reservations.departureDate} > ${date}`,
),
);
const roomsSold = roomsSoldResult?.count ?? 0;
Expand Down
5 changes: 3 additions & 2 deletions docs/test-stats.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tests": 1535,
"tests": 1536,
"files": 217,
"updatedAt": "2026-08-21T01:30:40.178Z"
"updatedAt": "2026-08-21T03:39:58.360"
}
Z
Loading