Built motion from commit e1760111.|2.6.18
[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 _0x9dc1=['debug','stringify','error','message','Interval','find','where','ShowInterval','catch','all','ifTime','reduce','format','name','findById','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','intervalIds','intervals','string','timezone','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','join','Iftime','silly','resolve','isArray','../../mysqldb','../../utils/iftime','iftime','../../config/logger','rpc','GetInterval','findAll','options','raw','map','include','model','attributes','then','info'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x9dc1,0xed));var _0x19dc=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x9dc1[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var util=require('util');var db=require(_0x19dc('0x0'))['db'];var iftime=require(_0x19dc('0x1'))[_0x19dc('0x2')];var logger=require(_0x19dc('0x3'))(_0x19dc('0x4'));exports[_0x19dc('0x5')]=function(_0x357d0d){var _0x379e3b=this;return new Promise(function(_0x1c6f2f,_0x247682){return db['Interval'][_0x19dc('0x6')]({'raw':_0x357d0d[_0x19dc('0x7')]?_0x357d0d[_0x19dc('0x7')][_0x19dc('0x8')]===undefined?!![]:![]:!![],'where':_0x357d0d[_0x19dc('0x7')]?_0x357d0d['options']['where']||null:null,'attributes':_0x357d0d[_0x19dc('0x7')]?_0x357d0d[_0x19dc('0x7')]['attributes']||null:null,'limit':_0x357d0d['options']?_0x357d0d['options']['limit']||null:null,'include':_0x357d0d[_0x19dc('0x7')]?_0x357d0d[_0x19dc('0x7')]['include']?_[_0x19dc('0x9')](_0x357d0d['options'][_0x19dc('0xa')],function(_0x57695c){return{'model':db[_0x57695c[_0x19dc('0xb')]],'as':_0x57695c['as'],'attributes':_0x57695c[_0x19dc('0xc')],'include':_0x57695c[_0x19dc('0xa')]?_['map'](_0x57695c[_0x19dc('0xa')],function(_0x9353e5){return{'model':db[_0x9353e5['model']],'as':_0x9353e5['as'],'attributes':_0x9353e5['attributes'],'include':_0x9353e5[_0x19dc('0xa')]?_['map'](_0x9353e5[_0x19dc('0xa')],function(_0x432818){return{'model':db[_0x432818[_0x19dc('0xb')]],'as':_0x432818['as'],'attributes':_0x432818['attributes']};}):[]};}):[]};}):[]:[]})[_0x19dc('0xd')](function(_0xa41efb){logger[_0x19dc('0xe')]('GetInterval',_0x357d0d);logger[_0x19dc('0xf')](_0x19dc('0x5'),_0x357d0d,JSON[_0x19dc('0x10')](_0xa41efb));_0x1c6f2f(_0xa41efb);})['catch'](function(_0x3a76d9){logger[_0x19dc('0x11')](_0x19dc('0x5'),_0x3a76d9[_0x19dc('0x12')],_0x357d0d);_0x247682(_0x379e3b[_0x19dc('0x11')](0x1f4,_0x3a76d9[_0x19dc('0x12')]));});});};exports['ShowInterval']=function(_0x4007f2){var _0x3ceba7=this;return new Promise(function(_0x29b648,_0x4f1048){return db[_0x19dc('0x13')][_0x19dc('0x14')]({'raw':_0x4007f2[_0x19dc('0x7')]?_0x4007f2[_0x19dc('0x7')][_0x19dc('0x8')]===undefined?!![]:![]:!![],'where':_0x4007f2[_0x19dc('0x7')]?_0x4007f2[_0x19dc('0x7')][_0x19dc('0x15')]||null:null,'attributes':_0x4007f2[_0x19dc('0x7')]?_0x4007f2[_0x19dc('0x7')]['attributes']||null:null,'include':_0x4007f2[_0x19dc('0x7')]?_0x4007f2[_0x19dc('0x7')]['include']?_[_0x19dc('0x9')](_0x4007f2[_0x19dc('0x7')][_0x19dc('0xa')],function(_0x2aa8e4){return{'model':db[_0x2aa8e4[_0x19dc('0xb')]],'as':_0x2aa8e4['as'],'attributes':_0x2aa8e4[_0x19dc('0xc')],'include':_0x2aa8e4[_0x19dc('0xa')]?_[_0x19dc('0x9')](_0x2aa8e4['include'],function(_0x555400){return{'model':db[_0x555400['model']],'as':_0x555400['as'],'attributes':_0x555400['attributes'],'include':_0x555400['include']?_[_0x19dc('0x9')](_0x555400[_0x19dc('0xa')],function(_0x5e0da7){return{'model':db[_0x5e0da7[_0x19dc('0xb')]],'as':_0x5e0da7['as'],'attributes':_0x5e0da7['attributes']};}):[]};}):[]};}):[]:[]})[_0x19dc('0xd')](function(_0x2bf99b){logger['info']('ShowInterval',_0x4007f2);logger['debug'](_0x19dc('0x16'),_0x4007f2,JSON['stringify'](_0x2bf99b));_0x29b648(_0x2bf99b);})[_0x19dc('0x17')](function(_0x5e197b){logger[_0x19dc('0x11')](_0x19dc('0x16'),_0x5e197b[_0x19dc('0x12')],_0x4007f2);_0x4f1048(_0x3ceba7['error'](0x1f4,_0x5e197b[_0x19dc('0x12')]));});});};function checkArrayOfIntervals(_0x2bb295,_0x1cfa25){var _0x2b1c80=[];return db[_0x19dc('0x13')][_0x19dc('0x6')]({'where':{'id':_0x2bb295}})['then'](function(_0x13a805){_0x2b1c80=_0x13a805;return Promise[_0x19dc('0x18')](_0x2b1c80[_0x19dc('0x9')](function(_0x3f67c1){return _0x3f67c1[_0x19dc('0x19')](_0x1cfa25);}));})[_0x19dc('0xd')](function(_0x52200e){var _0x347441=_0x52200e[_0x19dc('0x1a')](function(_0x485793,_0x29488c){return _0x485793||_0x29488c;},![]);logger[_0x19dc('0xe')](util[_0x19dc('0x1b')]('IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)',_0x2b1c80['map'](function(_0x267ef8){return _0x267ef8[_0x19dc('0x1c')];})['join'](',\x20'),_0x2b1c80[_0x19dc('0x9')](function(_0x152aae){return _0x152aae['id'];})['join'](',\x20')));return _0x347441;});}function checkSingleInterval(_0xcfc5da,_0x269a9b){return db[_0x19dc('0x13')][_0x19dc('0x1d')](_0xcfc5da)[_0x19dc('0xd')](function(_0x57a1af){if(_0x57a1af){logger[_0x19dc('0xe')](util[_0x19dc('0x1b')](_0x19dc('0x1e'),_0x57a1af['name'],_0x57a1af['id']));return _0x57a1af['ifTime'](_0x269a9b);}});}exports['IntervalIftime']=function(_0x345154){var _0x18f3bc=_0x345154[_0x19dc('0x1f')];var _0x49e6d3=Array['isArray'](_0x345154[_0x19dc('0x20')])?_0x345154[_0x19dc('0x20')]:typeof _0x345154[_0x19dc('0x20')]===_0x19dc('0x21')?[_0x345154['intervals']]:[];var _0x74b1dc=_0x345154[_0x19dc('0x22')]||undefined;var _0x3b9783=![];if(_0x49e6d3[_0x19dc('0x23')]){logger['info'](util['format'](_0x19dc('0x24'),_0x49e6d3[_0x19dc('0x25')](';\x20')));}if(_0x74b1dc){logger[_0x19dc('0xe')](util[_0x19dc('0x1b')]('IntervalIftime:\x20timezone\x20=\x20%s',_0x74b1dc));}logger[_0x19dc('0xf')](_0x19dc('0x26'),_0x3b9783);logger[_0x19dc('0x27')]('IntervalIftime',_0x345154);return Promise[_0x19dc('0x28')]()[_0x19dc('0xd')](function(){if(Array[_0x19dc('0x29')](_0x18f3bc)){return checkArrayOfIntervals(_0x18f3bc,_0x74b1dc);}else if(_0x18f3bc){return checkSingleInterval(_0x18f3bc,_0x74b1dc);}})[_0x19dc('0xd')](function(_0x91c5a4){var _0x54f44c=_0x49e6d3['reduce'](function(_0x5ac8d1,_0x27a089){return _0x5ac8d1||iftime(_0x27a089,_0x74b1dc);},![]);_0x3b9783=_0x91c5a4||_0x54f44c;return _0x3b9783;})[_0x19dc('0x17')](function(_0x11f26a){logger[_0x19dc('0x11')]('IntervalIftime',_0x345154,_0x11f26a);throw this[_0x19dc('0x11')](0x1f4,_0x11f26a[_0x19dc('0x12')]);});};