51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { adaptPendingReviews } from "@/lib/adapters/reviews";
|
|
import { backendRequest } from "@/lib/http/backend-client";
|
|
import { jsonSuccess, withErrorHandling } from "@/lib/http/response";
|
|
import type {
|
|
PendingReviewResponseDto,
|
|
WorkflowStatusResponseDto,
|
|
} from "@/lib/types/backend";
|
|
import { adaptWorkflowDetail } from "@/lib/adapters/workflows";
|
|
import type { ReviewQueueItemVM } from "@/lib/types/view-models";
|
|
|
|
async function enrichQueueItem(
|
|
item: ReviewQueueItemVM,
|
|
): Promise<ReviewQueueItemVM> {
|
|
try {
|
|
const workflowResponse = await backendRequest<WorkflowStatusResponseDto>(
|
|
`/workflows/${item.orderId}`,
|
|
);
|
|
const workflow = adaptWorkflowDetail(workflowResponse.data);
|
|
|
|
return {
|
|
...item,
|
|
workflowType: workflow.workflowType,
|
|
hasMockAssets: workflow.hasMockAssets,
|
|
failureCount: workflow.failureCount,
|
|
};
|
|
} catch {
|
|
return item;
|
|
}
|
|
}
|
|
|
|
export async function GET(request: Request) {
|
|
return withErrorHandling(async () => {
|
|
void request;
|
|
const response = await backendRequest<PendingReviewResponseDto[]>(
|
|
"/reviews/pending",
|
|
);
|
|
const queue = adaptPendingReviews(response.data);
|
|
const items = await Promise.all(queue.items.map(enrichQueueItem));
|
|
|
|
return jsonSuccess(
|
|
{
|
|
...queue,
|
|
items,
|
|
},
|
|
{
|
|
mode: "proxy",
|
|
},
|
|
);
|
|
});
|
|
}
|