import qs from 'querystringify' ; import { Base , Pagination } from '../base' ; import { Listing , ListingCategory , NewListing , UpdateListing } from './types' ; const resourceName = 'listings' ; type SearchListingsParams = Pagination & { category ? : ListingCategory ; } ; export class Listings extends Base { getListings ( params ? ) { let query = resourceName ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Listing [ ] > ( query ) ; } getListingsByCategory ( category , params ? ) { let query = `${ resourceName }/category/${ category }` ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Listing [ ] > ( query ) ; } getListing ( id ) { return this . request < Listing > ( `${ resourceName }/${ id }` ) ; } createListing ( params ) { return this . request < Listing > ( resourceName , { method : 'POST' , body : JSON . stringify ( { classified_listing : params } ) } ) ; } updateListing ( id , params ? ) { return this . request < Listing > ( `${ resourceName }/${ id }` , { method : 'PUT' , body : JSON . stringify ( { classified_listing : params } ) } ) ; } }