import { Injectable , Inject } from '@angular/core' ; import { APP_CONFIG } from "../../app.config" ; import { QueryHelper } from "./models/requests/query-helper.class" ; import { QueryFilter } from "./models/requests/query-filter.class" ; import { QueryOrdering } from "./models/requests/query-ordering.class" ; @ Injectable ( ) export class QueryHelperService { constructor ( @ Inject ( APP_CONFIG ) private config ) { } public getExportQueryString ( exportType , queryFilters = [ ] , searchTerm = null , queryOrdering = null , includedFields = [ ] ) { let queryHelper = new QueryHelper ( ) ; if ( queryOrdering ) { queryHelper . orderBy ( queryOrdering . orderField , queryOrdering . orderDirection ) ; } queryHelper . addFilters ( queryFilters ) ; queryHelper . searchTerm = searchTerm ; queryHelper . exportType = exportType ; queryHelper . includedFields = includedFields ; return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } public getQueryString ( page = 1 , queryFilters = [ ] , orderField = null , orderDirection = null , searchTerm = null ) { let queryHelper = new QueryHelper ( ) ; queryHelper . page = page ; if ( orderField != null ) { queryHelper . orderBy ( orderField , orderDirection ) ; } queryHelper . addFilters ( queryFilters ) ; queryHelper . searchTerm = searchTerm ; return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } public getQueryStringNew ( page = 1 , queryFilters = [ ] , queryOrdering = null , searchTerm = null ) { let queryHelper = new QueryHelper ( ) ; queryHelper . page = page ; if ( queryOrdering ) { queryHelper . orderBy ( queryOrdering . orderField , queryOrdering . orderDirection ) ; } queryHelper . addFilters ( queryFilters ) ; queryHelper . searchTerm = searchTerm ; return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } public getQueryStringFromFilters ( queryFilters ) { let queryHelper = new QueryHelper ( ) ; queryHelper . addFilters ( queryFilters ) ; return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } public getQueryStringFromFiltersAndSearch ( queryFilters = [ ] , searchTerm = null ) { let queryHelper = new QueryHelper ( ) ; queryHelper . addFilters ( queryFilters ) ; queryHelper . searchTerm = searchTerm ; return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } public getQueryStringForPage ( page ) { let queryHelper = new QueryHelper ( ) ; queryHelper . page = page ; return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } public getQueryStringForPageAndOrder ( page , orderField ? , orderDirection ? ) { let queryHelper = new QueryHelper ( ) ; queryHelper . page = page ; if ( orderField ) { queryHelper . orderBy ( orderField , orderDirection ) ; } return queryHelper . getQueryString ( this . config . orderingKey , this . config . paginationKey , this . config . searchKey , this . config . exportKey , this . config . includeFieldsKey ) ; } }