freshter-logs/routes/api/msg/[id].ts
2023-04-28 19:48:34 -04:00

24 lines
639 B
TypeScript

import { PageProps } from "$fresh/server.ts";
import { json_response } from "utils";
import { get_message } from "db";
export async function handler(
req: Request,
props: PageProps
): Promise<Response> {
if (req.method == "GET") {
return await get(props);
} else {
return new Response(JSON.stringify({ err: "expected a PUT" }));
}
}
async function get(props: PageProps): Promise<Response> {
const got = await get_message(props.params.id);
if (!got) {
return json_response({ err: "not found" }, { status: 404 });
} else {
return json_response(got, { status: 300 });
}
}