2022-01-13 18:13:25 +00:00
|
|
|
import { promises as fs } from 'fs';
|
2022-01-13 17:07:44 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
2022-01-13 18:13:25 +00:00
|
|
|
import path from 'path';
|
2022-02-05 17:04:55 +00:00
|
|
|
import { apps, metadata } from '../../../services';
|
2022-01-13 17:07:44 +00:00
|
|
|
import type { App, IdPMetadata } from '../../../types';
|
|
|
|
|
|
|
|
|
|
export default async function handler(
|
|
|
|
|
req: NextApiRequest,
|
|
|
|
|
res: NextApiResponse<App | App[] | IdPMetadata | null>
|
|
|
|
|
) {
|
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:04:55 +00:00
|
|
|
async function getAllApps() {
|
|
|
|
|
const appList = await apps.getAll();
|
|
|
|
|
|
|
|
|
|
return res.json(appList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-05 17:04:55 +00:00
|
|
|
const app = await apps.create(name, description, acs_url, entity_id);
|
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
|
|
|
}
|
|
|
|
|
}
|