trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
38 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformToEventInstance = transformToEventInstance;
const lodash_1 = require("lodash");
const entities_1 = require("../index.js");
const _utilities_1 = require("../../../utilities");
/**
* map of event types to event classes
*/
const eventTypeMap = {
OutrightScore: entities_1.OutrightScoreEvent,
OutrightFixture: entities_1.OutrightFixtureEvent,
Markets: entities_1.MarketEvent,
OutrightLeague: entities_1.OutrightLeagueFixtureEvent,
};
/**
* get the event class based on the object properties
* @param obj the object to be checked
* @returns the event class
*/
function getEventClass(obj) {
const eventType = (0, lodash_1.find)((0, lodash_1.keys)(eventTypeMap), (key) => (0, lodash_1.has)(obj, key) && !(0, lodash_1.isNil)(obj[key]));
return eventTypeMap[eventType];
}
/**
* tranform to event instance array by checking the type of the event
* @param value the value to be transformed to event instance array
* @returns event instance array
*/
function transformToEventInstance(value) {
if (!(0, lodash_1.isArray)(value) || ((0, lodash_1.isArray)(value) && (0, lodash_1.isEmpty)(value)))
return value;
const propertyEventClass = getEventClass(value[0]);
if (!(0, lodash_1.isNil)(propertyEventClass))
return _utilities_1.TransformerUtil.transformArray(value, propertyEventClass);
return value;
}
//# sourceMappingURL=transform-event-instance.js.map