starkinfra
Version:
SDK to facilitate Node integrations with Stark Infra
105 lines (96 loc) • 4.87 kB
JavaScript
const rest = require('../../utils/rest.js');
const check = require('starkcore').check;
const Resource = require('../../utils/resource.js').Resource;
class Log extends Resource {
/**
*
* PixPullRequest Log object
*
* @description Every time a PixPullRequest entity is modified, a corresponding PixPullRequest.Log
* is generated for the entity. This log is never generated by the user.
*
* Attributes:
* @param id [string]: unique id returned when the log is created. ex: '5656565656565656'
* @param created [string]: creation datetime for the log. ex: '2020-03-10 10:30:00.000'
* @param type [string]: type of the PixPullRequest event which triggered the log creation. Options: 'created', 'sent', 'scheduled', 'denied', 'success', 'canceling', 'canceled', 'expired'.
* @param errors [list of strings]: list of errors linked to this PixPullRequest event.
* @param request [PixPullRequest]: PixPullRequest entity to which the log refers to.
*
*/
constructor({
id = null, created = null, type = null, errors = null, request = null
}) {
super(id);
this.created = check.datetime(created);
this.type = type;
this.errors = errors;
this.request = request;
}
}
exports.Log = Log;
let resource = {'class': exports.Log, 'name': 'PixPullRequestLog'};
exports.get = async function (id, {user} = {}) {
return rest.getId(resource, id, user);
};
exports.query = async function ({limit, after, before, types, ids, requestIds, user} = {}) {
/**
*
* Retrieve PixPullRequest Logs
*
* @description Receive a generator of PixPullRequest Log objects previously created in the Stark Infra API
*
* Parameters (optional):
* @param limit [integer, default null]: maximum number of objects to be retrieved. ex: 35
* @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-03-10'
* @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-03-10'
* @param types [list of strings, default null]: filter retrieved objects by types. ex: ['created', 'sent', 'success']
* @param ids [list of strings, default null]: list of PixPullRequest.Log ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
* @param requestIds [list of strings, default null]: list of PixPullRequest ids to filter retrieved objects. ex: ['5859939668983808', '4545454545454545']
* @param user [Organization/Project object, default null]: Organization or Project object. Not necessary if starkinfra.user was set before function call
*
* Return:
* @returns list of PixPullRequest Log objects with updated attributes
*
*/
let query = {
limit: limit,
after: after,
before: before,
types: types,
ids: ids,
requestIds: requestIds,
};
return rest.getList(resource, query, user);
};
exports.page = async function ({cursor, limit, after, before, types, ids, requestIds, user} = {}) {
/**
*
* Retrieve paged PixPullRequest Logs
*
* @description Receive a list of up to 100 PixPullRequest.Log objects previously created in the Stark Infra API and the cursor to the next page.
*
* Parameters (optional):
* @param cursor [string, default null]: cursor returned on the previous page function call. ex: 'bf85ddf6-7d1e-4f0a-9c0a-1d2e3f4a5b6c'
* @param limit [integer, default 100]: maximum number of objects to be retrieved. ex: 35
* @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-03-10'
* @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-03-10'
* @param types [list of strings, default null]: filter retrieved objects by types. ex: ['created', 'sent', 'success']
* @param ids [list of strings, default null]: list of PixPullRequest.Log ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
* @param requestIds [list of strings, default null]: list of PixPullRequest ids to filter retrieved objects. ex: ['5859939668983808', '4545454545454545']
* @param user [Organization/Project object, default null]: Organization or Project object. Not necessary if starkinfra.user was set before function call
*
* Return:
* @returns list of PixPullRequest Log objects with updated attributes and cursor to retrieve the next page
*
*/
let query = {
cursor: cursor,
limit: limit,
after: after,
before: before,
types: types,
ids: ids,
requestIds: requestIds,
};
return rest.getPage(resource, query, user);
};