| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- /**
- * Classe permettant de construire les options d'une URL
- */
- import TypesTesting from "~/services/utils/typesTesting";
- import {ListArgs, UrlArgs} from "~/types/interfaces";
- import {QUERY_TYPE} from "~/types/enums";
- class UrlOptionsBuilder {
- /**
- * Main méthode qui appellera les méthode privées correspondantes (getUrlOptionsImage, getUrlOptionsLists)
- * @param {UrlArgs} args
- * @return {string}
- */
- public static build(args: UrlArgs): Array<string> {
- let options: Array<string> = []
- if (args.type === QUERY_TYPE.IMAGE){
- options = [...options, this.getUrlOptionsImage()]
- }
- if (TypesTesting.isDataProviderArgs(args) && args.listArgs !== undefined) {
- options = [...options, ...this.getUrlOptionsLists(args.listArgs)]
- }
- return options
- }
- /**
- * Une image doit toujours avoir le time en options pour éviter les problème de cache
- * @private
- */
- private static getUrlOptionsImage(): string {
- return new Date().getTime().toString()
- }
- /**
- * Fonction renvoyant le tableau d'options d'une list
- * @param listArgs
- * @private
- */
- private static getUrlOptionsLists(listArgs: ListArgs): Array<string> {
- const options: Array<string> = []
- if (listArgs.itemsPerPage) {
- options.push(`itemsPerPage=${listArgs.itemsPerPage}`)
- }
- if (listArgs.page) {
- options.push(`page=${listArgs.page}`)
- }
- if (listArgs.filters) {
- for(const filter of listArgs.filters){
- options.push(`${filter.key}=${filter.value}`)
- }
- }
- return options
- }
- }
- export default UrlOptionsBuilder
|