2022-08-08 10:17:32 +00:00
|
|
|
/* global axios */
|
2022-07-27 06:59:11 +00:00
|
|
|
|
2022-08-08 10:17:32 +00:00
|
|
|
import PortalsAPI from './portals';
|
|
|
|
|
|
|
|
class ArticlesAPI extends PortalsAPI {
|
2022-07-27 06:59:11 +00:00
|
|
|
constructor() {
|
|
|
|
super('articles', { accountScoped: true });
|
|
|
|
}
|
2022-08-08 10:17:32 +00:00
|
|
|
|
2022-08-10 05:18:41 +00:00
|
|
|
getArticles({
|
|
|
|
pageNumber,
|
|
|
|
portalSlug,
|
|
|
|
locale,
|
|
|
|
status,
|
|
|
|
author_id,
|
|
|
|
category_slug,
|
|
|
|
}) {
|
2022-08-08 10:17:32 +00:00
|
|
|
let baseUrl = `${this.url}/${portalSlug}/articles?page=${pageNumber}&locale=${locale}`;
|
|
|
|
if (status !== undefined) baseUrl += `&status=${status}`;
|
|
|
|
if (author_id) baseUrl += `&author_id=${author_id}`;
|
2022-08-10 05:18:41 +00:00
|
|
|
if (category_slug) baseUrl += `&category_slug=${category_slug}`;
|
2022-08-08 10:17:32 +00:00
|
|
|
return axios.get(baseUrl);
|
|
|
|
}
|
2022-08-16 12:25:34 +00:00
|
|
|
|
|
|
|
getArticle({ id, portalSlug }) {
|
|
|
|
return axios.get(`${this.url}/${portalSlug}/articles/${id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateArticle({ portalSlug, articleId, articleObj }) {
|
|
|
|
return axios.patch(
|
|
|
|
`${this.url}/${portalSlug}/articles/${articleId}`,
|
|
|
|
articleObj
|
|
|
|
);
|
|
|
|
}
|
2022-08-18 06:15:08 +00:00
|
|
|
|
|
|
|
createArticle({ portalSlug, articleObj }) {
|
|
|
|
const { content, title, author_id, category_id } = articleObj;
|
|
|
|
return axios.post(`${this.url}/${portalSlug}/articles`, {
|
|
|
|
content,
|
|
|
|
title,
|
|
|
|
author_id,
|
|
|
|
category_id,
|
|
|
|
});
|
|
|
|
}
|
2022-09-01 05:25:59 +00:00
|
|
|
|
|
|
|
deleteArticle({ articleId, portalSlug }) {
|
|
|
|
return axios.delete(`${this.url}/${portalSlug}/articles/${articleId}`);
|
|
|
|
}
|
2022-07-27 06:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new ArticlesAPI();
|