mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { apiFindAllByApplication } from "@/server/db/schema";
|
|
import {
|
|
findApplicationById,
|
|
findPreviewDeploymentById,
|
|
findPreviewDeploymentsByApplicationId,
|
|
removePreviewDeployment,
|
|
} from "@dokploy/server";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { z } from "zod";
|
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
|
|
|
export const previewDeploymentRouter = createTRPCRouter({
|
|
all: protectedProcedure
|
|
.input(apiFindAllByApplication)
|
|
.query(async ({ input, ctx }) => {
|
|
const application = await findApplicationById(input.applicationId);
|
|
if (application.project.adminId !== ctx.user.adminId) {
|
|
throw new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: "You are not authorized to access this application",
|
|
});
|
|
}
|
|
return await findPreviewDeploymentsByApplicationId(input.applicationId);
|
|
}),
|
|
delete: protectedProcedure
|
|
.input(z.object({ previewDeploymentId: z.string() }))
|
|
.mutation(async ({ input, ctx }) => {
|
|
const previewDeployment = await findPreviewDeploymentById(
|
|
input.previewDeploymentId,
|
|
);
|
|
if (previewDeployment.application.project.adminId !== ctx.user.adminId) {
|
|
throw new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: "You are not authorized to delete this preview deployment",
|
|
});
|
|
}
|
|
await removePreviewDeployment(input.previewDeploymentId);
|
|
return true;
|
|
}),
|
|
one: protectedProcedure
|
|
.input(z.object({ previewDeploymentId: z.string() }))
|
|
.query(async ({ input, ctx }) => {
|
|
const previewDeployment = await findPreviewDeploymentById(
|
|
input.previewDeploymentId,
|
|
);
|
|
if (previewDeployment.application.project.adminId !== ctx.user.adminId) {
|
|
throw new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: "You are not authorized to access this preview deployment",
|
|
});
|
|
}
|
|
return previewDeployment;
|
|
}),
|
|
});
|