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);
|
||||
}
|
||||
@@ -1,27 +1,14 @@
|
||||
import { z } from "zod";
|
||||
import { createTRPCRouter, controllerProcedure, 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";
|
||||
import { createTRPCRouter, controllerProcedure } from "../trpc.js";
|
||||
import {
|
||||
computationGraphDetailProcedures,
|
||||
getProjectGraphData,
|
||||
getResourceGraphData,
|
||||
ProjectGraphInputSchema,
|
||||
ResourceGraphInputSchema,
|
||||
} from "./computation-graph-procedure-support.js";
|
||||
import { type GraphLink, type GraphNode } from "./computation-graph-shared.js";
|
||||
export type { GraphLink, GraphNode } from "./computation-graph-shared.js";
|
||||
|
||||
const resourceGraphInputSchema = z.object({
|
||||
resourceId: z.string(),
|
||||
month: z.string().regex(/^\d{4}-\d{2}$/),
|
||||
});
|
||||
|
||||
const projectGraphInputSchema = z.object({
|
||||
projectId: z.string(),
|
||||
});
|
||||
|
||||
const computationGraphDetailProcedures = createComputationGraphDetailProcedures({
|
||||
resourceGraphInputSchema,
|
||||
projectGraphInputSchema,
|
||||
readResourceGraphSnapshot,
|
||||
readProjectGraphSnapshot,
|
||||
});
|
||||
|
||||
// ─── Router ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const computationGraphRouter = createTRPCRouter({
|
||||
@@ -31,13 +18,13 @@ export const computationGraphRouter = createTRPCRouter({
|
||||
* for a single resource in a single month.
|
||||
*/
|
||||
getResourceData: controllerProcedure
|
||||
.input(resourceGraphInputSchema)
|
||||
.query(({ ctx, input }) => readResourceGraphSnapshot(ctx, input)),
|
||||
.input(ResourceGraphInputSchema)
|
||||
.query(({ ctx, input }) => getResourceGraphData(ctx, input)),
|
||||
|
||||
/**
|
||||
* Project View: Estimate, Commercial, Experience, Effort, Spread, Budget
|
||||
*/
|
||||
getProjectData: controllerProcedure
|
||||
.input(projectGraphInputSchema)
|
||||
.query(({ ctx, input }) => readProjectGraphSnapshot(ctx, input)),
|
||||
.input(ProjectGraphInputSchema)
|
||||
.query(({ ctx, input }) => getProjectGraphData(ctx, input)),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user