Built motion from commit 3c2ce842.|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 _0x8272=['GetInterval','Interval','options','where','attributes','limit','include','map','model','then','info','stringify','catch','error','message','ShowInterval','find','raw','debug','findAll','all','ifTime','reduce','name','join','findById','format','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','intervalIds','isArray','intervals','string','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','IntervalIftime:\x20timezone\x20=\x20%s','Iftime','silly','IntervalIftime','resolve','util','../../mysqldb','../../utils/iftime','iftime','../../config/logger','rpc'];(function(_0x4e2596,_0x1ff134){var _0x3804de=function(_0x3cba73){while(--_0x3cba73){_0x4e2596['push'](_0x4e2596['shift']());}};_0x3804de(++_0x1ff134);}(_0x8272,0xdb));var _0x2827=function(_0x3e1294,_0x41791a){_0x3e1294=_0x3e1294-0x0;var _0x3bbca2=_0x8272[_0x3e1294];return _0x3bbca2;};'use strict';var _=require('lodash');var util=require(_0x2827('0x0'));var db=require(_0x2827('0x1'))['db'];var iftime=require(_0x2827('0x2'))[_0x2827('0x3')];var logger=require(_0x2827('0x4'))(_0x2827('0x5'));exports[_0x2827('0x6')]=function(_0x149520){var _0x276165=this;return new Promise(function(_0x21d70b,_0x273697){return db[_0x2827('0x7')]['findAll']({'raw':_0x149520['options']?_0x149520[_0x2827('0x8')]['raw']===undefined?!![]:![]:!![],'where':_0x149520[_0x2827('0x8')]?_0x149520[_0x2827('0x8')][_0x2827('0x9')]||null:null,'attributes':_0x149520[_0x2827('0x8')]?_0x149520[_0x2827('0x8')][_0x2827('0xa')]||null:null,'limit':_0x149520[_0x2827('0x8')]?_0x149520[_0x2827('0x8')][_0x2827('0xb')]||null:null,'include':_0x149520['options']?_0x149520[_0x2827('0x8')][_0x2827('0xc')]?_[_0x2827('0xd')](_0x149520[_0x2827('0x8')][_0x2827('0xc')],function(_0x256345){return{'model':db[_0x256345[_0x2827('0xe')]],'as':_0x256345['as'],'attributes':_0x256345[_0x2827('0xa')],'include':_0x256345[_0x2827('0xc')]?_[_0x2827('0xd')](_0x256345[_0x2827('0xc')],function(_0x173ee4){return{'model':db[_0x173ee4[_0x2827('0xe')]],'as':_0x173ee4['as'],'attributes':_0x173ee4[_0x2827('0xa')],'include':_0x173ee4['include']?_[_0x2827('0xd')](_0x173ee4['include'],function(_0x324e98){return{'model':db[_0x324e98[_0x2827('0xe')]],'as':_0x324e98['as'],'attributes':_0x324e98[_0x2827('0xa')]};}):[]};}):[]};}):[]:[]})[_0x2827('0xf')](function(_0x40c109){logger[_0x2827('0x10')]('GetInterval',_0x149520);logger['debug']('GetInterval',_0x149520,JSON[_0x2827('0x11')](_0x40c109));_0x21d70b(_0x40c109);})[_0x2827('0x12')](function(_0x92e0cb){logger[_0x2827('0x13')](_0x2827('0x6'),_0x92e0cb['message'],_0x149520);_0x273697(_0x276165[_0x2827('0x13')](0x1f4,_0x92e0cb[_0x2827('0x14')]));});});};exports[_0x2827('0x15')]=function(_0x546a2c){var _0x1b4828=this;return new Promise(function(_0x3496e3,_0x4cce70){return db[_0x2827('0x7')][_0x2827('0x16')]({'raw':_0x546a2c[_0x2827('0x8')]?_0x546a2c[_0x2827('0x8')][_0x2827('0x17')]===undefined?!![]:![]:!![],'where':_0x546a2c['options']?_0x546a2c[_0x2827('0x8')][_0x2827('0x9')]||null:null,'attributes':_0x546a2c[_0x2827('0x8')]?_0x546a2c['options'][_0x2827('0xa')]||null:null,'include':_0x546a2c['options']?_0x546a2c[_0x2827('0x8')][_0x2827('0xc')]?_[_0x2827('0xd')](_0x546a2c[_0x2827('0x8')][_0x2827('0xc')],function(_0x359cd6){return{'model':db[_0x359cd6[_0x2827('0xe')]],'as':_0x359cd6['as'],'attributes':_0x359cd6[_0x2827('0xa')],'include':_0x359cd6[_0x2827('0xc')]?_[_0x2827('0xd')](_0x359cd6['include'],function(_0x2bbfae){return{'model':db[_0x2bbfae['model']],'as':_0x2bbfae['as'],'attributes':_0x2bbfae['attributes'],'include':_0x2bbfae[_0x2827('0xc')]?_[_0x2827('0xd')](_0x2bbfae[_0x2827('0xc')],function(_0x2848bf){return{'model':db[_0x2848bf['model']],'as':_0x2848bf['as'],'attributes':_0x2848bf['attributes']};}):[]};}):[]};}):[]:[]})[_0x2827('0xf')](function(_0x47023a){logger[_0x2827('0x10')](_0x2827('0x15'),_0x546a2c);logger[_0x2827('0x18')](_0x2827('0x15'),_0x546a2c,JSON['stringify'](_0x47023a));_0x3496e3(_0x47023a);})[_0x2827('0x12')](function(_0xd5e7f0){logger[_0x2827('0x13')](_0x2827('0x15'),_0xd5e7f0[_0x2827('0x14')],_0x546a2c);_0x4cce70(_0x1b4828[_0x2827('0x13')](0x1f4,_0xd5e7f0[_0x2827('0x14')]));});});};function checkArrayOfIntervals(_0xabae98,_0x2979d4){var _0x2e12f3=[];return db['Interval'][_0x2827('0x19')]({'where':{'id':_0xabae98}})[_0x2827('0xf')](function(_0x3cb61c){_0x2e12f3=_0x3cb61c;return Promise[_0x2827('0x1a')](_0x2e12f3['map'](function(_0x4c68cc){return _0x4c68cc[_0x2827('0x1b')](_0x2979d4);}));})[_0x2827('0xf')](function(_0x2955ce){var _0x19096e=_0x2955ce[_0x2827('0x1c')](function(_0x325dfa,_0x5831f3){return _0x325dfa||_0x5831f3;},![]);logger['info'](util['format']('IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)',_0x2e12f3[_0x2827('0xd')](function(_0x251fa4){return _0x251fa4[_0x2827('0x1d')];})[_0x2827('0x1e')](',\x20'),_0x2e12f3[_0x2827('0xd')](function(_0x520386){return _0x520386['id'];})['join'](',\x20')));return _0x19096e;});}function checkSingleInterval(_0x3e9fcf,_0x4b272e){return db['Interval'][_0x2827('0x1f')](_0x3e9fcf)['then'](function(_0x3b1c5d){if(_0x3b1c5d){logger['info'](util[_0x2827('0x20')](_0x2827('0x21'),_0x3b1c5d['name'],_0x3b1c5d['id']));return _0x3b1c5d[_0x2827('0x1b')](_0x4b272e);}});}exports['IntervalIftime']=function(_0x4d1c13){var _0x474de8=_0x4d1c13[_0x2827('0x22')];var _0x45f691=Array[_0x2827('0x23')](_0x4d1c13[_0x2827('0x24')])?_0x4d1c13[_0x2827('0x24')]:typeof _0x4d1c13['intervals']===_0x2827('0x25')?[_0x4d1c13[_0x2827('0x24')]]:[];var _0x27356c=_0x4d1c13['timezone']||undefined;var _0x4d02dc=![];if(_0x45f691[_0x2827('0x26')]){logger['info'](util[_0x2827('0x20')](_0x2827('0x27'),_0x45f691[_0x2827('0x1e')](';\x20')));}if(_0x27356c){logger[_0x2827('0x10')](util[_0x2827('0x20')](_0x2827('0x28'),_0x27356c));}logger[_0x2827('0x18')](_0x2827('0x29'),_0x4d02dc);logger[_0x2827('0x2a')](_0x2827('0x2b'),_0x4d1c13);return Promise[_0x2827('0x2c')]()[_0x2827('0xf')](function(){if(Array['isArray'](_0x474de8)){return checkArrayOfIntervals(_0x474de8,_0x27356c);}else if(_0x474de8){return checkSingleInterval(_0x474de8,_0x27356c);}})['then'](function(_0x3efd1c){var _0x4f0ac5=_0x45f691[_0x2827('0x1c')](function(_0x5d81c1,_0x399d3c){return _0x5d81c1||iftime(_0x399d3c,_0x27356c);},![]);_0x4d02dc=_0x3efd1c||_0x4f0ac5;return _0x4d02dc;})['catch'](function(_0x2f30c8){logger[_0x2827('0x13')](_0x2827('0x2b'),_0x4d1c13,_0x2f30c8);throw this[_0x2827('0x13')](0x1f4,_0x2f30c8[_0x2827('0x14')]);});};