36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import type {NextRequest} from 'next/server';
|
|
import {sitesApi} from '@/services/api/sitesApi';
|
|
import {serveUpstream} from '@/shared/services/bff';
|
|
import type {ApiSiteCheck} from '@/services/api/types';
|
|
import type {SiteCheck} from '@/features/stores/types/siteCheck';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
function toSiteCheck(c: ApiSiteCheck): SiteCheck {
|
|
return {
|
|
siteName: c.site,
|
|
ok: c.ok,
|
|
steps: (c.steps ?? []).map((s) => ({
|
|
name: s.name,
|
|
status: s.status,
|
|
detail: s.detail,
|
|
advice: s.advice || null,
|
|
})),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* GET /api/sites/{site}/check — is this shop working, in five ordered steps.
|
|
*
|
|
* Answered from what head office already knows, so it works when the shop PC
|
|
* is off — which is itself one of the answers. Read-only and cheap, so it is a
|
|
* GET the screen can repeat as often as somebody taps it.
|
|
*/
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{params}: {params: Promise<{site: string}>},
|
|
) {
|
|
const {site} = await params;
|
|
return serveUpstream(req, (token) => sitesApi.check(token, site), toSiteCheck);
|
|
}
|