Built motion from commit 8c034dcd.|2.6.31
[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 _0x5988=['../../config/logger','rpc','GetInterval','Interval','findAll','options','raw','where','attributes','limit','include','model','map','then','info','debug','stringify','error','message','ShowInterval','find','all','ifTime','reduce','format','name','join','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','IntervalIftime','isArray','intervals','string','timezone','length','Iftime','silly','resolve','catch','lodash','util','../../utils/iftime','iftime'];(function(_0x2a1077,_0x34901b){var _0x40b180=function(_0xe3dc65){while(--_0xe3dc65){_0x2a1077['push'](_0x2a1077['shift']());}};_0x40b180(++_0x34901b);}(_0x5988,0xce));var _0x8598=function(_0x186376,_0x5d988a){_0x186376=_0x186376-0x0;var _0x2dbdd9=_0x5988[_0x186376];return _0x2dbdd9;};'use strict';var _=require(_0x8598('0x0'));var util=require(_0x8598('0x1'));var db=require('../../mysqldb')['db'];var iftime=require(_0x8598('0x2'))[_0x8598('0x3')];var logger=require(_0x8598('0x4'))(_0x8598('0x5'));exports[_0x8598('0x6')]=function(_0x2ed841){var _0x56eee6=this;return new Promise(function(_0x336848,_0x41d4d2){return db[_0x8598('0x7')][_0x8598('0x8')]({'raw':_0x2ed841[_0x8598('0x9')]?_0x2ed841[_0x8598('0x9')][_0x8598('0xa')]===undefined?!![]:![]:!![],'where':_0x2ed841[_0x8598('0x9')]?_0x2ed841[_0x8598('0x9')][_0x8598('0xb')]||null:null,'attributes':_0x2ed841['options']?_0x2ed841[_0x8598('0x9')][_0x8598('0xc')]||null:null,'limit':_0x2ed841[_0x8598('0x9')]?_0x2ed841[_0x8598('0x9')][_0x8598('0xd')]||null:null,'include':_0x2ed841[_0x8598('0x9')]?_0x2ed841['options'][_0x8598('0xe')]?_['map'](_0x2ed841[_0x8598('0x9')][_0x8598('0xe')],function(_0x819cf8){return{'model':db[_0x819cf8['model']],'as':_0x819cf8['as'],'attributes':_0x819cf8['attributes'],'include':_0x819cf8[_0x8598('0xe')]?_['map'](_0x819cf8[_0x8598('0xe')],function(_0x4048bf){return{'model':db[_0x4048bf[_0x8598('0xf')]],'as':_0x4048bf['as'],'attributes':_0x4048bf[_0x8598('0xc')],'include':_0x4048bf['include']?_[_0x8598('0x10')](_0x4048bf[_0x8598('0xe')],function(_0x2c93d7){return{'model':db[_0x2c93d7['model']],'as':_0x2c93d7['as'],'attributes':_0x2c93d7[_0x8598('0xc')]};}):[]};}):[]};}):[]:[]})[_0x8598('0x11')](function(_0x5e6c81){logger[_0x8598('0x12')](_0x8598('0x6'),_0x2ed841);logger[_0x8598('0x13')](_0x8598('0x6'),_0x2ed841,JSON[_0x8598('0x14')](_0x5e6c81));_0x336848(_0x5e6c81);})['catch'](function(_0x3a8b29){logger[_0x8598('0x15')]('GetInterval',_0x3a8b29[_0x8598('0x16')],_0x2ed841);_0x41d4d2(_0x56eee6[_0x8598('0x15')](0x1f4,_0x3a8b29[_0x8598('0x16')]));});});};exports[_0x8598('0x17')]=function(_0x5557f0){var _0x363c08=this;return new Promise(function(_0xb49ecd,_0x1319b0){return db['Interval'][_0x8598('0x18')]({'raw':_0x5557f0['options']?_0x5557f0['options']['raw']===undefined?!![]:![]:!![],'where':_0x5557f0[_0x8598('0x9')]?_0x5557f0[_0x8598('0x9')][_0x8598('0xb')]||null:null,'attributes':_0x5557f0[_0x8598('0x9')]?_0x5557f0[_0x8598('0x9')][_0x8598('0xc')]||null:null,'include':_0x5557f0[_0x8598('0x9')]?_0x5557f0[_0x8598('0x9')][_0x8598('0xe')]?_[_0x8598('0x10')](_0x5557f0['options']['include'],function(_0x140912){return{'model':db[_0x140912[_0x8598('0xf')]],'as':_0x140912['as'],'attributes':_0x140912['attributes'],'include':_0x140912[_0x8598('0xe')]?_[_0x8598('0x10')](_0x140912[_0x8598('0xe')],function(_0x438941){return{'model':db[_0x438941[_0x8598('0xf')]],'as':_0x438941['as'],'attributes':_0x438941[_0x8598('0xc')],'include':_0x438941[_0x8598('0xe')]?_[_0x8598('0x10')](_0x438941[_0x8598('0xe')],function(_0x3fb3f3){return{'model':db[_0x3fb3f3[_0x8598('0xf')]],'as':_0x3fb3f3['as'],'attributes':_0x3fb3f3[_0x8598('0xc')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x28fedd){logger['info'](_0x8598('0x17'),_0x5557f0);logger[_0x8598('0x13')](_0x8598('0x17'),_0x5557f0,JSON[_0x8598('0x14')](_0x28fedd));_0xb49ecd(_0x28fedd);})['catch'](function(_0x57da5b){logger[_0x8598('0x15')]('ShowInterval',_0x57da5b[_0x8598('0x16')],_0x5557f0);_0x1319b0(_0x363c08[_0x8598('0x15')](0x1f4,_0x57da5b[_0x8598('0x16')]));});});};function checkArrayOfIntervals(_0x4bd78e,_0x193e41){var _0x16640f=[];return db[_0x8598('0x7')][_0x8598('0x8')]({'where':{'id':_0x4bd78e}})[_0x8598('0x11')](function(_0x4a317d){_0x16640f=_0x4a317d;return Promise[_0x8598('0x19')](_0x16640f[_0x8598('0x10')](function(_0x562229){return _0x562229[_0x8598('0x1a')](_0x193e41);}));})[_0x8598('0x11')](function(_0xcaa4e5){var _0x128076=_0xcaa4e5[_0x8598('0x1b')](function(_0x236c5d,_0xad551c){return _0x236c5d||_0xad551c;},![]);logger[_0x8598('0x12')](util[_0x8598('0x1c')]('IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)',_0x16640f['map'](function(_0x3c9fd0){return _0x3c9fd0[_0x8598('0x1d')];})[_0x8598('0x1e')](',\x20'),_0x16640f[_0x8598('0x10')](function(_0x1f2221){return _0x1f2221['id'];})[_0x8598('0x1e')](',\x20')));return _0x128076;});}function checkSingleInterval(_0x3614de,_0x59fed3){return db[_0x8598('0x7')]['findById'](_0x3614de)[_0x8598('0x11')](function(_0x44fda7){if(_0x44fda7){logger[_0x8598('0x12')](util[_0x8598('0x1c')](_0x8598('0x1f'),_0x44fda7[_0x8598('0x1d')],_0x44fda7['id']));return _0x44fda7['ifTime'](_0x59fed3);}});}exports[_0x8598('0x20')]=function(_0x14be44){var _0x51398a=_0x14be44['intervalIds'];var _0x322252=Array[_0x8598('0x21')](_0x14be44[_0x8598('0x22')])?_0x14be44[_0x8598('0x22')]:typeof _0x14be44[_0x8598('0x22')]===_0x8598('0x23')?[_0x14be44[_0x8598('0x22')]]:[];var _0x4c63be=_0x14be44[_0x8598('0x24')]||undefined;var _0x13ddc5=![];if(_0x322252[_0x8598('0x25')]){logger[_0x8598('0x12')](util[_0x8598('0x1c')]('IntervalIftime:\x20interval\x20strings\x20=\x20%s',_0x322252['join'](';\x20')));}if(_0x4c63be){logger[_0x8598('0x12')](util['format']('IntervalIftime:\x20timezone\x20=\x20%s',_0x4c63be));}logger[_0x8598('0x13')](_0x8598('0x26'),_0x13ddc5);logger[_0x8598('0x27')]('IntervalIftime',_0x14be44);return Promise[_0x8598('0x28')]()[_0x8598('0x11')](function(){if(Array[_0x8598('0x21')](_0x51398a)){return checkArrayOfIntervals(_0x51398a,_0x4c63be);}else if(_0x51398a){return checkSingleInterval(_0x51398a,_0x4c63be);}})[_0x8598('0x11')](function(_0x28629f){var _0x312177=_0x322252[_0x8598('0x1b')](function(_0x5d0e9f,_0x4dde8c){return _0x5d0e9f||iftime(_0x4dde8c,_0x4c63be);},![]);_0x13ddc5=_0x28629f||_0x312177;return _0x13ddc5;})[_0x8598('0x29')](function(_0x123295){logger['error'](_0x8598('0x20'),_0x14be44,_0x123295);throw this[_0x8598('0x15')](0x1f4,_0x123295['message']);});};