Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / api / interval / interval.rpc.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x1ce1=['limit','include','model','attributes','map','then','info','debug','catch','error','message','ShowInterval','stringify','all','ifTime','reduce','format','IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)','name','join','findById','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','IntervalIftime','intervalIds','intervals','string','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','Iftime','silly','isArray','lodash','util','../../mysqldb','../../config/logger','rpc','GetInterval','Interval','findAll','options','raw','where'];(function(_0x1f4c09,_0x75df9d){var _0x564684=function(_0x30bb1f){while(--_0x30bb1f){_0x1f4c09['push'](_0x1f4c09['shift']());}};_0x564684(++_0x75df9d);}(_0x1ce1,0x1ed));var _0x11ce=function(_0x5ecdb0,_0x507e96){_0x5ecdb0=_0x5ecdb0-0x0;var _0x2a1652=_0x1ce1[_0x5ecdb0];return _0x2a1652;};'use strict';var _=require(_0x11ce('0x0'));var util=require(_0x11ce('0x1'));var db=require(_0x11ce('0x2'))['db'];var iftime=require('../../utils/iftime')['iftime'];var logger=require(_0x11ce('0x3'))(_0x11ce('0x4'));exports[_0x11ce('0x5')]=function(_0x5e17e9){var _0x4aa679=this;return new Promise(function(_0x2d059b,_0x3402ad){return db[_0x11ce('0x6')][_0x11ce('0x7')]({'raw':_0x5e17e9[_0x11ce('0x8')]?_0x5e17e9[_0x11ce('0x8')][_0x11ce('0x9')]===undefined?!![]:![]:!![],'where':_0x5e17e9[_0x11ce('0x8')]?_0x5e17e9['options'][_0x11ce('0xa')]||null:null,'attributes':_0x5e17e9[_0x11ce('0x8')]?_0x5e17e9[_0x11ce('0x8')]['attributes']||null:null,'limit':_0x5e17e9[_0x11ce('0x8')]?_0x5e17e9[_0x11ce('0x8')][_0x11ce('0xb')]||null:null,'include':_0x5e17e9['options']?_0x5e17e9[_0x11ce('0x8')][_0x11ce('0xc')]?_['map'](_0x5e17e9[_0x11ce('0x8')][_0x11ce('0xc')],function(_0x3701e5){return{'model':db[_0x3701e5[_0x11ce('0xd')]],'as':_0x3701e5['as'],'attributes':_0x3701e5[_0x11ce('0xe')],'include':_0x3701e5[_0x11ce('0xc')]?_[_0x11ce('0xf')](_0x3701e5[_0x11ce('0xc')],function(_0x5619c8){return{'model':db[_0x5619c8[_0x11ce('0xd')]],'as':_0x5619c8['as'],'attributes':_0x5619c8['attributes'],'include':_0x5619c8[_0x11ce('0xc')]?_[_0x11ce('0xf')](_0x5619c8[_0x11ce('0xc')],function(_0x40a8c7){return{'model':db[_0x40a8c7[_0x11ce('0xd')]],'as':_0x40a8c7['as'],'attributes':_0x40a8c7[_0x11ce('0xe')]};}):[]};}):[]};}):[]:[]})[_0x11ce('0x10')](function(_0x10b946){logger[_0x11ce('0x11')](_0x11ce('0x5'),_0x5e17e9);logger[_0x11ce('0x12')](_0x11ce('0x5'),_0x5e17e9,JSON['stringify'](_0x10b946));_0x2d059b(_0x10b946);})[_0x11ce('0x13')](function(_0x394f68){logger[_0x11ce('0x14')](_0x11ce('0x5'),_0x394f68['message'],_0x5e17e9);_0x3402ad(_0x4aa679[_0x11ce('0x14')](0x1f4,_0x394f68[_0x11ce('0x15')]));});});};exports[_0x11ce('0x16')]=function(_0x3668a7){var _0x1213f0=this;return new Promise(function(_0x13777f,_0x5a4a03){return db[_0x11ce('0x6')]['find']({'raw':_0x3668a7[_0x11ce('0x8')]?_0x3668a7[_0x11ce('0x8')][_0x11ce('0x9')]===undefined?!![]:![]:!![],'where':_0x3668a7['options']?_0x3668a7[_0x11ce('0x8')][_0x11ce('0xa')]||null:null,'attributes':_0x3668a7[_0x11ce('0x8')]?_0x3668a7[_0x11ce('0x8')][_0x11ce('0xe')]||null:null,'include':_0x3668a7[_0x11ce('0x8')]?_0x3668a7[_0x11ce('0x8')][_0x11ce('0xc')]?_['map'](_0x3668a7[_0x11ce('0x8')][_0x11ce('0xc')],function(_0x4f030e){return{'model':db[_0x4f030e['model']],'as':_0x4f030e['as'],'attributes':_0x4f030e[_0x11ce('0xe')],'include':_0x4f030e[_0x11ce('0xc')]?_[_0x11ce('0xf')](_0x4f030e[_0x11ce('0xc')],function(_0x2c1c16){return{'model':db[_0x2c1c16['model']],'as':_0x2c1c16['as'],'attributes':_0x2c1c16['attributes'],'include':_0x2c1c16[_0x11ce('0xc')]?_[_0x11ce('0xf')](_0x2c1c16[_0x11ce('0xc')],function(_0x4adaf6){return{'model':db[_0x4adaf6[_0x11ce('0xd')]],'as':_0x4adaf6['as'],'attributes':_0x4adaf6[_0x11ce('0xe')]};}):[]};}):[]};}):[]:[]})[_0x11ce('0x10')](function(_0x30370b){logger[_0x11ce('0x11')](_0x11ce('0x16'),_0x3668a7);logger[_0x11ce('0x12')](_0x11ce('0x16'),_0x3668a7,JSON[_0x11ce('0x17')](_0x30370b));_0x13777f(_0x30370b);})[_0x11ce('0x13')](function(_0x434b5d){logger[_0x11ce('0x14')](_0x11ce('0x16'),_0x434b5d['message'],_0x3668a7);_0x5a4a03(_0x1213f0[_0x11ce('0x14')](0x1f4,_0x434b5d[_0x11ce('0x15')]));});});};function checkArrayOfIntervals(_0x3fce8a,_0xc64b2d){var _0x389d0d=[];return db['Interval'][_0x11ce('0x7')]({'where':{'id':_0x3fce8a}})[_0x11ce('0x10')](function(_0x441778){_0x389d0d=_0x441778;return Promise[_0x11ce('0x18')](_0x389d0d['map'](function(_0x24b201){return _0x24b201[_0x11ce('0x19')](_0xc64b2d);}));})['then'](function(_0x56320e){var _0x1715ba=_0x56320e[_0x11ce('0x1a')](function(_0x35b47f,_0x4fbcf0){return _0x35b47f||_0x4fbcf0;},![]);logger[_0x11ce('0x11')](util[_0x11ce('0x1b')](_0x11ce('0x1c'),_0x389d0d[_0x11ce('0xf')](function(_0x47fade){return _0x47fade[_0x11ce('0x1d')];})['join'](',\x20'),_0x389d0d[_0x11ce('0xf')](function(_0x5485d5){return _0x5485d5['id'];})[_0x11ce('0x1e')](',\x20')));return _0x1715ba;});}function checkSingleInterval(_0x1d346a,_0x482c70){return db[_0x11ce('0x6')][_0x11ce('0x1f')](_0x1d346a)[_0x11ce('0x10')](function(_0x1b1698){if(_0x1b1698){logger[_0x11ce('0x11')](util[_0x11ce('0x1b')](_0x11ce('0x20'),_0x1b1698[_0x11ce('0x1d')],_0x1b1698['id']));return _0x1b1698[_0x11ce('0x19')](_0x482c70);}});}exports[_0x11ce('0x21')]=function(_0x119c82){var _0x4fa05b=_0x119c82[_0x11ce('0x22')];var _0x23a143=Array['isArray'](_0x119c82['intervals'])?_0x119c82[_0x11ce('0x23')]:typeof _0x119c82['intervals']===_0x11ce('0x24')?[_0x119c82[_0x11ce('0x23')]]:[];var _0x314724=_0x119c82['timezone']||undefined;var _0x271406=![];if(_0x23a143[_0x11ce('0x25')]){logger[_0x11ce('0x11')](util[_0x11ce('0x1b')](_0x11ce('0x26'),_0x23a143[_0x11ce('0x1e')](';\x20')));}if(_0x314724){logger[_0x11ce('0x11')](util[_0x11ce('0x1b')]('IntervalIftime:\x20timezone\x20=\x20%s',_0x314724));}logger[_0x11ce('0x12')](_0x11ce('0x27'),_0x271406);logger[_0x11ce('0x28')](_0x11ce('0x21'),_0x119c82);return Promise['resolve']()['then'](function(){if(Array[_0x11ce('0x29')](_0x4fa05b)){return checkArrayOfIntervals(_0x4fa05b,_0x314724);}else if(_0x4fa05b){return checkSingleInterval(_0x4fa05b,_0x314724);}})[_0x11ce('0x10')](function(_0x582c3b){var _0x360379=_0x23a143[_0x11ce('0x1a')](function(_0x1325ed,_0x399ecb){return _0x1325ed||iftime(_0x399ecb,_0x314724);},![]);_0x271406=_0x582c3b||_0x360379;return _0x271406;})['catch'](function(_0x51cdb4){logger[_0x11ce('0x14')](_0x11ce('0x21'),_0x119c82,_0x51cdb4);throw this['error'](0x1f4,_0x51cdb4[_0x11ce('0x15')]);});};