import { defaultGqlPermission, defaultPermission } from "@tailor-platform/erp-kit/core"; import { db } from "@tailor-platform/sdk"; import { costLayer } from "./costLayer"; import { inventoryLedger } from "./inventoryLedger"; const builtins = () => { return { costLayerId: db .uuid() .relation({ type: "n-1", toward: { type: costLayer, as: "costLayer" }, backward: "consumptions", }) .description("Layer the issue consumed from"), ledgerEntryId: db .uuid() .relation({ type: "n-1", toward: { type: inventoryLedger, as: "ledgerEntry" }, backward: "costLayerConsumptions", }) .description("OUT ledger entry that consumed the layer"), quantity: db.decimal().description("Quantity consumed from the layer"), }; }; export function createCostLayerConsumptionType() { return db .table("CostLayerConsumption", { ...builtins(), createdAt: db.fields.timestamps().createdAt, }) .permission(defaultPermission) .gqlPermission(defaultGqlPermission); } export const costLayerConsumption = createCostLayerConsumptionType();