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

OZG-5012 impl getItems

parent 8b052f1d
No related branches found
No related tags found
No related merge requests found
...@@ -473,4 +473,25 @@ describe('ListResourceService', () => { ...@@ -473,4 +473,25 @@ describe('ListResourceService', () => {
expect(isFirst).toBe(true); expect(isFirst).toBe(true);
}); });
}); });
describe('get items', () => {
it('should return empty array on empty stateResource', (done) => {
service.listResource.next(createEmptyStateResource());
service.getItems().subscribe((items) => {
expect(items).toEqual([]);
done();
});
});
it('should return listresource items', (done) => {
const listIems: Resource[] = [createDummyResource()];
service.listResource.next(createStateResource(createFilledDummyListResource(listIems)));
service.getItems().subscribe((items) => {
expect(items).toEqual(listIems);
done();
});
});
});
}); });
import { Resource, ResourceUri, getUrl, hasLink } from '@ngxp/rest'; import { Resource, ResourceUri, getUrl, hasLink } from '@ngxp/rest';
import { isEqual, isNull } from 'lodash-es'; import { isEqual, isNull } from 'lodash-es';
import { BehaviorSubject, Observable, combineLatest, filter, first, startWith, tap } from 'rxjs'; import {
BehaviorSubject,
Observable,
combineLatest,
filter,
first,
map,
startWith,
tap,
} from 'rxjs';
import { isNotNull, isNotUndefined } from '../tech.util'; import { isNotNull, isNotUndefined } from '../tech.util';
import { CreateResourceData, ListItemResource, ListResourceServiceConfig } from './resource.model'; import { CreateResourceData, ListItemResource, ListResourceServiceConfig } from './resource.model';
import { ResourceRepository } from './resource.repository'; import { ResourceRepository } from './resource.repository';
...@@ -220,4 +229,14 @@ export class ResourceListService< ...@@ -220,4 +229,14 @@ export class ResourceListService<
private getListResource(): T { private getListResource(): T {
return this.listResource.value.resource; return this.listResource.value.resource;
} }
public getItems(): Observable<ListItemResource[]> {
return this.listResource
.asObservable()
.pipe(
map((listStateResource: StateResource<T>) =>
getEmbeddedResources<ListItemResource>(listStateResource, this.config.listLinkRel),
),
);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment