feat: add validate server

This commit is contained in:
Mauricio Siu
2024-12-08 19:37:11 -06:00
parent bf9abbc37c
commit 9a7ed91a55
6 changed files with 281 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ import {
haveActiveServices,
removeDeploymentsByServerId,
serverSetup,
serverValidate,
updateServerById,
} from "@dokploy/server";
import { TRPCError } from "@trpc/server";
@@ -118,6 +119,34 @@ export const serverRouter = createTRPCRouter({
throw error;
}
}),
validate: protectedProcedure
.input(apiFindOneServer)
.query(async ({ input, ctx }) => {
try {
const server = await findServerById(input.serverId);
if (server.adminId !== ctx.user.adminId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to validate this server",
});
}
const response = await serverValidate(input.serverId);
return response as unknown as {
isDockerInstalled: boolean;
isRCloneInstalled: boolean;
isSwarmInstalled: boolean;
isNixpacksInstalled: boolean;
isBuildpacksInstalled: boolean;
isMainDirectoryInstalled: boolean;
};
} catch (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message: error instanceof Error ? error?.message : `Error: ${error}`,
cause: error as Error,
});
}
}),
remove: protectedProcedure
.input(apiRemoveServer)
.mutation(async ({ input, ctx }) => {