fix workspace-member deletion with existing attachments/documents (#5232)
## Context We have a non-nullable constraint on authorId in attachments and documents, until we have soft-deletion we need to handle deletion of workspace-members and their attachments/documents. This PR introduces pre-hooks to deleteOne/deleteMany This is called when a user deletes a workspace-member from the members page Next: needs to be done on user level as well. This is called when users try to delete their own accounts. I've seen other issues such as re-creating a user with a previously used email failing.
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
|
||||
@Injectable()
|
||||
export class CommentRepository {
|
||||
constructor(
|
||||
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
|
||||
) {}
|
||||
|
||||
async deleteByAuthorId(authorId: string, workspaceId: string): Promise<void> {
|
||||
const dataSourceSchema =
|
||||
this.workspaceDataSourceService.getSchemaName(workspaceId);
|
||||
|
||||
await this.workspaceDataSourceService.executeRawQuery(
|
||||
`DELETE FROM ${dataSourceSchema}."comment" WHERE "authorId" = $1`,
|
||||
[authorId],
|
||||
workspaceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user