mirror of
https://github.com/chatwoot/chatwoot.git
synced 2026-06-13 21:01:16 +08:00
106 lines
2.5 KiB
JavaScript
106 lines
2.5 KiB
JavaScript
/* global axios */
|
|
|
|
import PortalsAPI from './portals';
|
|
import { getArticleSearchURL } from 'dashboard/helper/URLHelper.js';
|
|
|
|
class ArticlesAPI extends PortalsAPI {
|
|
constructor() {
|
|
super('articles', { accountScoped: true });
|
|
}
|
|
|
|
getArticles({
|
|
pageNumber,
|
|
portalSlug,
|
|
locale,
|
|
status,
|
|
authorId,
|
|
categorySlug,
|
|
sort,
|
|
}) {
|
|
const url = getArticleSearchURL({
|
|
pageNumber,
|
|
portalSlug,
|
|
locale,
|
|
status,
|
|
authorId,
|
|
categorySlug,
|
|
sort,
|
|
host: this.url,
|
|
});
|
|
|
|
return axios.get(url);
|
|
}
|
|
|
|
searchArticles({ portalSlug, query }) {
|
|
const url = getArticleSearchURL({
|
|
portalSlug,
|
|
query,
|
|
host: this.url,
|
|
});
|
|
return axios.get(url);
|
|
}
|
|
|
|
getArticle({ id, portalSlug }) {
|
|
return axios.get(`${this.url}/${portalSlug}/articles/${id}`);
|
|
}
|
|
|
|
updateArticle({ portalSlug, articleId, articleObj }) {
|
|
return axios.patch(
|
|
`${this.url}/${portalSlug}/articles/${articleId}`,
|
|
articleObj
|
|
);
|
|
}
|
|
|
|
createArticle({ portalSlug, articleObj }) {
|
|
const { content, title, authorId, categoryId, locale } = articleObj;
|
|
return axios.post(`${this.url}/${portalSlug}/articles`, {
|
|
content,
|
|
title,
|
|
author_id: authorId,
|
|
category_id: categoryId,
|
|
locale,
|
|
});
|
|
}
|
|
|
|
deleteArticle({ articleId, portalSlug }) {
|
|
return axios.delete(`${this.url}/${portalSlug}/articles/${articleId}`);
|
|
}
|
|
|
|
reorderArticles({ portalSlug, reorderedGroup, categorySlug }) {
|
|
return axios.post(`${this.url}/${portalSlug}/articles/reorder`, {
|
|
positions_hash: reorderedGroup,
|
|
category_slug: categorySlug,
|
|
});
|
|
}
|
|
|
|
bulkTranslate({ portalSlug, articleIds, locale, categoryId, force = false }) {
|
|
return axios.post(
|
|
`${this.url}/${portalSlug}/articles/bulk_actions/translate`,
|
|
{ ids: articleIds, locale, category_id: categoryId, force }
|
|
);
|
|
}
|
|
|
|
bulkUpdateStatus({ portalSlug, articleIds, status }) {
|
|
return axios.patch(
|
|
`${this.url}/${portalSlug}/articles/bulk_actions/update_status`,
|
|
{ ids: articleIds, status }
|
|
);
|
|
}
|
|
|
|
bulkUpdateCategory({ portalSlug, articleIds, categoryId }) {
|
|
return axios.patch(
|
|
`${this.url}/${portalSlug}/articles/bulk_actions/update_category`,
|
|
{ ids: articleIds, category_id: categoryId }
|
|
);
|
|
}
|
|
|
|
bulkDelete({ portalSlug, articleIds }) {
|
|
return axios.delete(
|
|
`${this.url}/${portalSlug}/articles/bulk_actions/delete_articles`,
|
|
{ data: { ids: articleIds } }
|
|
);
|
|
}
|
|
}
|
|
|
|
export default new ArticlesAPI();
|