Skip to content

Commit

Permalink
fix(api): Project hard sync existing entities deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
csehatt741 committed Feb 4, 2025
1 parent fd92c3b commit 026cc0b
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion apps/api/src/project/service/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,11 @@ export class ProjectService {
// hardCopy = false: Only add those items in the toProject that are not already present in it
hardCopy: boolean = false
) {
// This field will be populated if hardCopy is true
// When we are doing a hard copy, we need to delete all the
// items in the toProject that are already present in it
const deleteOps = []

// Get all the environments that belongs to the parent project
// and replicate them for the new project
const createEnvironmentOps = []
Expand Down Expand Up @@ -964,6 +969,30 @@ export class ProjectService {
variables.forEach((variable) => {
toProjectVariables.add(variable.name)
})
} else {
deleteOps.push(
this.prisma.environment.deleteMany({
where: {
projectId: toProject.id
}
})
)

deleteOps.push(
this.prisma.secret.deleteMany({
where: {
projectId: toProject.id
}
})
)

deleteOps.push(
this.prisma.variable.deleteMany({
where: {
projectId: toProject.id
}
})
)
}

// We want to find all such environments in the fromProject that
Expand Down Expand Up @@ -1117,7 +1146,12 @@ export class ProjectService {
)
}

return [...createEnvironmentOps, ...createSecretOps, ...createVariableOps]
return [
...deleteOps,
...createEnvironmentOps,
...createSecretOps,
...createVariableOps
]
}

/**
Expand Down

0 comments on commit 026cc0b

Please sign in to comment.