50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
"use server";
|
|
|
|
import {
|
|
fail,
|
|
type HousekeepingResult,
|
|
mapUnknownError,
|
|
} from "@/features/housekeeping/foundation/contracts";
|
|
import { createCorrelationId } from "@/features/housekeeping/foundation/correlation";
|
|
import type { HousekeepingRecentItem } from "@/features/housekeeping/foundation/recent/recent-work";
|
|
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
|
import {
|
|
loadHousekeepingRecentWork,
|
|
recordHousekeepingRouteVisit,
|
|
} from "@/lib/housekeeping-recent-work";
|
|
|
|
export async function executeHousekeepingRecent(): Promise<
|
|
HousekeepingResult<readonly HousekeepingRecentItem[]>
|
|
> {
|
|
try {
|
|
const context = await getHousekeepingCapabilityContext();
|
|
return await loadHousekeepingRecentWork(context);
|
|
} catch (error) {
|
|
return mapUnknownError(error);
|
|
}
|
|
}
|
|
|
|
export async function recordHousekeepingRouteVisitAction(
|
|
routeId: unknown,
|
|
): Promise<HousekeepingResult<HousekeepingRecentItem>> {
|
|
if (
|
|
typeof routeId !== "string" ||
|
|
!routeId.trim() ||
|
|
routeId !== routeId.trim() ||
|
|
routeId.length > 128
|
|
) {
|
|
return fail(
|
|
"VALIDATION",
|
|
"errors.housekeeping.recent.invalidRoute",
|
|
createCorrelationId(),
|
|
);
|
|
}
|
|
|
|
try {
|
|
const context = await getHousekeepingCapabilityContext();
|
|
return await recordHousekeepingRouteVisit(routeId, context);
|
|
} catch (error) {
|
|
return mapUnknownError(error);
|
|
}
|
|
}
|