Built motion from commit b5996064.|2.6.21
[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 _0x28ff=['attributes','limit','include','map','model','then','info','stringify','catch','message','error','ShowInterval','find','debug','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)','intervalIds','isArray','intervals','timezone','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','IntervalIftime:\x20timezone\x20=\x20%s','silly','IntervalIftime','lodash','util','../../mysqldb','../../config/logger','GetInterval','Interval','findAll','options','raw','where'];(function(_0x3430aa,_0x57cd92){var _0x2ac5c=function(_0x3068dd){while(--_0x3068dd){_0x3430aa['push'](_0x3430aa['shift']());}};_0x2ac5c(++_0x57cd92);}(_0x28ff,0x11c));var _0xf28f=function(_0x3ab51d,_0x2fa01d){_0x3ab51d=_0x3ab51d-0x0;var _0x29a04e=_0x28ff[_0x3ab51d];return _0x29a04e;};'use strict';var _=require(_0xf28f('0x0'));var util=require(_0xf28f('0x1'));var db=require(_0xf28f('0x2'))['db'];var iftime=require('../../utils/iftime')['iftime'];var logger=require(_0xf28f('0x3'))('rpc');exports[_0xf28f('0x4')]=function(_0x4cdaae){var _0x3b4969=this;return new Promise(function(_0xee6cf8,_0x5a1614){return db[_0xf28f('0x5')][_0xf28f('0x6')]({'raw':_0x4cdaae[_0xf28f('0x7')]?_0x4cdaae[_0xf28f('0x7')][_0xf28f('0x8')]===undefined?!![]:![]:!![],'where':_0x4cdaae[_0xf28f('0x7')]?_0x4cdaae[_0xf28f('0x7')][_0xf28f('0x9')]||null:null,'attributes':_0x4cdaae[_0xf28f('0x7')]?_0x4cdaae[_0xf28f('0x7')][_0xf28f('0xa')]||null:null,'limit':_0x4cdaae[_0xf28f('0x7')]?_0x4cdaae['options'][_0xf28f('0xb')]||null:null,'include':_0x4cdaae[_0xf28f('0x7')]?_0x4cdaae[_0xf28f('0x7')][_0xf28f('0xc')]?_[_0xf28f('0xd')](_0x4cdaae[_0xf28f('0x7')][_0xf28f('0xc')],function(_0x2194ef){return{'model':db[_0x2194ef[_0xf28f('0xe')]],'as':_0x2194ef['as'],'attributes':_0x2194ef[_0xf28f('0xa')],'include':_0x2194ef['include']?_[_0xf28f('0xd')](_0x2194ef[_0xf28f('0xc')],function(_0x2e9c47){return{'model':db[_0x2e9c47[_0xf28f('0xe')]],'as':_0x2e9c47['as'],'attributes':_0x2e9c47['attributes'],'include':_0x2e9c47['include']?_['map'](_0x2e9c47[_0xf28f('0xc')],function(_0x3759bf){return{'model':db[_0x3759bf[_0xf28f('0xe')]],'as':_0x3759bf['as'],'attributes':_0x3759bf[_0xf28f('0xa')]};}):[]};}):[]};}):[]:[]})[_0xf28f('0xf')](function(_0x4d599b){logger[_0xf28f('0x10')](_0xf28f('0x4'),_0x4cdaae);logger['debug'](_0xf28f('0x4'),_0x4cdaae,JSON[_0xf28f('0x11')](_0x4d599b));_0xee6cf8(_0x4d599b);})[_0xf28f('0x12')](function(_0xa54bb8){logger['error']('GetInterval',_0xa54bb8[_0xf28f('0x13')],_0x4cdaae);_0x5a1614(_0x3b4969[_0xf28f('0x14')](0x1f4,_0xa54bb8['message']));});});};exports[_0xf28f('0x15')]=function(_0x2b0a17){var _0x2ebe40=this;return new Promise(function(_0x1c3ff1,_0xff83cb){return db[_0xf28f('0x5')][_0xf28f('0x16')]({'raw':_0x2b0a17[_0xf28f('0x7')]?_0x2b0a17['options'][_0xf28f('0x8')]===undefined?!![]:![]:!![],'where':_0x2b0a17[_0xf28f('0x7')]?_0x2b0a17[_0xf28f('0x7')][_0xf28f('0x9')]||null:null,'attributes':_0x2b0a17[_0xf28f('0x7')]?_0x2b0a17[_0xf28f('0x7')][_0xf28f('0xa')]||null:null,'include':_0x2b0a17[_0xf28f('0x7')]?_0x2b0a17[_0xf28f('0x7')][_0xf28f('0xc')]?_[_0xf28f('0xd')](_0x2b0a17[_0xf28f('0x7')][_0xf28f('0xc')],function(_0x3ad66e){return{'model':db[_0x3ad66e[_0xf28f('0xe')]],'as':_0x3ad66e['as'],'attributes':_0x3ad66e[_0xf28f('0xa')],'include':_0x3ad66e[_0xf28f('0xc')]?_[_0xf28f('0xd')](_0x3ad66e[_0xf28f('0xc')],function(_0x5642de){return{'model':db[_0x5642de[_0xf28f('0xe')]],'as':_0x5642de['as'],'attributes':_0x5642de[_0xf28f('0xa')],'include':_0x5642de['include']?_['map'](_0x5642de[_0xf28f('0xc')],function(_0x1b43b1){return{'model':db[_0x1b43b1[_0xf28f('0xe')]],'as':_0x1b43b1['as'],'attributes':_0x1b43b1[_0xf28f('0xa')]};}):[]};}):[]};}):[]:[]})[_0xf28f('0xf')](function(_0x2dea6a){logger[_0xf28f('0x10')](_0xf28f('0x15'),_0x2b0a17);logger[_0xf28f('0x17')](_0xf28f('0x15'),_0x2b0a17,JSON['stringify'](_0x2dea6a));_0x1c3ff1(_0x2dea6a);})[_0xf28f('0x12')](function(_0x4c6f82){logger['error'](_0xf28f('0x15'),_0x4c6f82[_0xf28f('0x13')],_0x2b0a17);_0xff83cb(_0x2ebe40[_0xf28f('0x14')](0x1f4,_0x4c6f82[_0xf28f('0x13')]));});});};function checkArrayOfIntervals(_0x168a88,_0x1c21d0){var _0xcd239c=[];return db[_0xf28f('0x5')][_0xf28f('0x6')]({'where':{'id':_0x168a88}})[_0xf28f('0xf')](function(_0x90c774){_0xcd239c=_0x90c774;return Promise[_0xf28f('0x18')](_0xcd239c[_0xf28f('0xd')](function(_0x1b13d2){return _0x1b13d2[_0xf28f('0x19')](_0x1c21d0);}));})[_0xf28f('0xf')](function(_0x12d311){var _0x584ddc=_0x12d311[_0xf28f('0x1a')](function(_0x1cebde,_0x3dd2aa){return _0x1cebde||_0x3dd2aa;},![]);logger[_0xf28f('0x10')](util[_0xf28f('0x1b')](_0xf28f('0x1c'),_0xcd239c['map'](function(_0x5c82f4){return _0x5c82f4[_0xf28f('0x1d')];})[_0xf28f('0x1e')](',\x20'),_0xcd239c[_0xf28f('0xd')](function(_0x50a9d1){return _0x50a9d1['id'];})['join'](',\x20')));return _0x584ddc;});}function checkSingleInterval(_0x431d7d,_0x4b2042){return db[_0xf28f('0x5')][_0xf28f('0x1f')](_0x431d7d)['then'](function(_0x3f2a13){if(_0x3f2a13){logger['info'](util['format'](_0xf28f('0x20'),_0x3f2a13[_0xf28f('0x1d')],_0x3f2a13['id']));return _0x3f2a13['ifTime'](_0x4b2042);}});}exports['IntervalIftime']=function(_0x1a0daf){var _0x526da3=_0x1a0daf[_0xf28f('0x21')];var _0x4d757b=Array[_0xf28f('0x22')](_0x1a0daf[_0xf28f('0x23')])?_0x1a0daf[_0xf28f('0x23')]:typeof _0x1a0daf[_0xf28f('0x23')]==='string'?[_0x1a0daf['intervals']]:[];var _0x18c103=_0x1a0daf[_0xf28f('0x24')]||undefined;var _0xb9a511=![];if(_0x4d757b[_0xf28f('0x25')]){logger[_0xf28f('0x10')](util['format'](_0xf28f('0x26'),_0x4d757b['join'](';\x20')));}if(_0x18c103){logger[_0xf28f('0x10')](util[_0xf28f('0x1b')](_0xf28f('0x27'),_0x18c103));}logger[_0xf28f('0x17')]('Iftime',_0xb9a511);logger[_0xf28f('0x28')](_0xf28f('0x29'),_0x1a0daf);return Promise['resolve']()[_0xf28f('0xf')](function(){if(Array[_0xf28f('0x22')](_0x526da3)){return checkArrayOfIntervals(_0x526da3,_0x18c103);}else if(_0x526da3){return checkSingleInterval(_0x526da3,_0x18c103);}})[_0xf28f('0xf')](function(_0x5ca5ba){var _0x259124=_0x4d757b['reduce'](function(_0x5a68d0,_0x271434){return _0x5a68d0||iftime(_0x271434,_0x18c103);},![]);_0xb9a511=_0x5ca5ba||_0x259124;return _0xb9a511;})[_0xf28f('0x12')](function(_0x4b8a77){logger[_0xf28f('0x14')](_0xf28f('0x29'),_0x1a0daf,_0x4b8a77);throw this[_0xf28f('0x14')](0x1f4,_0x4b8a77['message']);});};