Update flow for deleting deployments

This commit is contained in:
IshaVenikar 2025-01-31 15:49:21 +05:30
parent d28a270e7b
commit 4826242f0a

View File

@ -1208,37 +1208,28 @@ export class Service {
}, },
}); });
// Compare deployer in DNS while deleting
if (deployment && deployment.applicationDeploymentRecordId) { if (deployment && deployment.applicationDeploymentRecordId) {
// If deployment is current, remove deployment for project subdomain as well // If deployment is current, remove deployment for project subdomain as well
if (deployment.isCurrent) { 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 if (!dnsDeployment) {
const deploymentRecords = log(`DNS deployment for deployment with id ${deployment.id} not found`);
await this.laconicRegistry.getDeploymentRecordsByFilter({
application: deployment.applicationRecordId,
url: currentDeploymentURL,
});
if (!deploymentRecords.length) {
log(
`No ApplicationDeploymentRecord found for URL ${currentDeploymentURL} and ApplicationDeploymentRecord id ${deployment.applicationDeploymentRecordId}`,
);
return false; 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({ await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
deploymentId: latestRecord.id, deploymentId: dnsDeployment.id,
deployerLrn: deployment.deployer.deployerLrn, deployerLrn: dnsDeployment.deployer.deployerLrn,
auctionId: deployment.project.auctionId, auctionId: dnsDeployment.project.auctionId,
payment: deployment.project.txHash payment: dnsDeployment.project.txHash
}); });
} }