Skip to content

Commit

Permalink
Merge pull request #351 from prezly/fix/dev-19015-allow-coverage-inte…
Browse files Browse the repository at this point in the history
…grations-to-undelete-or-ignore-previously

[DEV-19015] Feature - Support multiple coverage entries with the same `external_reference_id`
  • Loading branch information
e1himself authored Dec 23, 2024
2 parents da78914 + f5519aa commit fdd79b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Client', () => {
});
const result = await prezlySdk.coverage.getByExternalReferenceId(externalReferenceId);

const search = `?include_deleted=on&query=%7B%22external_reference_id%22%3A%7B%22%24in%22%3A%5B%22${externalReferenceId}%22%5D%7D%7D`;
const search = `?include_deleted=on&query=%7B%22external_reference_id%22%3A%7B%22%24in%22%3A%5B%22${externalReferenceId}%22%5D%7D%7D&sort=deleted_at`;
expect(fetch).toHaveBeenCalledWith(`${defaultCoverageApiUrl}${search}`, {
...DEFAULT_REQUEST_PROPS,
method: Method.GET,
Expand Down
4 changes: 3 additions & 1 deletion src/endpoints/Coverage/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ export function createClient(api: DeferredJobsApiClient) {

async function getByExternalReferenceId(
externalReferenceId: string,
options: { includeDeleted?: boolean } = {},
): Promise<CoverageEntry | null> {
const query = JSON.stringify({ external_reference_id: { $in: [externalReferenceId] } });
const { coverage } = await search({
includeDeleted: true,
includeDeleted: options.includeDeleted ?? true,
query,
sortOrder: 'deleted_at', // Prefer non-deleted records first
});
return coverage[0] || null;
}
Expand Down

0 comments on commit fdd79b5

Please sign in to comment.