refactor: update project and API components to utilize environment context for organization authorization checks and enhance service retrieval methods

This commit is contained in:
Mauricio Siu
2025-09-01 20:36:03 -06:00
parent e0b6a8627a
commit 399bcb0302
4 changed files with 82 additions and 100 deletions

View File

@@ -31,7 +31,11 @@ export const findPreviewDeploymentById = async (
application: {
with: {
server: true,
project: true,
environment: {
with: {
project: true,
},
},
},
},
},
@@ -45,36 +49,7 @@ export const findPreviewDeploymentById = async (
return application;
};
export const findApplicationByPreview = async (applicationId: string) => {
const application = await db.query.applications.findFirst({
with: {
previewDeployments: {
where: eq(previewDeployments.applicationId, applicationId),
},
project: true,
domains: true,
deployments: true,
mounts: true,
redirects: true,
security: true,
ports: true,
registry: true,
gitlab: true,
github: true,
bitbucket: true,
gitea: true,
server: true,
},
});
if (!application) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Application not found",
});
}
return application;
};
export const removePreviewDeployment = async (previewDeploymentId: string) => {
try {
@@ -163,7 +138,7 @@ export const createPreviewDeployment = async (
const appName = `preview-${application.appName}-${generatePassword(6)}`;
const org = await db.query.organization.findFirst({
where: eq(organization.id, application.project.organizationId),
where: eq(organization.id, application.environment.project.organizationId),
});
const generateDomain = await generateWildcardDomain(
application.previewWildcard || "*.traefik.me",