aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/shared/rest/rest.service.ts
blob: 43dc20b34e09eb4618e17e43708baf2e34f276e5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                               
 
                                                  



                          

                                                                   

                     

                                                                                  
 

                                           


               
                              

     
                 


   
import { Injectable } from '@angular/core'
import { URLSearchParams } from '@angular/http'

import { RestPagination } from './rest-pagination'

@Injectable()
export class RestService {

  buildRestGetParams (pagination?: RestPagination, sort?: string) {
    const params = new URLSearchParams()

    if (pagination) {
      const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage
      const count: number = pagination.itemsPerPage

      params.set('start', start.toString())
      params.set('count', count.toString())
    }

    if (sort) {
      params.set('sort', sort)
    }

    return params
  }

}