refactor(api): extract computation graph procedures
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { z } from "zod";
|
||||
import type { TRPCContext } from "../trpc.js";
|
||||
import { createComputationGraphDetailProcedures } from "./computation-graph-detail.js";
|
||||
import { readProjectGraphSnapshot } from "./computation-graph-project.js";
|
||||
import { readResourceGraphSnapshot } from "./computation-graph-resource.js";
|
||||
|
||||
export const ResourceGraphInputSchema = z.object({
|
||||
resourceId: z.string(),
|
||||
month: z.string().regex(/^\d{4}-\d{2}$/),
|
||||
});
|
||||
|
||||
export const ProjectGraphInputSchema = z.object({
|
||||
projectId: z.string(),
|
||||
});
|
||||
|
||||
type ComputationGraphProcedureContext = Pick<TRPCContext, "db">;
|
||||
|
||||
export const computationGraphDetailProcedures = createComputationGraphDetailProcedures({
|
||||
resourceGraphInputSchema: ResourceGraphInputSchema,
|
||||
projectGraphInputSchema: ProjectGraphInputSchema,
|
||||
readResourceGraphSnapshot,
|
||||
readProjectGraphSnapshot,
|
||||
});
|
||||
|
||||
export async function getResourceGraphData(
|
||||
ctx: ComputationGraphProcedureContext,
|
||||
input: z.infer<typeof ResourceGraphInputSchema>,
|
||||
) {
|
||||
return readResourceGraphSnapshot(ctx, input);
|
||||
}
|
||||
|
||||
export async function getProjectGraphData(
|
||||
ctx: ComputationGraphProcedureContext,
|
||||
input: z.infer<typeof ProjectGraphInputSchema>,
|
||||
) {
|
||||
return readProjectGraphSnapshot(ctx, input);
|
||||
}
|
||||
Reference in New Issue
Block a user