26 lines
859 B
TypeScript
26 lines
859 B
TypeScript
import { appResources } from "@/lib/mock-data";
|
|
import { AppResource } from "@/lib/types";
|
|
import { appListSchema, appResourceSchema } from "@/dto/app.dto";
|
|
import { requestWithSchema } from "@/services/api-client";
|
|
|
|
const USE_REMOTE_API = false;
|
|
|
|
export async function getApps(): Promise<AppResource[]> {
|
|
if (!USE_REMOTE_API) {
|
|
return appListSchema.parse(appResources) as AppResource[];
|
|
}
|
|
return requestWithSchema({
|
|
endpoint: "/api/apps",
|
|
schema: appListSchema,
|
|
}) as Promise<AppResource[]>;
|
|
}
|
|
|
|
export async function getAppBySlug(slug: string): Promise<AppResource | null> {
|
|
if (!USE_REMOTE_API) {
|
|
const matched = appResources.find((app) => app.slug === slug);
|
|
return matched ? (appResourceSchema.parse(matched) as AppResource) : null;
|
|
}
|
|
const all = await getApps();
|
|
return all.find((app) => app.slug === slug) ?? null;
|
|
}
|