fix(web): unwrap CacheMetaInterceptor envelope + dev port migration + homepage diacritic

Several fixes discovered while smoke-testing the homepage under the new
port layout (web 3200 / api 3201) to avoid clashing with a sibling project:

- analytics-api: add `unwrap<T>()` helper for the `{ data, cacheMeta }`
  envelope the backend CacheMetaInterceptor appends to every
  `/analytics/*` response. Apply to all 9 analytics methods. Without this
  `data.activeCount` (etc.) were `undefined`, crashing KpiStrip with
  `TypeError: Cannot read properties of undefined (reading 'toLocaleString')`.
- public page: hard-coded `city = 'Ho Chi Minh'` returned 0 rows because
  the DB stores `'Hồ Chí Minh'` and the SQL filter is case-insensitive but
  not diacritic-insensitive. Use the accented spelling.
- use-analytics hooks: add `useAuthedAnalytics()` gate so unauthenticated
  visitors on public routes no longer fire 401s from analytics queries.
- next.config.js CSP: add localhost:3200/3201 (http + ws) to connect-src so
  the web origin can reach the relocated API. Without this fetches hit
  `TypeError: Failed to fetch` on login.
- .claude/launch.json + package.json: web → 3200, api → 3201 (was 3000/3001,
  conflicting with the sibling psyforge project also using 3000).
- Minor follow-ups from parallel QA work on this branch (analytics modules,
  notifications gateway, auth test fixtures, trending-areas handler + DTO
  + tests, a few E2E smoke specs).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-22 16:54:44 +07:00
parent 1668c800fe
commit 3a9e44758c
29 changed files with 1418 additions and 69 deletions

View File

@@ -87,7 +87,7 @@ export class NotificationsController {
@ApiResponse({ status: 200, description: 'Unread count retrieved' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async getUnreadCount(@CurrentUser() user: JwtPayload) {
const count = await this.notificationRepo.countUnreadByUserId(user.sub);
const count = await this.notificationsGateway.getUnreadCount(user.sub);
return { unreadCount: count };
}

View File

@@ -269,8 +269,11 @@ export class NotificationsGateway
/**
* Read the unread count from Redis (cache-aside pattern).
* Falls back to the database when Redis is unavailable or cache misses.
*
* Public so REST callers (e.g. `GET /notifications/unread-count`) can
* share the same cached counter as the WebSocket fan-out.
*/
private async getUnreadCount(userId: string): Promise<number> {
async getUnreadCount(userId: string): Promise<number> {
if (this.redisService.isAvailable()) {
try {
const cached = await this.redisService.get(UNREAD_COUNT_KEY(userId));