Built motion from commit c738b9ac.|2.6.25
[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 _0x53f4=['reduce','IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)','name','join','findById','format','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','ifTime','isArray','intervals','timezone','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','IntervalIftime:\x20timezone\x20=\x20%s','Iftime','silly','IntervalIftime','resolve','lodash','util','../../mysqldb','../../utils/iftime','iftime','../../config/logger','rpc','GetInterval','Interval','findAll','options','raw','where','attributes','limit','include','model','map','then','info','debug','catch','message','error','find','ShowInterval','stringify','all'];(function(_0xe37814,_0x3f8f6a){var _0x3d7ebc=function(_0x5c1b42){while(--_0x5c1b42){_0xe37814['push'](_0xe37814['shift']());}};_0x3d7ebc(++_0x3f8f6a);}(_0x53f4,0x154));var _0x453f=function(_0x5b06c5,_0x2f3afe){_0x5b06c5=_0x5b06c5-0x0;var _0x247879=_0x53f4[_0x5b06c5];return _0x247879;};'use strict';var _=require(_0x453f('0x0'));var util=require(_0x453f('0x1'));var db=require(_0x453f('0x2'))['db'];var iftime=require(_0x453f('0x3'))[_0x453f('0x4')];var logger=require(_0x453f('0x5'))(_0x453f('0x6'));exports[_0x453f('0x7')]=function(_0x3eaa30){var _0x4f9656=this;return new Promise(function(_0x27d5e7,_0x273a0d){return db[_0x453f('0x8')][_0x453f('0x9')]({'raw':_0x3eaa30[_0x453f('0xa')]?_0x3eaa30[_0x453f('0xa')][_0x453f('0xb')]===undefined?!![]:![]:!![],'where':_0x3eaa30[_0x453f('0xa')]?_0x3eaa30[_0x453f('0xa')][_0x453f('0xc')]||null:null,'attributes':_0x3eaa30[_0x453f('0xa')]?_0x3eaa30['options'][_0x453f('0xd')]||null:null,'limit':_0x3eaa30[_0x453f('0xa')]?_0x3eaa30[_0x453f('0xa')][_0x453f('0xe')]||null:null,'include':_0x3eaa30['options']?_0x3eaa30[_0x453f('0xa')]['include']?_['map'](_0x3eaa30[_0x453f('0xa')][_0x453f('0xf')],function(_0x145ef2){return{'model':db[_0x145ef2[_0x453f('0x10')]],'as':_0x145ef2['as'],'attributes':_0x145ef2[_0x453f('0xd')],'include':_0x145ef2[_0x453f('0xf')]?_[_0x453f('0x11')](_0x145ef2[_0x453f('0xf')],function(_0x3d78cf){return{'model':db[_0x3d78cf[_0x453f('0x10')]],'as':_0x3d78cf['as'],'attributes':_0x3d78cf[_0x453f('0xd')],'include':_0x3d78cf['include']?_[_0x453f('0x11')](_0x3d78cf['include'],function(_0x45fd31){return{'model':db[_0x45fd31[_0x453f('0x10')]],'as':_0x45fd31['as'],'attributes':_0x45fd31[_0x453f('0xd')]};}):[]};}):[]};}):[]:[]})[_0x453f('0x12')](function(_0x575e01){logger[_0x453f('0x13')]('GetInterval',_0x3eaa30);logger[_0x453f('0x14')](_0x453f('0x7'),_0x3eaa30,JSON['stringify'](_0x575e01));_0x27d5e7(_0x575e01);})[_0x453f('0x15')](function(_0x22c73d){logger['error'](_0x453f('0x7'),_0x22c73d[_0x453f('0x16')],_0x3eaa30);_0x273a0d(_0x4f9656[_0x453f('0x17')](0x1f4,_0x22c73d['message']));});});};exports['ShowInterval']=function(_0x50f64e){var _0x22bfe3=this;return new Promise(function(_0x216ab0,_0x32123a){return db['Interval'][_0x453f('0x18')]({'raw':_0x50f64e['options']?_0x50f64e['options'][_0x453f('0xb')]===undefined?!![]:![]:!![],'where':_0x50f64e[_0x453f('0xa')]?_0x50f64e[_0x453f('0xa')][_0x453f('0xc')]||null:null,'attributes':_0x50f64e['options']?_0x50f64e[_0x453f('0xa')][_0x453f('0xd')]||null:null,'include':_0x50f64e[_0x453f('0xa')]?_0x50f64e['options'][_0x453f('0xf')]?_[_0x453f('0x11')](_0x50f64e[_0x453f('0xa')][_0x453f('0xf')],function(_0x382b75){return{'model':db[_0x382b75[_0x453f('0x10')]],'as':_0x382b75['as'],'attributes':_0x382b75[_0x453f('0xd')],'include':_0x382b75[_0x453f('0xf')]?_[_0x453f('0x11')](_0x382b75[_0x453f('0xf')],function(_0x157f56){return{'model':db[_0x157f56[_0x453f('0x10')]],'as':_0x157f56['as'],'attributes':_0x157f56[_0x453f('0xd')],'include':_0x157f56[_0x453f('0xf')]?_[_0x453f('0x11')](_0x157f56[_0x453f('0xf')],function(_0x3ffdf7){return{'model':db[_0x3ffdf7['model']],'as':_0x3ffdf7['as'],'attributes':_0x3ffdf7[_0x453f('0xd')]};}):[]};}):[]};}):[]:[]})[_0x453f('0x12')](function(_0x20d35a){logger['info'](_0x453f('0x19'),_0x50f64e);logger[_0x453f('0x14')]('ShowInterval',_0x50f64e,JSON[_0x453f('0x1a')](_0x20d35a));_0x216ab0(_0x20d35a);})[_0x453f('0x15')](function(_0x5b3295){logger[_0x453f('0x17')]('ShowInterval',_0x5b3295[_0x453f('0x16')],_0x50f64e);_0x32123a(_0x22bfe3['error'](0x1f4,_0x5b3295['message']));});});};function checkArrayOfIntervals(_0x453cb3,_0x504f73){var _0xf47c28=[];return db[_0x453f('0x8')]['findAll']({'where':{'id':_0x453cb3}})[_0x453f('0x12')](function(_0x26f788){_0xf47c28=_0x26f788;return Promise[_0x453f('0x1b')](_0xf47c28['map'](function(_0x4327b3){return _0x4327b3['ifTime'](_0x504f73);}));})['then'](function(_0x486ee7){var _0x3a4c9a=_0x486ee7[_0x453f('0x1c')](function(_0x5e7c1c,_0x4372e4){return _0x5e7c1c||_0x4372e4;},![]);logger[_0x453f('0x13')](util['format'](_0x453f('0x1d'),_0xf47c28['map'](function(_0x1eae5b){return _0x1eae5b[_0x453f('0x1e')];})[_0x453f('0x1f')](',\x20'),_0xf47c28[_0x453f('0x11')](function(_0x5c23f2){return _0x5c23f2['id'];})[_0x453f('0x1f')](',\x20')));return _0x3a4c9a;});}function checkSingleInterval(_0x556b93,_0x573c9c){return db['Interval'][_0x453f('0x20')](_0x556b93)[_0x453f('0x12')](function(_0x4e0345){if(_0x4e0345){logger[_0x453f('0x13')](util[_0x453f('0x21')](_0x453f('0x22'),_0x4e0345[_0x453f('0x1e')],_0x4e0345['id']));return _0x4e0345[_0x453f('0x23')](_0x573c9c);}});}exports['IntervalIftime']=function(_0x361b79){var _0x3b871b=_0x361b79['intervalIds'];var _0x2d3bd4=Array[_0x453f('0x24')](_0x361b79['intervals'])?_0x361b79[_0x453f('0x25')]:typeof _0x361b79['intervals']==='string'?[_0x361b79[_0x453f('0x25')]]:[];var _0x5a4944=_0x361b79[_0x453f('0x26')]||undefined;var _0x1bc08d=![];if(_0x2d3bd4[_0x453f('0x27')]){logger[_0x453f('0x13')](util['format'](_0x453f('0x28'),_0x2d3bd4['join'](';\x20')));}if(_0x5a4944){logger['info'](util[_0x453f('0x21')](_0x453f('0x29'),_0x5a4944));}logger['debug'](_0x453f('0x2a'),_0x1bc08d);logger[_0x453f('0x2b')](_0x453f('0x2c'),_0x361b79);return Promise[_0x453f('0x2d')]()[_0x453f('0x12')](function(){if(Array[_0x453f('0x24')](_0x3b871b)){return checkArrayOfIntervals(_0x3b871b,_0x5a4944);}else if(_0x3b871b){return checkSingleInterval(_0x3b871b,_0x5a4944);}})[_0x453f('0x12')](function(_0x48c3d3){var _0x19b6d8=_0x2d3bd4[_0x453f('0x1c')](function(_0x3de288,_0x6690de){return _0x3de288||iftime(_0x6690de,_0x5a4944);},![]);_0x1bc08d=_0x48c3d3||_0x19b6d8;return _0x1bc08d;})[_0x453f('0x15')](function(_0x3cb859){logger['error'](_0x453f('0x2c'),_0x361b79,_0x3cb859);throw this[_0x453f('0x17')](0x1f4,_0x3cb859[_0x453f('0x16')]);});};