One large commit to avoid dealing with messy patches later on. Turns out I had https://marketplace.visualstudio.com/items?itemName=amatiasq.sort-imports installed with single quotes which messed up all double quotes from prettier.
38 lines
951 B
TypeScript
38 lines
951 B
TypeScript
import { NextApiRequest, NextApiResponse } from "next/types";
|
|
|
|
import { pgGetByIds } from "../../backend/database/pg-wrapper";
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
if (req.method !== "POST") {
|
|
res.status(400).send("Expected POST request");
|
|
return;
|
|
}
|
|
|
|
console.log(req.body);
|
|
let id = req.body.id;
|
|
console.log(id);
|
|
let dashboardItemArray = await pgGetByIds({
|
|
ids: [id],
|
|
schema: "latest",
|
|
table: "dashboards",
|
|
});
|
|
if (!!dashboardItemArray && dashboardItemArray.length > 0) {
|
|
let dashboardItem = dashboardItemArray[0];
|
|
console.log(dashboardItem);
|
|
let dashboardContents = await pgGetByIds({
|
|
ids: dashboardItem.contents,
|
|
schema: "latest",
|
|
table: "combined",
|
|
});
|
|
res.status(200).send({
|
|
dashboardContents,
|
|
dashboardItem,
|
|
});
|
|
} else {
|
|
res.status(404).send({ error: `Dashboard not found with id ${id}` });
|
|
}
|
|
}
|