import { Params } from '@angular/router' ; import { Sort } from '../types/sort' ; import { APP_CONFIG } from '../../app.config' ; import { SortOrder } from '../../app.constants' ; export function convertSortToRequestParams ( sort ) { return { [ APP_CONFIG . sortRequestParam ] : sort . order === SortOrder . Desc ? `-${ sort . field }` : sort . field , } ; } export function convertQueryParamsToSort ( params , defaultSortField ) { let field = params . sort || defaultSortField ; let order = SortOrder . Asc ; if ( field . startsWith ( '-' ) ) { order = SortOrder . Desc ; field = field . substr ( 1 ) ; } return { field : field , order : order , } ; }