Fixed mismatched endpoint calling
This commit is contained in:
@@ -1549,8 +1549,18 @@ export const getProjectBeneficiaries = async (projectId: string | number): Promi
|
||||
|
||||
export const getBeneficiary = async (beneficiaryId: string | number): Promise<Beneficiary> => {
|
||||
const hashedBeneficiaryId = await toolsService.encodeId(beneficiaryId);
|
||||
const res = await apiClient.get<Beneficiary>(`/v1/api/projects/beneficiaries/${hashedBeneficiaryId}`);
|
||||
return res.data;
|
||||
try {
|
||||
const res = await apiClient.get<Beneficiary>(`/v1/api/projects/beneficiaries/${hashedBeneficiaryId}`);
|
||||
return res.data;
|
||||
} catch (err: any) {
|
||||
if (String(beneficiaryId) !== String(hashedBeneficiaryId)) {
|
||||
try {
|
||||
const fallbackRes = await apiClient.get<Beneficiary>(`/v1/api/projects/beneficiaries/${beneficiaryId}`);
|
||||
return fallbackRes.data;
|
||||
} catch {}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export const createBeneficiary = async (payload: CreateBeneficiaryRequest): Promise<void> => {
|
||||
@@ -1635,8 +1645,18 @@ export const getProjectChangeRequests = async (projectId: string | number): Prom
|
||||
|
||||
export const getChangeRequest = async (changeRequestId: string | number): Promise<ChangeRequest> => {
|
||||
const hashedChangeReqId = await toolsService.encodeId(changeRequestId);
|
||||
const res = await apiClient.get<ChangeRequest>(`/v1/api/projects/changerequests/${hashedChangeReqId}`);
|
||||
return res.data;
|
||||
try {
|
||||
const res = await apiClient.get<ChangeRequest>(`/v1/api/projects/changerequests/${hashedChangeReqId}`);
|
||||
return res.data;
|
||||
} catch (err: any) {
|
||||
if (String(changeRequestId) !== String(hashedChangeReqId)) {
|
||||
try {
|
||||
const fallbackRes = await apiClient.get<ChangeRequest>(`/v1/api/projects/changerequests/${changeRequestId}`);
|
||||
return fallbackRes.data;
|
||||
} catch {}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export const createChangeRequest = async (payload: CreateChangeRequest): Promise<void> => {
|
||||
@@ -1733,18 +1753,31 @@ export const createIssue = async (payload: CreateIssueRequest): Promise<void> =>
|
||||
};
|
||||
|
||||
export const updateIssue = async (payload: UpdateIssueRequest): Promise<void> => {
|
||||
const resolvedAtIso = payload.resolvedAt
|
||||
? (payload.resolvedAt.includes('T') ? payload.resolvedAt : new Date(payload.resolvedAt).toISOString())
|
||||
: null;
|
||||
let resolvedAtIso: string | null = null;
|
||||
if (payload.resolvedAt) {
|
||||
try {
|
||||
resolvedAtIso = payload.resolvedAt.includes('T') && payload.resolvedAt.endsWith('Z')
|
||||
? payload.resolvedAt
|
||||
: new Date(payload.resolvedAt).toISOString();
|
||||
} catch {
|
||||
resolvedAtIso = new Date().toISOString();
|
||||
}
|
||||
} else {
|
||||
resolvedAtIso = new Date().toISOString();
|
||||
}
|
||||
|
||||
const finalResolution = payload.resolution && payload.resolution.trim() !== ''
|
||||
? payload.resolution
|
||||
: (Number(payload.status) === ActivityStatus.Inactive ? 'Resolved' : 'Under active investigation');
|
||||
|
||||
await apiClient.put('/v1/api/projects/issues', {
|
||||
issueId: toIntegerId(payload.issueId),
|
||||
title: payload.title,
|
||||
description: payload.description,
|
||||
resolution: payload.resolution,
|
||||
resolution: finalResolution,
|
||||
resolvedAt: resolvedAtIso,
|
||||
priority: Number(payload.priority),
|
||||
status: Number(payload.status),
|
||||
status: payload.status !== undefined ? Number(payload.status) : ActivityStatus.Active,
|
||||
assignedTo: payload.assignedTo,
|
||||
});
|
||||
};
|
||||
@@ -1772,8 +1805,18 @@ export const getProjectSiteVisits = async (projectId: string | number): Promise<
|
||||
|
||||
export const getSiteVisit = async (siteVisitId: string | number): Promise<SiteVisit> => {
|
||||
const hashedVisitId = await toolsService.encodeId(siteVisitId);
|
||||
const res = await apiClient.get<SiteVisit>(`/v1/api/projects/sitevisits/${hashedVisitId}`);
|
||||
return res.data;
|
||||
try {
|
||||
const res = await apiClient.get<SiteVisit>(`/v1/api/projects/sitevisits/${hashedVisitId}`);
|
||||
return res.data;
|
||||
} catch (err: any) {
|
||||
if (String(siteVisitId) !== String(hashedVisitId)) {
|
||||
try {
|
||||
const fallbackRes = await apiClient.get<SiteVisit>(`/v1/api/projects/sitevisits/${siteVisitId}`);
|
||||
return fallbackRes.data;
|
||||
} catch {}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export const createSiteVisit = async (payload: CreateSiteVisitRequest): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user