260321:1700 Correct Coresspondence / Doing RFA
This commit is contained in:
@@ -7,6 +7,68 @@ import {
|
||||
CommitBatchDto,
|
||||
} from '@/types/migration';
|
||||
|
||||
interface WrappedData {
|
||||
data?: unknown;
|
||||
}
|
||||
|
||||
const extractNestedData = <T,>(value: unknown): T => {
|
||||
let current: unknown = value;
|
||||
|
||||
for (let i = 0; i < 5; i += 1) {
|
||||
if (!current || typeof current !== 'object' || !('data' in current)) {
|
||||
return current as T;
|
||||
}
|
||||
|
||||
current = (current as WrappedData).data;
|
||||
}
|
||||
|
||||
return current as T;
|
||||
};
|
||||
|
||||
const normalizePaginatedResponse = <T,>(value: unknown): PaginatedResponse<T> => {
|
||||
const extracted = extractNestedData<unknown>(value);
|
||||
|
||||
if (!extracted || typeof extracted !== 'object') {
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
page: 1,
|
||||
limit: 0,
|
||||
totalPages: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const response = extracted as Partial<PaginatedResponse<T>> & { data?: unknown };
|
||||
|
||||
if (Array.isArray(response.items)) {
|
||||
return {
|
||||
items: response.items,
|
||||
total: response.total ?? response.items.length,
|
||||
page: response.page ?? 1,
|
||||
limit: response.limit ?? response.items.length,
|
||||
totalPages: response.totalPages ?? 1,
|
||||
};
|
||||
}
|
||||
|
||||
if (Array.isArray(response.data)) {
|
||||
return {
|
||||
items: response.data as T[],
|
||||
total: response.total ?? response.data.length,
|
||||
page: response.page ?? 1,
|
||||
limit: response.limit ?? response.data.length,
|
||||
totalPages: response.totalPages ?? 1,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
page: 1,
|
||||
limit: 0,
|
||||
totalPages: 0,
|
||||
};
|
||||
};
|
||||
|
||||
export const migrationService = {
|
||||
getReviewQueue: async (params: {
|
||||
page?: number;
|
||||
@@ -14,12 +76,12 @@ export const migrationService = {
|
||||
status?: MigrationReviewStatus;
|
||||
}): Promise<PaginatedResponse<MigrationReviewQueueItem>> => {
|
||||
const { data } = await api.get('/migration/queue', { params });
|
||||
return data?.data || data;
|
||||
return normalizePaginatedResponse<MigrationReviewQueueItem>(data);
|
||||
},
|
||||
|
||||
getQueueItem: async (id: number): Promise<MigrationReviewQueueItem> => {
|
||||
const { data } = await api.get(`/migration/queue/${id}`);
|
||||
return data?.data || data;
|
||||
return extractNestedData<MigrationReviewQueueItem>(data);
|
||||
},
|
||||
|
||||
getErrors: async (params: {
|
||||
@@ -27,7 +89,7 @@ export const migrationService = {
|
||||
limit?: number;
|
||||
}): Promise<PaginatedResponse<MigrationErrorItem>> => {
|
||||
const { data } = await api.get('/migration/errors', { params });
|
||||
return data?.data || data;
|
||||
return normalizePaginatedResponse<MigrationErrorItem>(data);
|
||||
},
|
||||
|
||||
approveQueueItem: async (id: number, payload: any, idempotencyKey: string) => {
|
||||
|
||||
Reference in New Issue
Block a user