starkinfra
Version:
SDK to facilitate Node integrations with Stark Infra
122 lines (114 loc) • 5.38 kB
JavaScript
const rest = require('../../utils/rest.js');
const check = require('starkcore').check;
const Resource = require('../../utils/resource.js').Resource
class Log extends Resource {
/**
*
* IssuingStock Log object
*
* @description Every time an IssuingStock entity is modified, a corresponding IssuingStock 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 stock [IssuingStock]: IssuingStock entity to which the log refers to.
* @param type [string]: type of the IssuingStock event which triggered the log creation. ex: "created", "spent", "restocked", "lost"
* @param count [integer]: shift in stock balance. ex: 10
* @param created [string]: creation datetime for the log. ex: '2020-03-10 10:30:00.000'
*
*/
constructor({
id=null, stock=null, type=null, count=null, created=null
}) {
super(id);
this.stock = stock;
this.type = type;
this.count = count;
this.created = check.datetime(created);
}
}
exports.Log = Log;
let resource = {'class': exports.Log, 'name': 'IssuingStockLog'};
exports.get = async function (id, { user } = {}) {
/**
*
* Retrieve a specific IssuingStock Log
*
* @description Receive a single IssuingStock Log object previously created by the Stark Infra API by passing its id
*
* Parameters (required):
* @param id [string]: object unique id. ex: '5656565656565656'
*
* Parameters (optional):
* @param user [Organization/Project object]: Organization or Project object. Not necessary if starkinfra.user was set before function call
*
* Return:
* @returns IssuingStock Log object with updated attributes
*
*/
return rest.getId(resource, id, user);
};
exports.query = async function ({ limit, ids, after, before, types, stockIds, user } = {}) {
/**
*
* Retrieve IssuingStock Logs
*
* @description Receive a generator of IssuingStock Log objects previously created in the Stark Infra API
*
* Parameters (optional):
* @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35
* @param ids [list of strings, default null]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
* @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", "spent", "restocked", "lost"]
* @param stockIds [list of strings, default []]: list of IssuingStock ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
* @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call
*
* Return:
* @returns list of IssuingStock Log objects with updated attributes
*
*/
let query = {
limit: limit,
ids: ids,
after: after,
before: before,
types: types,
stockIds: stockIds,
};
return rest.getList(resource, query, user);
};
exports.page = async function ({ cursor, limit, ids, after, before, types, stockIds, user } = {}) {
/**
*
* Retrieve paged IssuingStock Logs
*
* @description Receive a list of up to 100 IssuingStock.Log objects previously created in the Stark Infra API and the cursor to the next page.
* Use this function instead of query if you want to manually page your identities.
*
* 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. It must be an integer between 1 and 100. ex: 35
* @param ids [list of strings, default null]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
* @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", "spent", "restocked", "lost"]
* @param stockIds [list of strings, default []]: list of IssuingStock ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
* @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call
*
* Return:
* @returns list of IssuingStock Log objects with updated attributes and cursor to retrieve the next page of IssuingStock Log objects
*
*/
let query = {
cursor: cursor,
ids: ids,
limit: limit,
after: after,
before: before,
types: types,
stockIds: stockIds,
};
return rest.getPage(resource, query, user);
};