2022-02-10 15:47:44 +01:00
|
|
|
import { getUserDetails } from '$lib/common';
|
|
|
|
import * as db from '$lib/database';
|
2022-02-14 09:28:37 +01:00
|
|
|
import { ErrorHandler } from '$lib/database';
|
2022-02-10 15:47:44 +01:00
|
|
|
import type { RequestHandler } from '@sveltejs/kit';
|
|
|
|
|
|
|
|
export const post: RequestHandler = async (event) => {
|
|
|
|
const { teamId, status, body } = await getUserDetails(event);
|
|
|
|
if (status === 401) return { status, body };
|
|
|
|
|
|
|
|
const { name, type, htmlUrl, apiUrl, organization } = await event.request.json();
|
|
|
|
try {
|
|
|
|
const { id } = await db.newSource({ name, teamId, type, htmlUrl, apiUrl, organization });
|
|
|
|
return { status: 201, body: { id } };
|
|
|
|
} catch (e) {
|
2022-02-14 09:28:37 +01:00
|
|
|
return ErrorHandler(e);
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
};
|