import qs from 'querystringify' ; import { Article , SearchArticlesParams , NewArticle } from './types' ; import { Base , Pagination } from '../base' ; const resourceName = 'articles' ; export class Articles extends Base { getArticles ( params ? ) { let query = `${ resourceName }` ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Articles [ ] > ( query ) ; } getArticle ( id ) { return this . request < Article > ( `${ resourceName }/${ id }` ) ; } getArticleByPath ( username , slug ) { return this . request < Article > ( `${ resourceName }/${ username }/${ slug }` ) ; } getMyArticles ( params ? ) { let query = `${ resourceName }/me` ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Article [ ] > ( query ) ; } getMyPublishedArticles ( params ? ) { let query = `${ resourceName }/me/published` ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Article [ ] > ( query ) ; } getMyUnpublishedArticles ( params ? ) { let query = `${ resourceName }/me/unpublished` ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Article [ ] > ( query ) ; } getMyAllArticles ( params ? ) { let query = `${ resourceName }/me/all` ; if ( params ) { query += qs . stringify ( params , '?' ) ; } return this . request < Article [ ] > ( query ) ; } createArticle ( params ) { return this . request < Article > ( resourceName , { method : 'POST' , body : JSON . stringify ( { article : params } ) } ) ; } updateArticle ( id , params ? ) { return this . request < Article > ( `${ resourceName }/${ id }` , { method : 'PUT' , body : JSON . stringify ( { article : params } ) } ) ; } }