e4f8d804d5
Fixes [#16819](https://github.com/twentyhq/twenty/issues/16819) Added a post-query hook (NoteDeleteOnePostQueryHook) that automatically soft-deletes all associated noteTarget records when a note is deleted. ## Key changes: Created `note-delete-one.post-query.hook.ts` Uses `GlobalWorkspaceOrmManager` to access workspace entities correctly Executes in the proper workspace context to ensure data isolation Soft-deletes noteTarget records to maintain referential consistency ## Testing 1. Company notes Create a Company Create and attach a Note to the Company Navigate to Company → Notes page (should display the note) Delete the Note Navigate to Company → Notes page (should no longer crash) Restore the Note (should appear again) Delete and destroy the Note permanently Navigate to Company → Notes page (should still work, just empty) 2. Opportunity notes Create an Opportunity Create and attach a Note to the Opportunity Navigate to Opportunity → Notes page (should display the note) Delete the Note Navigate to Opportunity → Notes page (should no longer crash) Restore the Note (should appear again) Delete and destroy the Note permanently Navigate to Opportunity → Notes page (should still work, just empty) ### Expected behavior: Company Notes page remains functional at all stages No console errors Deleted notes properly excluded from the view Other notes on the same Company remain accessible Additional Notes This fix ensures data consistency by maintaining the relationship between notes and their targets throughout the deletion lifecycle. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import { type WorkspacePostQueryHookInstance } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/interfaces/workspace-query-hook.interface';
|
|
|
|
import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/decorators/workspace-query-hook.decorator';
|
|
import { WorkspaceQueryHookType } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/types/workspace-query-hook.type';
|
|
import { type AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
|
|
import { NotePostQueryHookService } from 'src/modules/note/query-hooks/note-post-query-hook.service';
|
|
import { NoteWorkspaceEntity } from 'src/modules/note/standard-objects/note.workspace-entity';
|
|
|
|
@Injectable()
|
|
@WorkspaceQueryHook({
|
|
key: `note.deleteMany`,
|
|
type: WorkspaceQueryHookType.POST_HOOK,
|
|
})
|
|
export class NoteDeleteManyPostQueryHook
|
|
implements WorkspacePostQueryHookInstance
|
|
{
|
|
constructor(
|
|
private readonly notePostQueryHookService: NotePostQueryHookService,
|
|
) {}
|
|
|
|
async execute(
|
|
authContext: AuthContext,
|
|
_objectName: string,
|
|
payload: NoteWorkspaceEntity[],
|
|
): Promise<void> {
|
|
await this.notePostQueryHookService.handleNoteTargetsDelete(
|
|
authContext,
|
|
payload,
|
|
);
|
|
}
|
|
}
|