22 lines
548 B
TypeScript
22 lines
548 B
TypeScript
import { db } from "#server/db";
|
|
import * as tables from "#server/db/schema";
|
|
import { eq } from "drizzle-orm";
|
|
import { z } from "zod";
|
|
|
|
const paramsSchema = z.object({
|
|
id: z.string().transform(Number),
|
|
});
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const params = await getValidatedRouterParams(event, paramsSchema.parse);
|
|
|
|
const link = await db.query.links.findFirst({
|
|
where: eq(tables.links.id, params.id),
|
|
});
|
|
if (!link) {
|
|
throw createError({ statusCode: 404, message: "Link not found" });
|
|
}
|
|
|
|
return link;
|
|
});
|