diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 638e1020..0b1a2086 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -320,7 +320,7 @@ export class Service { const oldDeployments = projectDeployments.filter( (projectDeployment) => projectDeployment.deployer.deployerLrn === - deployment.deployer.deployerLrn && + deployment.deployer.deployerLrn && projectDeployment.id !== deployment.id && projectDeployment.isCanonical == deployment.isCanonical, ); @@ -756,24 +756,7 @@ export class Service { true, ); - let dns; - // If a custom domain is present then use that as the DNS in the deployment request - // Only deployers with version > 1 support multiple custom domains - if (deployer!.version && Number(deployer!.version) >= 1) { - const customDomains = await this.db.getDomainsByProjectId( - data.project.id!, - ); - - dns = - customDomains.length > 0 - ? customDomains.map((d) => d.name).join(',') - : `${canonicalDeployment.project.name}`; - } else { - const domain = await this.db.getOldestDomainByProjectId( - canonicalDeployment.project.id, - ); - dns = domain?.name ?? `${canonicalDeployment.project.name}`; - } + const dns = await this.getDnsForDeployerByProjectId(data.project.id!, deployer!.version, canonicalDeployment.project.name) // On deleting deployment later, project canonical deployment is also deleted // So publish project canonical deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later @@ -1349,13 +1332,9 @@ export class Service { const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData; - const customDomains = await this.db.getDomainsByProjectId(projectId); + const dns = await this.getDnsForDeployerByProjectId(projectId, newCurrentDeployment.deployer!.version, newCurrentDeployment.project.name) - if (customDomains.length > 0 && applicationDeploymentRequestData) { - applicationDeploymentRequestData.dns = customDomains - .map((d) => d.name) - .join(','); - } + applicationDeploymentRequestData!.dns = dns // Create a canonical deployment for the new current deployment const canonicalDeployment = await this.createDeploymentFromData( @@ -1764,4 +1743,27 @@ export class Service { return amount === amountSent && sender === senderAddress && recipient === recipientAddress; } + + async getDnsForDeployerByProjectId(projectId: string, deployerVersion: string | undefined | null, projectName: string): Promise { + let dns; + // If a custom domain is present then use that as the DNS in the deployment request + // Only deployers with version > 1 support multiple custom domains + if (deployerVersion && Number(deployerVersion) >= 1) { + const customDomains = await this.db.getDomainsByProjectId( + projectId, + ); + + dns = + customDomains.length > 0 + ? customDomains.map((d) => d.name).join(',') + : `${projectName}`; + } else { + const domain = await this.db.getOldestDomainByProjectId( + projectId + ); + dns = domain?.name ?? `${projectName}`; + } + + return dns; + } }