Skip to content

Commit

Permalink
Add endpoint to get post title
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmbos committed Oct 8, 2024
1 parent 36dd412 commit c2f6e8b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pages/api/utils/post-image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NextApiRequest, NextApiResponse } from "next";
import { handleError } from "../errorHandler";
import { parseJsonRequest } from "../../../types/api/types";
import sql from "../../../database/db.mjs";
import { Post } from "../../../types/database/types";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
try {
if (req.method === "GET") {
const title = req.query["title"];
if (!title || typeof title !== "string") {
res.status(400);
}
const baseQuery = sql;
const postTitle = (
await sql<
{ title: string }[]
>`select title from post.post where title = ${title as string}`
)[0];
res.status(200).json(postTitle);
} else if (req.method === "POST") {
res.status(200).json({});
}
} catch (error) {
handleError(res, error, "An error occurred saving the post.");
}
}

0 comments on commit c2f6e8b

Please sign in to comment.