40 lines
798 B
TypeScript
40 lines
798 B
TypeScript
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;
|
|
},
|
|
);
|
|
}
|