mirror of https://github.com/boxyhq/jackson.git
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
|
import jackson from '@lib/jackson';
|
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const { method } = req;
|
|
|
|
try {
|
|
switch (method) {
|
|
case 'GET':
|
|
return await handleGET(req, res);
|
|
case 'PATCH':
|
|
return await handlePATCH(req, res);
|
|
case 'DELETE':
|
|
return await handleDELETE(req, res);
|
|
default:
|
|
res.setHeader('Allow', 'GET, PUT, DELETE');
|
|
res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } });
|
|
}
|
|
} catch (error: any) {
|
|
const { message, statusCode = 500 } = error;
|
|
|
|
return res.status(statusCode).json({
|
|
error: { message },
|
|
});
|
|
}
|
|
};
|
|
|
|
// Get SAML Federation app by id
|
|
const handleGET = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const { samlFederatedController } = await jackson();
|
|
|
|
const { id } = req.query as { id: string };
|
|
|
|
const app = await samlFederatedController.app.get({ id });
|
|
const metadata = await samlFederatedController.app.getMetadata();
|
|
|
|
return res.status(200).json({
|
|
data: {
|
|
...app,
|
|
metadata,
|
|
},
|
|
});
|
|
};
|
|
|
|
// Update SAML Federation app
|
|
const handlePATCH = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const { samlFederatedController } = await jackson();
|
|
|
|
const updatedApp = await samlFederatedController.app.update(req.body);
|
|
|
|
return res.status(200).json({ data: updatedApp });
|
|
};
|
|
|
|
// Delete the SAML Federation app
|
|
const handleDELETE = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const { samlFederatedController } = await jackson();
|
|
|
|
const { id } = req.query as { id: string };
|
|
|
|
await samlFederatedController.app.delete({ id });
|
|
|
|
return res.status(200).json({ data: {} });
|
|
};
|
|
|
|
export default handler;
|