2022-01-13 17:07:44 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
|
|
import type { App, IdPMetadata } from '../../../types';
|
2022-02-17 06:05:50 +00:00
|
|
|
import prisma from '../../../lib/prisma';
|
2022-01-13 17:07:44 +00:00
|
|
|
|
|
|
|
|
export default async function handler(
|
|
|
|
|
req: NextApiRequest,
|
2022-02-17 06:05:50 +00:00
|
|
|
res: NextApiResponse<App | App[]>
|
2022-01-13 17:07:44 +00:00
|
|
|
) {
|
2022-02-05 17:04:55 +00:00
|
|
|
|
|
|
|
|
switch (req.method) {
|
|
|
|
|
case 'GET':
|
|
|
|
|
return await getAllApps();
|
|
|
|
|
case 'POST':
|
|
|
|
|
return await createApp();
|
|
|
|
|
default:
|
|
|
|
|
return res.status(405).end(`Method ${req.method} Not Allowed`);
|
2022-01-13 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 17:05:37 +00:00
|
|
|
// Get all apps
|
2022-02-05 17:04:55 +00:00
|
|
|
async function getAllApps() {
|
2022-02-17 06:05:50 +00:00
|
|
|
const apps = await prisma.app.findMany();
|
2022-02-05 17:04:55 +00:00
|
|
|
|
2022-02-17 06:05:50 +00:00
|
|
|
return res.json(apps);
|
2022-02-05 17:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-17 06:05:50 +00:00
|
|
|
// Create a new app
|
2022-02-05 17:04:55 +00:00
|
|
|
async function createApp() {
|
2022-01-13 17:07:44 +00:00
|
|
|
const {
|
2022-02-05 17:04:55 +00:00
|
|
|
name,
|
2022-01-13 17:50:16 +00:00
|
|
|
acs_url,
|
|
|
|
|
entity_id,
|
2022-01-13 17:07:44 +00:00
|
|
|
description = null,
|
|
|
|
|
} = req.body;
|
|
|
|
|
|
2022-02-17 06:05:50 +00:00
|
|
|
const app = await prisma.app.create({
|
|
|
|
|
data: {
|
|
|
|
|
name,
|
|
|
|
|
acs_url,
|
|
|
|
|
entity_id,
|
|
|
|
|
description
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-01-13 17:07:44 +00:00
|
|
|
|
2022-02-05 17:04:55 +00:00
|
|
|
return res.json(app);
|
2022-01-13 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
}
|