diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index d905e36f..d675dd24 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -1222,37 +1222,28 @@ export class Service { }, }); - // Compare deployer in DNS while deleting - if (deployment && deployment.applicationDeploymentRecordId) { // If deployment is current, remove deployment for project subdomain as well if (deployment.isCurrent) { - const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.deployer.baseDomain}`; + const dnsDeployment = await this.db.getDeployment({ + where: { + projectId: deployment.project.id, + deployer: deployment.deployer, + isDNS: true + } + }) - // TODO: Store the latest DNS deployment record - const deploymentRecords = - await this.laconicRegistry.getDeploymentRecordsByFilter({ - application: deployment.applicationRecordId, - url: currentDeploymentURL, - }); - - if (!deploymentRecords.length) { - log( - `No ApplicationDeploymentRecord found for URL ${currentDeploymentURL} and ApplicationDeploymentRecord id ${deployment.applicationDeploymentRecordId}`, - ); + if (!dnsDeployment) { + log(`DNS deployment for deployment with id ${deployment.id} not found`); return false; } - // Multiple records are fetched, take the latest record - const latestRecord = deploymentRecords - .sort((a, b) => new Date(b.createTime).getTime() - new Date(a.createTime).getTime())[0]; - await this.laconicRegistry.createApplicationDeploymentRemovalRequest({ - deploymentId: latestRecord.id, - deployerLrn: deployment.deployer.deployerLrn, - auctionId: deployment.project.auctionId, - payment: deployment.project.txHash + deploymentId: dnsDeployment.id, + deployerLrn: dnsDeployment.deployer.deployerLrn, + auctionId: dnsDeployment.project.auctionId, + payment: dnsDeployment.project.txHash }); }