mega-plant/lib/cash-float-server.ts

12 lines
560 B
TypeScript
Raw Permalink Normal View History

import "server-only";
import type PocketBase from "pocketbase";
import { normaliseCostCode } from "./cost-code";
/** The register vehicle a typed cost code names, or "" — matched like a purchase order's code, never guessed. */
export async function assetIdForCostCode(pb: PocketBase, costCode: string): Promise<string> {
const wanted = normaliseCostCode(costCode);
if (!wanted) return "";
const hit = (await pb.collection("assets").getFullList({ fields: "id,code" })).find((a) => normaliseCostCode(a.code || "") === wanted);
return hit?.id ?? "";
}