baasic-sdk-nodejs
Version:
NodeJS SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
684 lines (683 loc) • 200 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ArticleClient = (function () {
function ArticleClient(baasicApp) {
this.baasicApp = baasicApp;
}
Object.defineProperty(ArticleClient.prototype, "articles", {
get: function () {
var baasicApp = this.baasicApp;
return {
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of article resources matching the given criteria.
* @method
* @param options A promise that is resolved once the find action has been performed.
* @returns A promise that is resolved once the find action has been performed.
* @example ArticleClient.articles.find({
pageNumber : 1,
pageSize : 10,
orderBy : '<field>',
orderDirection : '<asc|desc>',
search : '<search-phrase>'
})
.then(function (collection) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
find: function (options) {
return baasicApp.articleModule.articles.find(options);
},
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns a single article resource.
* @method
* @param id Article slug or id which uniquely identifies article resource that needs to be retrieved.
* @param options Options object that contains embed items.
* @returns a promise that is resolved once the get action has been performed.
* @example ArticleClient.articles.get('<article-id>')
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
get: function (id, options) {
return baasicApp.articleModule.articles.get(id, options);
},
/**
* Returns a promise that is resolved once the create article action has been performed, this action creates a new article resource.
* @method
* @param data An article object that needs to be inserted into the system.
* @returns a promise that is resolved once the create article action has been performed.
* @example ArticleClient.articles.create({
publishDate : new Date(),
title : '<title>',
content : '<content>',
slug : '',
status : baasicArticleClient.statuses.draft,
$tags : ['<tag1>', '<tag2>']
})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
create: function (data) {
return baasicApp.articleModule.articles.create(data);
},
/**
* Returns a promise that is resolved once the update article action has been performed; this action updates an article resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(article);
* let uri = params['model'].links('put').href;
* ```
* @method
* @param data An article object that needs to be updated into the system.
* @returns A promise that is resolved once the update article action has been performed.
* @example // article is a resource previously fetched using get action.
article.title = '<title>';
ArticleClient.articles.update(article)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
update: function (data) {
return baasicApp.articleModule.articles.update(data);
},
/**
* Returns a promise that is resolved once the saveDraft article action has been performed. This action saves an article with "draft" status. If an article does not exist it will create a new article resource otherwise it will update an existing article resource.
* @method
* @param data An article object that needs to be inserted into the system.
* @returns A promise that is resolved once the saveDraft article action has been performed.
* @example // article is a resource previously fetched using get action.
ArticleClient.articles.saveDraft(article)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
saveDraft: function (data) {
return baasicApp.articleModule.articles.saveDraft(data);
},
/**
* Returns a promise that is resolved once the remove article action has been performed. If the action is successfully completed, the article resource will be permanently removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.removeParams(article);
* let uri = params['model'].links('delete').href;
* ```
* @method
* @param data An article object that needs to be removed from the system.
* @returns A promise that is resolved once the remove article action has been performed.
* @example // article is a resource previously fetched using get action.
ArticleClient.articles.remove(article)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
remove: function (data) {
return baasicApp.articleModule.articles.remove(data);
},
/**
* Returns a promise that is resolved once the archive article action has been performed. This action sets the status of an article from "published" to "archive". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(article);
* let uri = params['model'].links('archive').href;
* ```
* @method
* @param data An article object.
* @param options Notification options.
* @returns A promise that is resolved once the archive article action has been performed.
* @example // article is a resource previously fetched using get action.
ArticleClient.articles.archive(article, articleOptions)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
archive: function (data, options) {
return baasicApp.articleModule.articles.archive(data, options);
},
/**
* Returns a promise that is resolved once the restore article action has been performed. This action sets the status of an article from "archive" to "published". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleRouteClient` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(article);
* let uri = params['model'].links('restore').href;
* ```
* @method
* @param data Article object.
* @returns A promise that is resolved once the restore article action has been performed.
* @example // article is a resource previously fetched using get action.
ArticleClient.articles.restore(article)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
restore: function (data) {
return baasicApp.articleModule.articles.restore(data);
},
/**
* Returns a promise that is resolved once the unpublish article action has been performed. This action sets the status of an article from "published" to "draft". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(article);
* let uri = params['model'].links('unpublish').href;
* ```
* @method
* @param data An article object.
* @returns A promise that is resolved once the unpublish article action has been performed.
* @example // article is a resource previously fetched using get action.
ArticleClient.articles.unpublish(article)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
unpublish: function (data) {
return baasicApp.articleModule.articles.unpublish(data);
},
/**
* Returns a promise that is resolved once the publish article action has been performed. This action sets the status of an article from "draft" to "published".
* @method
* @param data An article object.
* @param articleOptions Notification options.
* @returns A promise that is resolved once the unpublish article action has been performed.
* @example ArticleClient.articles.publish(article, articleOptions)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
publish: function (data, articleOptions) {
return baasicApp.articleModule.articles.publish(data, articleOptions);
},
/**
* Returns a promise that is resolved once the purge articles action has been performed. Please note that all article resources will be deleted from the system once the action is successfully completed and therefore it can only be executed by user assigned to account owner role.
* @method
* @example ArticleClient.articles.purge({})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
purge: function (options) {
return baasicApp.articleModule.articles.purge(options);
},
acl: {
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns a list of ACL policies established for the specified article resource.
* @method
* @example baasicArticleACLClient.get({id: '<article-id>'})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
get: function (options) {
return baasicApp.articleModule.articles.acl.get(options);
},
/**
* Returns a promise that is resolved once the update acl action has been performed, this action creates new ACL policy for the specified article resource.
* @method
* @param options An ACL policy object that needs to be updated in the system. This object specifies parameters necessary for establishing user and/or role set of rights.
* @returns A promise that is resolved once the update acl action has been performed.
* @example let options = {id : '<article-id>'};
let aclObj = {
actionId: '<action-id'>,
roleId: '<roleId>',
userId: '<userId>'
};
options[baasicConstants.modelPropertyName] = aclObj;
baasicArticleACLClient.update(options)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
update: function (options) {
return baasicApp.articleModule.articles.acl.update(options);
},
/**
* Returns a promise that is resolved once the removeByUser action has been performed. This action deletes ACL policy assigned to the specified user and article resource.
* @method
* @param articleId Article id which uniquely identifies article resource whose security privileges need to be retrieved and updated.
* @param action Action abbreviation which identifies ACL policy assigned to the specified user and article resource.
* Supported Values:
* "Create"
* "Delete"
* "Read"
* "Update"
* @param user A value that uniquely identifies user for which ACL policy needs to be removed.
* @param data An ACL policy object that needs to be updated in the system.
* @returns A promise that is resolved once the removeByUser action has been performed.
* @example baasicArticleACLClient.removeByUser('<article-id>', '<access-action>', '<username>')
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
removeByUser: function (articleId, action, user, data) {
return baasicApp.articleModule.articles.acl.removeByUser(articleId, action, user, data);
},
/**
* Returns a promise that is resolved once the removeByRole action has been performed. This action deletes ACL policy assigned to the specified role and article resource.
* @method
* @param articleId Article id which uniquely identifies article resource whose security privileges need to be retrieved and updated.
* @param action Action abbreviation which identifies ACL policy assigned to the specified user and article resource.
* Supported Values:
* "Create"
* "Delete"
* "Read"
* "Update"
* @param role A value that uniquely identifies role for which ACL policy needs to be removed.
* @param data An ACL policy object that needs to be updated in the system.
* @returns A promise that is resolved once the removeByRole action has been performed.
* @example baasicArticleACLClient.removeByRole('<article-id>', '<access-action>', '<role-name>')
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
removeByRole: function (articleId, action, role, data) {
return baasicApp.articleModule.articles.acl.removeByRole(articleId, action, role, data);
}
},
comments: {
/**
* Returns a promise that is resolved once the approve article comment action has been performed. This action sets the state of an article comment to "approved". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-approve').href;
* ```
* @method
* @param data Article Comment object.
* @param options Notification configuration used to control the article comment recourse access when managing notification distribution.
* @returns A promise that is resolved once the approve article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.approve(articleComment, commentOptions)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
approve: function (data, options) {
return baasicApp.articleModule.articles.comments.approve(data, options);
},
/**
* Returns a promise that is resolved once the unapprove article comment action has been performed. This action sets the state of an article comment to "unapproved". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-unapprove').href;
* ```
* @method
* @param data Article Comment object.
* @returns A promise that is resolved once the unapprove article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.unapprove(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
unapprove: function (data) {
return baasicApp.articleModule.articles.comments.unapprove(data);
},
/**
* Returns a promise that is resolved once the create article comment action has been performed; this action creates a new comment for an article.
* @method
* @param data An article comment object that needs to be inserted into the system.
* @returns A promise that is resolved once the create article comment action has been performed.
* @example ArticleClient.articles.comments.create({
articleId : '<article-id>',
comment : <comment>,
userId : '<user-id>' })
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
create: function (data) {
return baasicApp.articleModule.articles.comments.create(data);
},
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of article comment resources matching the given criteria.
* @method
* @param articleId Article slug or id which uniquely identifies article whose comment resources need to be retrieved.
* @param options Query resource options object.
* @returns A promise that is resolved once the find action has been performed.
* @example ArticleClient.articles.comments.find({
pageNumber : 1,
pageSize : 10,
orderBy : '<field>',
orderDirection : '<asc|desc>',
search : '<search-phrase>'
})
.success(function (collection) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
**/
find: function (articleId, options) {
return baasicApp.articleModule.articles.comments.find(articleId, options);
},
/**
* Returns a promise that is resolved once the flag article comment action has been performed. This action sets the state of an article comment to "flagged". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-flag').href;
* ```
* @method
* @param data Article Comment object.
* @returns A promise that is resolved once the flag article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.flag(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
flag: function (data) {
return baasicApp.articleModule.articles.comments.flag(data);
},
/**
* Returns a promise that is resolved once the unflag article comment action has been performed. This action removes the "flagged" comment mark. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-unflag').href;
* ```
* @method
* @param data Article Comment object.
* @returns A promise that is resolved once the unflag article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.unflag(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
unflag: function (data) {
return baasicApp.articleModule.articles.comments.unflag(data);
},
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns the specified article comment resource.
* @method
* @param articleId Article slug or id which uniquely identifies article whose comment resource needs to be retrieved.
* @param commentId Id which identifies article comment resource that needs to be retrieved.
* @param options Options object that contains embed data.
* @returns A promise that is resolved once the get action has been performed.
* @example ArticleClient.articles.comments.get('<article-id>', '<comment-id>')
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
get: function (articleId, commentId, options) {
return baasicApp.articleModule.articles.comments.get(articleId, commentId, options);
},
/**
* Returns a promise that is resolved once the remove article comment action has been performed. If the action is successfully completed, the article comment resource and its replies will be permanently removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
```
let params = modelMapper.removeParams(articleComment);
let uri = params['model'].links('delete').href;
```
* @method
* @param data An article comment object used to delete specified article comment resource.
* @returns A promise that is resolved once the remove article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.remove(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
remove: function (data) {
return baasicApp.articleModule.articles.comments.remove(data);
},
/**
* Returns a promise that is resolved once the removeAll article comment action has been performed. This action will remove all comments and comment replies from an article if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleInstanceRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.removeParams(articleComment);
* let uri = params['model'].links('delete-comments-by-article').href;
* ```
* @method
* @param data An article object used to delete specified article comment resource.
* @returns A promise that is resolved once the removeAll article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.removeAll(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
removeAll: function (data) {
return baasicApp.articleModule.articles.comments.removeAll(data);
},
/**
* Returns a promise that is resolved once the report article comment action has been performed. This action sets the state of an article comment to "reported". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-report').href;
* ```
* @method
* @param data Article Comment object.
* @param options Notification configuration used to control the article comment recourse access when managing notification distribution.
* @returns A promise that is resolved once the report article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.report(articleComment, commentOptions)
.success(function (data) {
// perform success action here
})
.error(function (response, status, headers, config) {
// perform error handling here
});
**/
report: function (data, options) {
return baasicApp.articleModule.articles.comments.report(data, options);
},
/**
* Returns a promise that is resolved once the unreport article comment action has been performed. This action removes the "reported" comment mark. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-unreport').href;
* ```
* @method
* @param data Article Comment object.
* @returns A promise that is resolved once the unreport article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.unreport(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
unreport: function (data) {
return baasicApp.articleModule.articles.comments.unreport(data);
},
/**
* Returns a promise that is resolved once the update article comment action has been performed; this action updates an article comment resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentsRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('put').href;
* ```
* @method
* @param data An article comments object used to update specified article comment resource.
* @returns A promise that is resolved once the update article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.article.comments.update(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
update: function (data) {
return baasicApp.articleModule.articles.comments.update(data);
},
/**
* Returns a promise that is resolved once the mark as spam article comment action has been performed. This action sets the state of an article comment to "spam". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleInstanceRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-spam').href;
* ```
* @method
* @param data Article Comment object.
* @returns A promise that is resolved once the mark as spam article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.spam(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
spam: function (data) {
return baasicApp.articleModule.articles.comments.spam(data);
},
/**
* Returns a promise that is resolved once the unspam article comment action has been performed. This action removes the "spam" comment state. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleInstanceRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleComment);
* let uri = params['model'].links('comment-unspam').href;
* ```
* @method
* @param data Article Comment object.
* @returns A promise that is resolved once the unspam article comment action has been performed.
* @example // articleComment is a resource previously fetched using get action.
ArticleClient.articles.comments.unspam(articleComment)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
unspam: function (data) {
return baasicApp.articleModule.articles.comments.unspam(data);
},
replies: {
/**
* Returns a promise that is resolved once the approve article comment reply action has been performed. This action sets the state of an article comment reply to "approved". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicArticleCommentRepliesRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleCommentReply);
* let uri = params['model'].links('comment-approve').href;
* ```
* @method
* @param data Article Comment Reply object.
* @param options Notification configuration used to control the article comment recourse access when managing notification distribution.
* @example // articleCommentReply is a resource previously fetched using get action.
ArticleClient.articles.comments.replies.approve(articleCommentReply, commentOptions)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
approve: function (data, options) {
return baasicApp.articleModule.articles.comments.replies.approve(data, options);
},
/**
* Returns a promise that is resolved once the unapprove article comment reply action has been performed. This action sets the state of an article comment reply to "unapproved". This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicarticleCommentRepliesRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(articleCommentReply);
* let uri = params['model'].links('comment-unapprove').href;
* ```
* @method
* @param data Article Comment Reply object.
* @returns A promise that is resolved once the unapprove article comment reply action has been performed.
* @example // articleCommentReply is a resource previously fetched using get action.
ArticleClient.articles.comments.replies.unapprove(articleCommentReply)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
unapprove: function (data) {
return baasicApp.articleModule.articles.comments.replies.unapprove(data);
},
/**
* Returns a promise that is resolved once the create article comment reply action has been performed; this action creates a new comment reply for an article.
* @method
* @param articleId Article id which uniquely identifies article that needs to be updated with new comment reply resource.
* @param data An article comment reply object that needs to be inserted into the system.
* @returns A promise that is resolved once the create article comment reply action has been performed.
* @example ArticleClient.articles.comments.replies.create('<article-id>', {
commentId : '<comment-id>',
comment : <comment>,
userId : '<user-id>' })
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
create: function (articleId, data) {
return baasicApp.articleModule.articles.comments.replies.create(articleId, data);
},
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of article comment reply resources matching the given criteria.
* @method
* @param articleId Article id which uniquely identifies article whose comment reply resources need to be retrieved.
* @param commentId Comment id which uniquely identifies comment whose reply resources need to be retrieved.
* @param options Query resource options.
* @returns A promise that is resolved once the find action has been performed.
* @example ArticleClient.articles.comments.replies.find({
pageNumber : 1,
pageSize : 10,
orderBy : '<field>',
orderDirection : '<asc|desc>',