Skip to content

Instantly share code, notes, and snippets.

@eduardoalcantara
Forked from krishna-acondy/query-options.ts
Created February 6, 2019 12:25
Show Gist options
  • Save eduardoalcantara/417836d89f52dee359bb69b666f6784f to your computer and use it in GitHub Desktop.
Save eduardoalcantara/417836d89f52dee359bb69b666f6784f to your computer and use it in GitHub Desktop.
Query Options Type
export interface QueryBuilder {
toQueryMap: () => Map<string, string>;
toQueryString: () => string;
}
export class QueryOptions implements QueryBuilder {
public pageNumber: number;
public pageSize: number;
constructor() {
this.pageNumber = 1;
this.pageSize = 10000;
}
toQueryMap() {
const queryMap = new Map<string, string>();
queryMap.set('pageNumber', `${this.pageNumber}`);
queryMap.set('pageSize', `${this.pageSize}`);
return queryMap;
}
toQueryString() {
let queryString = '';
this.toQueryMap().forEach((value: string, key: string) => {
queryString = queryString.concat(`${key}=${value}&`);
});
return queryString.substring(0, queryString.length - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment