Create new deployment when changing to production

This commit is contained in:
neeraj 2024-02-08 09:12:36 +05:30 committed by Nabarun
parent e0001466e0
commit 466b795eff
3 changed files with 16 additions and 10 deletions

View File

@ -121,9 +121,9 @@ export const createResolvers = async (db: Database, app: OAuthApp, service: Serv
}
},
updateDeploymentToProd: async (_: any, { deploymentId }: { deploymentId: string }) => {
updateDeploymentToProd: async (_: any, { deploymentId }: { deploymentId: string }, context: any) => {
try {
return await service.updateDeploymentToProd(deploymentId);
return Boolean(await service.updateDeploymentToProd(context.userId, deploymentId));
} catch (err) {
log(err);
return false;

View File

@ -149,7 +149,7 @@ export class Service {
return this.db.deleteEnvironmentVariable(environmentVariableId);
}
async updateDeploymentToProd (deploymentId: string): Promise<boolean> {
async updateDeploymentToProd (userId: string, deploymentId: string): Promise<Deployment> {
const deployment = await this.db.getDeployment({ where: { id: deploymentId }, relations: { project: true } });
if (!deployment) {
@ -173,13 +173,19 @@ export class Service {
});
}
const updateResult = await this.db.updateDeploymentById(deploymentId, {
environment: Environment.Production,
domain: prodBranchDomains[0],
isCurrent: true
const { createdAt, updatedAt, ...updatedDeployment } = deployment;
updatedDeployment.id = nanoid();
updatedDeployment.url = `${deployment.project.name}-${deployment.id}.${PROJECT_DOMAIN}`;
updatedDeployment.isCurrent = true;
updatedDeployment.environment = Environment.Production;
updatedDeployment.domain = prodBranchDomains[0];
updatedDeployment.createdBy = Object.assign(new User(), {
id: userId
});
return updateResult;
const newDeployement = await this.db.addDeployement(updatedDeployment);
return newDeployement;
}
async addProject (userId: string, organizationSlug: string, data: DeepPartial<Project>): Promise<Project | undefined> {

View File

@ -2,11 +2,11 @@
{
"id": "2379cf1f-a232-4ad2-ae14-4d881131cc26",
"name": "Snowball Tools",
"slug": "snowball-tools"
"slug": "snowball-tools-1"
},
{
"id": "7eb9b3eb-eb74-4b53-b59a-69884c82a7fb",
"name": "AirFoil",
"slug": "airfoil"
"slug": "airfoil-2"
}
]