Fix remove project (#7941)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-02-06 12:41:36 +07:00
committed by GitHub
parent dad177e61d
commit 997d910821
9 changed files with 90 additions and 52 deletions
@@ -98,10 +98,53 @@ export async function OnProjectChanges (txes: Tx[], control: TriggerControl): Pr
return result
}
/**
* @public
*/
export async function OnProjectRemove (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
const result: Tx[] = []
for (const ltx of txes) {
if (ltx._class === core.class.TxRemoveDoc) {
const cud = ltx as TxCUD<Doc>
if (control.hierarchy.isDerived(cud.objectClass, tracker.class.Project)) {
const project = control.removedMap.get(cud.objectId)
if (project === undefined) {
continue
}
if (control.hierarchy.hasMixin(project, github.mixin.GithubProject)) {
const repos = await control.findAll(control.ctx, github.class.GithubIntegrationRepository, {
githubProject: cud.objectId as Ref<GithubProject>
})
for (const repo of repos) {
result.push(
control.txFactory.createTxUpdateDoc(repo._class, repo.space, repo._id, {
enabled: false,
githubProject: null
})
)
}
const syncDocs = control.modelDb.findAllSync(github.class.DocSyncInfo, {
space: cud.objectId as Ref<Space>
})
for (const syncDoc of syncDocs) {
result.push(control.txFactory.createTxRemoveDoc(syncDoc._class, syncDoc.space, syncDoc._id))
}
}
}
}
}
if (result.length > 0) {
await OnGithubBroadcast(txes, control)
}
return result
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => ({
trigger: {
OnProjectChanges,
OnProjectRemove,
OnGithubBroadcast
},
functions: {