Skip to content

Commit

Permalink
Only return duplicates within the same scope in the `FilesResolver#du…
Browse files Browse the repository at this point in the history
…plicates` field resolver (#2048)

Previously, duplicates in all scopes were returned.
  • Loading branch information
thomasdax98 authored May 13, 2024
1 parent e938254 commit 584d14d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/wild-clocks-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/cms-api": patch
---

Only return duplicates within the same scope in the `FilesResolver#duplicates` field resolver

As a side effect `FilesService#findAllByHash` now accepts an optional scope parameter.
2 changes: 1 addition & 1 deletion packages/api/cms-api/src/dam/files/files.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function createFilesResolver({

@ResolveField(() => [File])
async duplicates(@Parent() file: FileInterface): Promise<FileInterface[]> {
const files = await this.filesService.findAllByHash(file.contentHash);
const files = await this.filesService.findAllByHash(file.contentHash, { scope: file.scope });
return files.filter((f) => f.id !== file.id);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/api/cms-api/src/dam/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export class FilesService {
return [files, totalCount];
}

async findAllByHash(contentHash: string): Promise<FileInterface[]> {
return withFilesSelect(this.selectQueryBuilder(), { contentHash }).getResult();
async findAllByHash(contentHash: string, options?: { scope?: DamScopeInterface }): Promise<FileInterface[]> {
return withFilesSelect(this.selectQueryBuilder(), { contentHash, scope: options?.scope }).getResult();
}

async findMultipleByIds(ids: string[]) {
Expand Down

0 comments on commit 584d14d

Please sign in to comment.