Created
April 4, 2018 14:21
-
-
Save krishna-acondy/0bb7110301e71ae6b641689faebbc0d9 to your computer and use it in GitHub Desktop.
Query Options Type
This file contains hidden or 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