Added typings for database/destinations
This commit is contained in:
@@ -1,43 +1,22 @@
|
||||
import { asyncExecShell, getUserDetails } from '$lib/common';
|
||||
import { getUserDetails } from '$lib/common';
|
||||
import * as db from '$lib/database';
|
||||
import { ErrorHandler } from '$lib/database';
|
||||
import { dockerInstance } from '$lib/docker';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import type { CreateDockerDestination } from '$lib/types/destinations';
|
||||
|
||||
export const post: RequestHandler = async (event) => {
|
||||
const { teamId, status, body } = await getUserDetails(event);
|
||||
if (status === 401) return { status, body };
|
||||
|
||||
const {
|
||||
name,
|
||||
engine,
|
||||
network,
|
||||
isCoolifyProxyUsed,
|
||||
remoteEngine,
|
||||
ipAddress,
|
||||
user,
|
||||
port,
|
||||
sshPrivateKey
|
||||
} = await event.request.json();
|
||||
const dockerDestinationProps = {
|
||||
...((await event.request.json()) as Omit<CreateDockerDestination, 'teamId'>),
|
||||
teamId
|
||||
};
|
||||
|
||||
try {
|
||||
let id = null;
|
||||
if (remoteEngine) {
|
||||
id = await db.newRemoteDestination({
|
||||
name,
|
||||
teamId,
|
||||
engine,
|
||||
network,
|
||||
isCoolifyProxyUsed,
|
||||
remoteEngine,
|
||||
ipAddress,
|
||||
user,
|
||||
port,
|
||||
sshPrivateKey
|
||||
});
|
||||
} else {
|
||||
id = await db.newLocalDestination({ name, teamId, engine, network, isCoolifyProxyUsed });
|
||||
}
|
||||
const id = dockerDestinationProps.remoteEngine
|
||||
? await db.newRemoteDestination(dockerDestinationProps)
|
||||
: await db.newLocalDestination(dockerDestinationProps);
|
||||
return { status: 200, body: { id } };
|
||||
} catch (error) {
|
||||
return ErrorHandler(error);
|
||||
|
||||
Reference in New Issue
Block a user