Files
edr-platform/apps/edr-freight-api/src/modules/warehouses/current-actor.util.ts
Hagernesh 2647776d19 feat(warehouse): stamp actor as display name instead of UUID
Add actorLabel(user) — resolves the authenticated user to a readable name
(name → username → email → id) — and use it for the performed_by audit stamp on
every warehouse action, so the activity log shows a person, not a UUID. The
freight DB has no users table to join, so the name is stamped at write time.
approve-delivery keeps the raw user id (it is an id argument, not the audit
label). Existing rows keep their prior value; this applies going forward.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 15:24:05 +00:00

14 lines
659 B
TypeScript

import type { TCurrentUser } from '@tria-plc/api-common/modules/auth/types/current-user.type';
/**
* Human-readable actor label for audit stamps (`performed_by` / `moved_by`).
* Prefers a display name, then username/email, so the activity log shows a
* person rather than a UUID. Returns undefined when there is no authenticated
* user (internal/cron calls), letting callers fall back to their prior value.
*/
export function actorLabel(user?: TCurrentUser | null): string | undefined {
if (!user) return undefined;
const name = user.name?.en?.trim() || user.name?.am?.trim();
return name || user.username || user.email || user.id || undefined;
}