mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 21:20:57 +00:00
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>
14 lines
659 B
TypeScript
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;
|
|
}
|