nfp_sites/app/api/article.js

84 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-10-01 11:35:00 +00:00
const common = require('./common')
2019-09-13 13:33:10 +00:00
exports.createArticle = function(body) {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-13 13:33:10 +00:00
method: 'POST',
url: '/api/articles',
body: body,
})
}
exports.updateArticle = function(id, body) {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-13 13:33:10 +00:00
method: 'PUT',
url: '/api/articles/' + id,
body: body,
})
}
exports.getAllArticles = function() {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-13 13:33:10 +00:00
method: 'GET',
url: '/api/articles?includes=parent',
})
}
2019-09-14 19:03:38 +00:00
exports.getAllArticlesPagination = function(options) {
let extra = ''
if (options.sort) {
extra += '&sort=' + options.sort
}
if (options.per_page) {
extra += '&perPage=' + options.per_page
}
if (options.page) {
extra += '&page=' + options.page
}
if (options.includes) {
extra += '&includes=' + options.includes.join(',')
}
return '/api/articles?' + extra
}
exports.getAllPageArticles = function(pageId, includes) {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-14 19:03:38 +00:00
method: 'GET',
url: '/api/pages/' + pageId + '/articles?includes=' + includes.join(','),
})
}
exports.getAllPageArticlesPagination = function(pageId, options) {
let extra = ''
if (options.sort) {
extra += '&sort=' + options.sort
}
if (options.per_page) {
extra += '&perPage=' + options.per_page
}
if (options.page) {
extra += '&page=' + options.page
}
if (options.includes) {
extra += '&includes=' + options.includes.join(',')
}
return '/api/pages/' + pageId + '/articles?' + extra
}
2019-09-13 13:33:10 +00:00
exports.getArticle = function(id) {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-13 13:33:10 +00:00
method: 'GET',
2019-09-14 19:03:38 +00:00
url: '/api/articles/' + id + '?includes=media,parent,banner,files',
2019-09-13 13:33:10 +00:00
})
}
exports.removeArticle = function(article, id) {
2019-10-01 11:35:00 +00:00
return common.sendRequest({
2019-09-13 13:33:10 +00:00
method: 'DELETE',
url: '/api/articles/' + id,
})
}