Test 2 reoslutions
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { apiClient } from './httpClient';
|
||||
import { toolsService } from './toolsService';
|
||||
import { getCurrentUserSub } from '../auth/AuthProvider';
|
||||
import {
|
||||
getCurrentUserSub,
|
||||
getCurrentUserTenantId,
|
||||
getCurrentUserHashedTenantId,
|
||||
} from '../auth/AuthProvider';
|
||||
|
||||
export { getCurrentUserTenantId, getCurrentUserHashedTenantId };
|
||||
import {
|
||||
Dashboard,
|
||||
Organisation,
|
||||
@@ -144,8 +150,16 @@ export const getOrganisations = async (page = 1, pageSize = 100): Promise<Organi
|
||||
return list.map(normalizeOrganisation);
|
||||
};
|
||||
|
||||
export const getOrganisation = async (organisationId: string | number): Promise<Organisation> => {
|
||||
const hashedOrgId = await toolsService.resolveOrganisationId(organisationId);
|
||||
export const getOrganisation = async (organisationId?: string | number): Promise<Organisation> => {
|
||||
const targetOrgId =
|
||||
organisationId !== undefined && organisationId !== '' && organisationId !== null
|
||||
? organisationId
|
||||
: getCurrentUserTenantId();
|
||||
|
||||
if (targetOrgId === undefined || targetOrgId === null || targetOrgId === '') {
|
||||
throw new Error('Organisation ID is required');
|
||||
}
|
||||
const hashedOrgId = await toolsService.resolveOrganisationId(targetOrgId);
|
||||
const res = await apiClient.get<any>(`/v1/api/governance/organisations/${hashedOrgId}`);
|
||||
return normalizeOrganisation(res.data);
|
||||
};
|
||||
@@ -171,8 +185,16 @@ export const updateOrganisation = async (payload: UpdateOrganisationRequest): Pr
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getPortfolios = async (organisationId: string | number): Promise<Portfolio[]> => {
|
||||
const hashedOrgId = await toolsService.resolveOrganisationId(organisationId);
|
||||
export const getPortfolios = async (organisationId?: string | number): Promise<Portfolio[]> => {
|
||||
const targetOrgId =
|
||||
organisationId !== undefined && organisationId !== '' && organisationId !== null
|
||||
? organisationId
|
||||
: getCurrentUserTenantId();
|
||||
|
||||
if (targetOrgId === undefined || targetOrgId === null || targetOrgId === '') {
|
||||
return [];
|
||||
}
|
||||
const hashedOrgId = await toolsService.resolveOrganisationId(targetOrgId);
|
||||
const res = await apiClient.get<Portfolio[]>(`/v1/api/governance/organisations/${hashedOrgId}/portfolio`);
|
||||
return res.data || [];
|
||||
};
|
||||
@@ -214,10 +236,16 @@ export const createPortfolio = async (payload: CreatePortfolioRequest): Promise<
|
||||
if (ownerId && typeof ownerId === 'string' && ownerId.includes('@')) {
|
||||
ownerId = getUserIdByEmail(ownerId) || userSub || ownerId;
|
||||
}
|
||||
const tenantId = getCurrentUserTenantId();
|
||||
const orgId =
|
||||
payload.organisationId !== undefined && payload.organisationId !== '' && payload.organisationId !== null
|
||||
? toIntegerId(payload.organisationId)
|
||||
: (tenantId !== null ? tenantId : 0);
|
||||
|
||||
const res = await apiClient.post('/v1/api/governance/organisations/portfolio', {
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
organisationId: toIntegerId(payload.organisationId),
|
||||
organisationId: orgId,
|
||||
ownerId: ownerId || userSub || '00000000-0000-0000-0000-000000000000',
|
||||
});
|
||||
return res.data;
|
||||
@@ -481,8 +509,14 @@ export const getAward = async (awardId: string | number): Promise<Award> => {
|
||||
};
|
||||
|
||||
export const createAward = async (payload: CreateAwardRequest): Promise<Award> => {
|
||||
const tenantId = getCurrentUserTenantId();
|
||||
const orgId =
|
||||
payload.organisationId !== undefined && payload.organisationId !== '' && payload.organisationId !== null
|
||||
? toIntegerId(payload.organisationId)
|
||||
: (tenantId !== null ? tenantId : 0);
|
||||
|
||||
const res = await apiClient.post('/v1/api/grants/awards', {
|
||||
organisationId: toIntegerId(payload.organisationId),
|
||||
organisationId: orgId,
|
||||
programmeId: toIntegerId(payload.programmeId),
|
||||
amount: Number(payload.amount),
|
||||
});
|
||||
@@ -888,7 +922,36 @@ export const getUsers = async (
|
||||
pageSize = 100,
|
||||
filter: UserFilterRequest = {}
|
||||
): Promise<User[]> => {
|
||||
const res = await apiClient.post<User[]>(`/v1/api/users/${page}/${pageSize}`, filter);
|
||||
const tenantId = getCurrentUserTenantId();
|
||||
// Unless otherwise specified by the user, ensure tenant_id is passed into endpoints where organisationId is required for system activities
|
||||
const orgId =
|
||||
filter.organisationId !== undefined
|
||||
? (filter.organisationId !== null && filter.organisationId !== ''
|
||||
? toIntegerId(filter.organisationId)
|
||||
: null)
|
||||
: tenantId;
|
||||
|
||||
const requestBody: Record<string, any> = {
|
||||
...filter,
|
||||
};
|
||||
if (orgId !== null && orgId !== undefined) {
|
||||
requestBody.organisationId = orgId;
|
||||
}
|
||||
|
||||
// HashID query parameter for query string protection
|
||||
const queryParams: Record<string, any> = {};
|
||||
if (orgId !== null && orgId !== undefined) {
|
||||
const hashedOrgId = await toolsService.encodeId(orgId);
|
||||
if (hashedOrgId) {
|
||||
queryParams.organisationId = hashedOrgId;
|
||||
}
|
||||
}
|
||||
|
||||
const res = await apiClient.post<User[]>(
|
||||
`/v1/api/users/${page}/${pageSize}`,
|
||||
requestBody,
|
||||
{ params: Object.keys(queryParams).length > 0 ? queryParams : undefined }
|
||||
);
|
||||
const list = res.data || [];
|
||||
registerUserEmails(list);
|
||||
return list;
|
||||
@@ -981,8 +1044,14 @@ export const syncIntegration = async (force = true): Promise<void> => {
|
||||
// 8. Communications & Invites APIs
|
||||
// ==========================================
|
||||
export const sendInvite = async (payload: InviteRequest): Promise<Invite> => {
|
||||
const tenantId = getCurrentUserTenantId();
|
||||
const hostOrgId =
|
||||
payload.organisationId !== undefined && payload.organisationId !== '' && payload.organisationId !== null
|
||||
? toIntegerId(payload.organisationId)
|
||||
: (tenantId !== null ? tenantId : 0);
|
||||
|
||||
const res = await apiClient.post<Invite>('/v1/api/communications/invite', {
|
||||
organisationId: toIntegerId(payload.organisationId),
|
||||
organisationId: hostOrgId,
|
||||
invitedOrganisationId: toIntegerId(payload.invitedOrganisationId),
|
||||
awardId: toIntegerId(payload.awardId),
|
||||
contractId: toIntegerId(payload.contractId),
|
||||
|
||||
@@ -20,6 +20,8 @@ export interface UserSyncProfile {
|
||||
name?: string | null;
|
||||
role?: string | null;
|
||||
tenant?: string | null;
|
||||
tenant_id?: number | string | null;
|
||||
organisationId?: number | string | null;
|
||||
organisationName?: string | null;
|
||||
}
|
||||
|
||||
@@ -199,6 +201,19 @@ async function executeBackendSync(
|
||||
userSub?: string,
|
||||
profile?: UserSyncProfile
|
||||
): Promise<{ endpoint: string; data?: any }> {
|
||||
const rawTenantId = profile?.tenant_id ?? (profile as any)?.tenantId;
|
||||
const parsedTenantId =
|
||||
rawTenantId !== undefined && rawTenantId !== null && rawTenantId !== ''
|
||||
? Number(rawTenantId)
|
||||
: undefined;
|
||||
|
||||
const resolvedOrgId =
|
||||
parsedTenantId !== undefined
|
||||
? parsedTenantId
|
||||
: profile?.organisationId !== undefined && profile?.organisationId !== null && profile?.organisationId !== ''
|
||||
? Number(profile.organisationId)
|
||||
: undefined;
|
||||
|
||||
const payload = {
|
||||
id: userSub || profile?.id || profile?.sub,
|
||||
sub: userSub || profile?.sub,
|
||||
@@ -206,6 +221,8 @@ async function executeBackendSync(
|
||||
name: profile?.name || undefined,
|
||||
role: profile?.role || undefined,
|
||||
tenant: profile?.tenant || undefined,
|
||||
tenant_id: parsedTenantId,
|
||||
organisationId: resolvedOrgId,
|
||||
};
|
||||
|
||||
const candidateEndpoints = USER_SYNC_CANDIDATE_ENDPOINTS;
|
||||
|
||||
Reference in New Issue
Block a user