formatting and grist
This commit is contained in:
39
src/grist/routes.ts
Normal file
39
src/grist/routes.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { GristRecord_PersonalGoals } from "@dpu/shared";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { z } from "zod";
|
||||
import type { GristService } from "./service";
|
||||
|
||||
export async function gristRoutes(
|
||||
fastify: FastifyInstance,
|
||||
{
|
||||
gristService,
|
||||
}: {
|
||||
gristService: GristService;
|
||||
},
|
||||
) {
|
||||
fastify.get(
|
||||
"/grist/today",
|
||||
{
|
||||
schema: {
|
||||
description: "Get goals for today",
|
||||
tags: ["grist"],
|
||||
response: {
|
||||
200: z.custom<GristRecord_PersonalGoals>(),
|
||||
418: z.object({
|
||||
error: z.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
async (_request, reply) => {
|
||||
const service_result = await gristService.getToday();
|
||||
|
||||
if (!service_result.successful) {
|
||||
reply.code(418);
|
||||
return { error: service_result.result };
|
||||
}
|
||||
|
||||
return service_result.result;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user