44 lines
1005 B
TypeScript
44 lines
1005 B
TypeScript
import type { API_HA_DeskPosition, TidalGetCurrent } from "@dpu/shared";
|
|
import type { FastifyInstance } from "fastify";
|
|
import { z } from "zod";
|
|
import type { HomepageService } from "./service.js";
|
|
|
|
export async function homepageRoutes(
|
|
fastify: FastifyInstance,
|
|
{
|
|
hpService,
|
|
}: {
|
|
hpService: HomepageService;
|
|
},
|
|
) {
|
|
fastify.get(
|
|
"/homepage/status",
|
|
{
|
|
schema: {
|
|
description: "Get all current information for dpu status page",
|
|
tags: ["homepage"],
|
|
response: {
|
|
200: z.object({
|
|
ha_desk_position: z.custom<API_HA_DeskPosition>().nullable(),
|
|
ha_temp: z.string().nullable(),
|
|
tidal_current: z.custom<TidalGetCurrent>().nullable(),
|
|
}),
|
|
418: z.object({
|
|
error: z.string(),
|
|
}),
|
|
},
|
|
},
|
|
},
|
|
async (_request, reply) => {
|
|
const service_result = await hpService.getFullInformation();
|
|
|
|
if (!service_result.successful) {
|
|
reply.code(418);
|
|
return { error: service_result.result };
|
|
}
|
|
|
|
return service_result.result;
|
|
},
|
|
);
|
|
}
|