-
-
Save eduardoalcantara/417836d89f52dee359bb69b666f6784f to your computer and use it in GitHub Desktop.
Query Options Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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