Skip to content
Snippets Groups Projects
Commit c8b92215 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6301 OZG-6525 fix empty result list

parent 7bee29b0
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
*/ */
import { getEmbeddedResource } from '@ngxp/rest'; import { getEmbeddedResource } from '@ngxp/rest';
import { DummyListLinkRel } from 'libs/tech-shared/test/dummy'; import { DummyListLinkRel } from 'libs/tech-shared/test/dummy';
import { createDummyListResource } from 'libs/tech-shared/test/resource'; import { createDummyListResource, toResource } from 'libs/tech-shared/test/resource';
import { ListResource } from '../resource/resource.util'; import { ListResource } from '../resource/resource.util';
import { EMPTY_ARRAY } from '../tech.util'; import { EMPTY_ARRAY } from '../tech.util';
import { ToEmbeddedResourcesPipe } from './to-embedded-resource.pipe'; import { ToEmbeddedResourcesPipe } from './to-embedded-resource.pipe';
...@@ -55,5 +55,11 @@ describe('ToEmbeddedResourcesPipe', () => { ...@@ -55,5 +55,11 @@ describe('ToEmbeddedResourcesPipe', () => {
expect(result).toBe(EMPTY_ARRAY); expect(result).toBe(EMPTY_ARRAY);
}); });
it('should return empty array non existing resources', () => {
const result: unknown[] = pipe.transform(toResource({}), DummyListLinkRel.LIST);
expect(result).toBe(EMPTY_ARRAY);
});
}); });
}); });
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
*/ */
import { Pipe, PipeTransform } from '@angular/core'; import { Pipe, PipeTransform } from '@angular/core';
import { Resource, getEmbeddedResource } from '@ngxp/rest'; import { Resource, getEmbeddedResource } from '@ngxp/rest';
import { isNil } from 'lodash-es'; import { isNil, isNull } from 'lodash-es';
import { LinkRelationName } from '../resource/resource.model'; import { LinkRelationName } from '../resource/resource.model';
import { ListResource } from '../resource/resource.util'; import { ListResource } from '../resource/resource.util';
import { EMPTY_ARRAY } from '../tech.util'; import { EMPTY_ARRAY } from '../tech.util';
...@@ -32,6 +32,7 @@ import { EMPTY_ARRAY } from '../tech.util'; ...@@ -32,6 +32,7 @@ import { EMPTY_ARRAY } from '../tech.util';
export class ToEmbeddedResourcesPipe implements PipeTransform { export class ToEmbeddedResourcesPipe implements PipeTransform {
transform(listResource: ListResource, linkRel: LinkRelationName): Resource[] { transform(listResource: ListResource, linkRel: LinkRelationName): Resource[] {
if (isNil(listResource) || isNil(linkRel)) return EMPTY_ARRAY; if (isNil(listResource) || isNil(linkRel)) return EMPTY_ARRAY;
return getEmbeddedResource(listResource, linkRel); const embeddedReources: Resource[] = getEmbeddedResource(listResource, linkRel);
return isNull(embeddedReources) ? EMPTY_ARRAY : embeddedReources;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment