Backend: Customer module (list/search/detail) + working session auth + pnpm

Adds the unified Customer API against the migrated data:
- customers.service: list (search across name/email/phone/city/legacy id,
  business-line filter, pagination + per-row _count flags), detail (identity +
  legacyRefs + properties/services/trust + policies with installments/vehicles/
  drivers/beneficiaries/claims/docs + recent transactions + a per-domain/
  currency ledger summary), and stats.
- customers.controller: GET /customers, /customers/:id, /customers/stats,
  guarded by AuthenticatedGuard. Registered in AppModule.
- Fix LocalAuthGuard to call super.logIn so a session is actually established
  (login previously succeeded but persisted no session -> 403 afterwards).
- apps/api/scripts/seed-user.mjs: idempotent Argon2 admin seed.

Tooling: adopt pnpm as the package manager (machine npm is a pnpm shim that
ignores the workspaces field). Add pnpm-workspace.yaml (+ onlyBuiltDependencies
for argon2/prisma/nest native builds), switch the api's @jorgecuadros/database
dep to workspace:*, add @types/passport, track pnpm-lock.yaml, drop the stale
package-lock.json.

Verified end-to-end against the dev DB: login sets a session cookie; stats
returns 1682 customers / 526 both-lines / 45861 transactions; search + detail
return the full cross-line customer view (properties+services AND policies AND
a unified transaction statement).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 19:13:44 -07:00
co-authored by Claude Opus 4.8
parent 46d75473ba
commit 98f5cc20d8
11 changed files with 5963 additions and 8660 deletions
+16 -2
View File
@@ -1,5 +1,19 @@
import { Injectable } from "@nestjs/common";
import { ExecutionContext, Injectable } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { Request } from "express";
/**
* Validates credentials via LocalStrategy AND establishes the session:
* super.logIn(request) calls passport's req.login, which serializes the user
* into the session store so subsequent requests carry an authenticated
* session cookie (otherwise login succeeds but no session is persisted).
*/
@Injectable()
export class LocalAuthGuard extends AuthGuard("local") {}
export class LocalAuthGuard extends AuthGuard("local") {
async canActivate(context: ExecutionContext): Promise<boolean> {
const result = (await super.canActivate(context)) as boolean;
const request = context.switchToHttp().getRequest<Request>();
await super.logIn(request);
return result;
}
}