Standardizing apis

This commit is contained in:
Leo Giovanetti 2022-11-16 14:27:56 -03:00
parent 70b3f7b98e
commit 0258a18229
3 changed files with 12 additions and 8 deletions

View File

@ -1,10 +1,14 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { defaultResponder } from "@calcom/lib/server";
import checkSession from "../../_utils/auth";
import { checkInstalled } from "../../_utils/installation";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
const session = checkSession(req);
await checkInstalled("sendgrid", session.user?.id);
return res.status(200).json({ url: "/apps/sendgrid/setup" });
return { url: "/apps/sendgrid/setup" };
}
export default defaultResponder(getHandler);

View File

@ -1,3 +1,4 @@
import getInstalledAppPath from "_utils/getInstalledAppPath";
import type { NextApiRequest, NextApiResponse } from "next";
import { symmetricEncrypt } from "@calcom/lib/crypto";
@ -7,7 +8,6 @@ import { defaultResponder } from "@calcom/lib/server";
import prisma from "@calcom/prisma";
import checkSession from "../../_utils/auth";
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
const session = checkSession(req);
@ -30,10 +30,10 @@ export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
});
} catch (reason) {
logger.error("Could not add Sendgrid app", reason);
return res.status(500).json({ message: "Could not add Sendgrid app" });
return { message: "Could not add Sendgrid app", statusCode: 500 };
}
return res.status(200).json({ url: `/apps/installed/$other?hl=sendgrid` });
return { url: getInstalledAppPath({ variant: "other", slug: "sendgrid" }) };
}
export default defaultResponder(getHandler);

View File

@ -17,12 +17,12 @@ export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
try {
const usernameInfo = await sendgrid.username();
if (usernameInfo.username) {
return res.status(200).end();
return {};
} else {
return res.status(404).end();
return { statusCode: 404 };
}
} catch (e) {
return res.status(500).json({ message: e });
return { message: e, statusCode: 500 };
}
}