Added startsWith param to getFindAllHref

This commit is contained in:
Mohamed Abdul Rasheed
2018-08-08 10:12:11 -04:00
parent 2d224bffc2
commit c11dcb14d1
3 changed files with 17 additions and 2 deletions

View File

@@ -104,15 +104,25 @@ describe('DataService', () => {
}); });
}); });
it('should include startsWith in href if startsWith provided in options', () => {
options = { startsWith: 'ab' };
const expected = `${endpoint}?startsWith=${options.startsWith}`;
(service as any).getFindAllHref(endpoint, options).subscribe((value) => {
expect(value).toBe(expected);
});
});
it('should include all provided options in href', () => { it('should include all provided options in href', () => {
const sortOptions = new SortOptions('field1', SortDirection.DESC) const sortOptions = new SortOptions('field1', SortDirection.DESC)
options = { options = {
currentPage: 6, currentPage: 6,
elementsPerPage: 10, elementsPerPage: 10,
sort: sortOptions sort: sortOptions,
startsWith: 'ab'
} }
const expected = `${endpoint}?page=${options.currentPage - 1}&size=${options.elementsPerPage}` + const expected = `${endpoint}?page=${options.currentPage - 1}&size=${options.elementsPerPage}` +
`&sort=${sortOptions.field},${sortOptions.direction}`; `&sort=${sortOptions.field},${sortOptions.direction}&startsWith=${options.startsWith}`;
(service as any).getFindAllHref(endpoint, options).subscribe((value) => { (service as any).getFindAllHref(endpoint, options).subscribe((value) => {
expect(value).toBe(expected); expect(value).toBe(expected);

View File

@@ -45,6 +45,10 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
args.push(`sort=${options.sort.field},${options.sort.direction}`); args.push(`sort=${options.sort.field},${options.sort.direction}`);
} }
if (hasValue(options.startsWith)) {
args.push(`startsWith=${options.startsWith}`);
}
if (isNotEmpty(args)) { if (isNotEmpty(args)) {
return result.map((href: string) => new URLCombiner(href, `?${args.join('&')}`).toString()); return result.map((href: string) => new URLCombiner(href, `?${args.join('&')}`).toString());
} else { } else {

View File

@@ -141,6 +141,7 @@ export class FindAllOptions {
elementsPerPage?: number; elementsPerPage?: number;
currentPage?: number; currentPage?: number;
sort?: SortOptions; sort?: SortOptions;
startsWith?: string;
} }
export class FindAllRequest extends GetRequest { export class FindAllRequest extends GetRequest {