refactor(cloud): add validation to prevent create applications without server

This commit is contained in:
Mauricio Siu
2024-10-04 21:31:22 -06:00
parent 7c4987d84d
commit 09ef851372
8 changed files with 375 additions and 339 deletions

View File

@@ -64,6 +64,13 @@ export const composeRouter = createTRPCRouter({
if (ctx.user.rol === "user") {
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
}
if (IS_CLOUD && !input.serverId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You need to use a server to create a compose",
});
}
const project = await findProjectById(input.projectId);
if (project.adminId !== ctx.user.adminId) {
throw new TRPCError({
@@ -77,11 +84,7 @@ export const composeRouter = createTRPCRouter({
await addNewService(ctx.user.authId, newService.composeId);
}
} catch (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error to create the compose",
cause: error,
});
throw error;
}
}),
@@ -347,6 +350,13 @@ export const composeRouter = createTRPCRouter({
await checkServiceAccess(ctx.user.authId, input.projectId, "create");
}
if (IS_CLOUD && !input.serverId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You need to use a server to create a compose",
});
}
const composeFile = await readTemplateComposeFile(input.id);
const generate = await loadTemplateModule(input.id as TemplatesKeys);