UNPKG

starkbank

Version:

SDK to facilitate Node integrations with Stark Bank

131 lines (120 loc) 5.97 kB
const rest = require('../../utils/rest.js'); const check = require('starkcore').check; const Resource = require('../../utils/resource.js').Resource; class Log extends Resource { /** * * corporatepurchase.Log object * * @description Every time a CorporatePurchase entity is updated, a corresponding corporatepurchase.Log * is generated for the entity. This log is never generated by the * user, but it can be retrieved to check additional information * on the CorporatePurchase. * * Attributes (return-only): * @return id [string]: unique id returned when the log is created. ex: "5656565656565656" * @return purchase [CorporatePurchase]: CorporatePurchase entity to which the log refers to. * @return description [string]: purchase descriptions. ex: "my_description" * @return corporateTransactionId [string]: transaction ID related to the CorporateCard. * @return errors [list of StarkCore.Error]: list of errors linked to this CorporatePurchase event. * @return type [string]: type of the CorporatePurchase event which triggered the log creation. ex: "approved", "canceled", "confirmed", "denied", "reversed", "voided" * @return created [string] latest update datetime for the CorporatePurchase. ex: '2020-03-10 10:30:00.000' * */ constructor({ id, purchase, description, corporateTransactionId, errors, type, created }){ super(id); this.purchase = purchase; this.description = description; this.corporateTransactionId = corporateTransactionId; this.errors = errors; this.type = type; this.created = created; } } exports.Log = Log; let resource = {'class': exports.Log, 'name': 'corporatePurchaseLog'}; exports.get = async function (id, {user} = {}) { /** * * Retrieve a specific corporatepurchase.Log * * @description Receive a single corporatepurchase.Log object previously created by the Stark Bank API by its id * * Parameters (required): * @param id [string]: object unique id. ex: "5656565656565656" * * Parameters (optional): * @param user [Organization/Project object, default null]: Organization or Project object. Not necessary if starkbank.user was set before function call * * Return: * @return corporatepurchase.Log object with updated attributes * */ return rest.getId(resource, id, user); } exports.query = async function ({ids, limit, after, before, types, purchaseIds, user} = {}) { /** * * Retrieve corporatepurchase.Log * * @description Receive a generator of corporatepurchase.Log objects previously created in the Stark Bank API * * Parameters (optional): * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. 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 for log event types. ex: ["approved", "canceled", "confirmed", "denied", "reversed", "voided"] * @param purchaseIds [list of strings, default null]: list of Purchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] * @param ids [list of strings, default null]: list of CorporatePurchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] * @param user [Organization/Project object, default null]: Organization or Project object. Not necessary if starkbank.user was set before function call * * Return: * @return generator of corporatepurchase.Log objects with updated attributes * */ let query = { ids: ids, limit: limit, after: check.date(after), before: check.date(before), types: types, purchaseIds: purchaseIds, } return rest.getList(resource, query, user); } exports.page = async function ({cursor, ids, limit, after, before, types, purchaseIds, user} = {}) { /** * * Retrieve paged corporatepurchase.Log * * @description Receive a list of up to 100 corporatepurchase.Log objects previously created in the Stark Bank API and the cursor to the next page. * Use this function instead of query if you want to manually page your requests. * * Parameters (optional): * @param cursor [string, default null]: cursor returned on the previous page function call * @param limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. 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 for log event types. ex: ["approved", "canceled", "confirmed", "denied", "reversed", "voided"] * @param purchaseIds [list of strings, default null]: list of Purchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] * @param ids [list of strings, default null]: list of CorporatePurchase ids to filter logs. ex: ["5656565656565656", "4545454545454545"] * @param user [Organization/Project object, default null]: Organization or Project object. Not necessary if starkbank.user was set before function call * * Return: * @return list of corporatepurchase.Log objects with updated attributes * @return cursor to retrieve the next page of corporatepurchase.Log objects * */ let query = { cursor: cursor, ids: ids, limit: limit, after: after, before: before, types: types, purchaseIds: purchaseIds, } return rest.getPage(resource, query, user); }