Merge pull request #893 from Tria-plc/freight_feature/usermanagement

feat(freight-me): add position type lookup and enrich user profile wi…
This commit is contained in:
marshal
2026-07-22 03:08:56 +03:00
committed by GitHub

View File

@@ -1,5 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import type { TCurrentUser } from '@tria-plc/api-common/modules/auth/types/current-user.type';
import { DataSource } from 'typeorm';
import {
collectPermissionKeys,
@@ -9,7 +11,35 @@ import { PERMISSIONS_CATALOG } from '../../seed/freight-permissions.registry';
@Injectable()
export class FreightMeService {
getEnrichedProfile(user: TCurrentUser) {
constructor(@InjectDataSource() private readonly dataSource: DataSource) {}
/**
* The JWT session snapshot has no position TYPE, but the backoffice needs it
* (GL sub-positions are identified by type key). Resolved live from IAM.
*/
private async lookupPositionType(
positionId: string | undefined,
): Promise<{ key: string; name: unknown } | null> {
if (!positionId) return null;
try {
const rows: { key: string; name: unknown }[] = await this.dataSource.query(
`SELECT pt.key, pt.name
FROM iam.positions p
JOIN iam.position_types pt ON pt.id = p.position_type_id
WHERE p.id = $1`,
[positionId],
);
return rows[0] ?? null;
} catch {
return null; // iam schema unreachable — degrade to the old payload shape
}
}
async getEnrichedProfile(user: TCurrentUser) {
const positionType = await this.lookupPositionType(
user.employee?.position?.id,
);
const employee = user.employee
? [
{
@@ -27,6 +57,7 @@ export class FreightMeService {
isDelegate: user.employee.position.isDelegate,
parentPositionId: user.employee.position.parentPositionId,
permissions: user.employee.position.permissions ?? [],
positionType,
},
]
: [],