f4a3b771a6f519c8091c490ac4105e7564217bc6
[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 _0xe090=['options','raw','where','limit','map','include','model','attributes','then','debug','GetInterval','stringify','catch','message','error','find','info','ShowInterval','all','reduce','format','join','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','name','ifTime','IntervalIftime','intervalIds','intervals','string','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','IntervalIftime:\x20timezone\x20=\x20%s','Iftime','silly','resolve','isArray','lodash','util','../../mysqldb','../../utils/iftime','iftime','../../config/logger','rpc','Interval','findAll'];(function(_0x2db12b,_0x30ab1d){var _0x20990b=function(_0x589477){while(--_0x589477){_0x2db12b['push'](_0x2db12b['shift']());}};_0x20990b(++_0x30ab1d);}(_0xe090,0x1e6));var _0x0e09=function(_0x4a53d,_0x58a95e){_0x4a53d=_0x4a53d-0x0;var _0x27410e=_0xe090[_0x4a53d];return _0x27410e;};'use strict';var _=require(_0x0e09('0x0'));var util=require(_0x0e09('0x1'));var db=require(_0x0e09('0x2'))['db'];var iftime=require(_0x0e09('0x3'))[_0x0e09('0x4')];var logger=require(_0x0e09('0x5'))(_0x0e09('0x6'));exports['GetInterval']=function(_0x1c79ff){var _0x410796=this;return new Promise(function(_0x36706e,_0x36cda1){return db[_0x0e09('0x7')][_0x0e09('0x8')]({'raw':_0x1c79ff[_0x0e09('0x9')]?_0x1c79ff[_0x0e09('0x9')][_0x0e09('0xa')]===undefined?!![]:![]:!![],'where':_0x1c79ff['options']?_0x1c79ff[_0x0e09('0x9')][_0x0e09('0xb')]||null:null,'attributes':_0x1c79ff[_0x0e09('0x9')]?_0x1c79ff[_0x0e09('0x9')]['attributes']||null:null,'limit':_0x1c79ff[_0x0e09('0x9')]?_0x1c79ff[_0x0e09('0x9')][_0x0e09('0xc')]||null:null,'include':_0x1c79ff[_0x0e09('0x9')]?_0x1c79ff['options']['include']?_[_0x0e09('0xd')](_0x1c79ff[_0x0e09('0x9')][_0x0e09('0xe')],function(_0x454856){return{'model':db[_0x454856[_0x0e09('0xf')]],'as':_0x454856['as'],'attributes':_0x454856[_0x0e09('0x10')],'include':_0x454856[_0x0e09('0xe')]?_['map'](_0x454856['include'],function(_0x908d53){return{'model':db[_0x908d53[_0x0e09('0xf')]],'as':_0x908d53['as'],'attributes':_0x908d53[_0x0e09('0x10')],'include':_0x908d53[_0x0e09('0xe')]?_[_0x0e09('0xd')](_0x908d53['include'],function(_0x1182ea){return{'model':db[_0x1182ea[_0x0e09('0xf')]],'as':_0x1182ea['as'],'attributes':_0x1182ea['attributes']};}):[]};}):[]};}):[]:[]})[_0x0e09('0x11')](function(_0x21e93c){logger['info']('GetInterval',_0x1c79ff);logger[_0x0e09('0x12')](_0x0e09('0x13'),_0x1c79ff,JSON[_0x0e09('0x14')](_0x21e93c));_0x36706e(_0x21e93c);})[_0x0e09('0x15')](function(_0x1f86de){logger['error'](_0x0e09('0x13'),_0x1f86de[_0x0e09('0x16')],_0x1c79ff);_0x36cda1(_0x410796[_0x0e09('0x17')](0x1f4,_0x1f86de[_0x0e09('0x16')]));});});};exports['ShowInterval']=function(_0x392527){var _0x27c8eb=this;return new Promise(function(_0x4b339b,_0x10bc38){return db['Interval'][_0x0e09('0x18')]({'raw':_0x392527[_0x0e09('0x9')]?_0x392527[_0x0e09('0x9')][_0x0e09('0xa')]===undefined?!![]:![]:!![],'where':_0x392527[_0x0e09('0x9')]?_0x392527[_0x0e09('0x9')][_0x0e09('0xb')]||null:null,'attributes':_0x392527[_0x0e09('0x9')]?_0x392527['options'][_0x0e09('0x10')]||null:null,'include':_0x392527[_0x0e09('0x9')]?_0x392527[_0x0e09('0x9')][_0x0e09('0xe')]?_[_0x0e09('0xd')](_0x392527[_0x0e09('0x9')][_0x0e09('0xe')],function(_0x37b55f){return{'model':db[_0x37b55f[_0x0e09('0xf')]],'as':_0x37b55f['as'],'attributes':_0x37b55f[_0x0e09('0x10')],'include':_0x37b55f['include']?_[_0x0e09('0xd')](_0x37b55f[_0x0e09('0xe')],function(_0x40d62f){return{'model':db[_0x40d62f[_0x0e09('0xf')]],'as':_0x40d62f['as'],'attributes':_0x40d62f[_0x0e09('0x10')],'include':_0x40d62f[_0x0e09('0xe')]?_[_0x0e09('0xd')](_0x40d62f[_0x0e09('0xe')],function(_0x464f9d){return{'model':db[_0x464f9d['model']],'as':_0x464f9d['as'],'attributes':_0x464f9d['attributes']};}):[]};}):[]};}):[]:[]})[_0x0e09('0x11')](function(_0x2293a6){logger[_0x0e09('0x19')]('ShowInterval',_0x392527);logger[_0x0e09('0x12')](_0x0e09('0x1a'),_0x392527,JSON[_0x0e09('0x14')](_0x2293a6));_0x4b339b(_0x2293a6);})['catch'](function(_0x45b538){logger[_0x0e09('0x17')](_0x0e09('0x1a'),_0x45b538[_0x0e09('0x16')],_0x392527);_0x10bc38(_0x27c8eb[_0x0e09('0x17')](0x1f4,_0x45b538['message']));});});};function checkArrayOfIntervals(_0x515889,_0x481c5d){var _0x418e64=[];return db[_0x0e09('0x7')][_0x0e09('0x8')]({'where':{'id':_0x515889}})[_0x0e09('0x11')](function(_0x1b220b){_0x418e64=_0x1b220b;return Promise[_0x0e09('0x1b')](_0x418e64[_0x0e09('0xd')](function(_0x157477){return _0x157477['ifTime'](_0x481c5d);}));})['then'](function(_0x57280b){var _0x3a4330=_0x57280b[_0x0e09('0x1c')](function(_0x3026eb,_0xe2c139){return _0x3026eb||_0xe2c139;},![]);logger[_0x0e09('0x19')](util[_0x0e09('0x1d')]('IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)',_0x418e64[_0x0e09('0xd')](function(_0x44404c){return _0x44404c['name'];})[_0x0e09('0x1e')](',\x20'),_0x418e64[_0x0e09('0xd')](function(_0x1b2e83){return _0x1b2e83['id'];})[_0x0e09('0x1e')](',\x20')));return _0x3a4330;});}function checkSingleInterval(_0x56d72d,_0x4a71aa){return db[_0x0e09('0x7')]['findById'](_0x56d72d)[_0x0e09('0x11')](function(_0x1ffb35){if(_0x1ffb35){logger[_0x0e09('0x19')](util['format'](_0x0e09('0x1f'),_0x1ffb35[_0x0e09('0x20')],_0x1ffb35['id']));return _0x1ffb35[_0x0e09('0x21')](_0x4a71aa);}});}exports[_0x0e09('0x22')]=function(_0x52f297){var _0x39c5c1=_0x52f297[_0x0e09('0x23')];var _0x732103=Array['isArray'](_0x52f297[_0x0e09('0x24')])?_0x52f297[_0x0e09('0x24')]:typeof _0x52f297['intervals']===_0x0e09('0x25')?[_0x52f297[_0x0e09('0x24')]]:[];var _0x377834=_0x52f297['timezone']||undefined;var _0x3079a1=![];if(_0x732103[_0x0e09('0x26')]){logger[_0x0e09('0x19')](util['format'](_0x0e09('0x27'),_0x732103[_0x0e09('0x1e')](';\x20')));}if(_0x377834){logger[_0x0e09('0x19')](util['format'](_0x0e09('0x28'),_0x377834));}logger[_0x0e09('0x12')](_0x0e09('0x29'),_0x3079a1);logger[_0x0e09('0x2a')]('IntervalIftime',_0x52f297);return Promise[_0x0e09('0x2b')]()[_0x0e09('0x11')](function(){if(Array[_0x0e09('0x2c')](_0x39c5c1)){return checkArrayOfIntervals(_0x39c5c1,_0x377834);}else if(_0x39c5c1){return checkSingleInterval(_0x39c5c1,_0x377834);}})[_0x0e09('0x11')](function(_0x30a0ad){var _0x479329=_0x732103[_0x0e09('0x1c')](function(_0x5660e9,_0x1bbfb5){return _0x5660e9||iftime(_0x1bbfb5,_0x377834);},![]);_0x3079a1=_0x30a0ad||_0x479329;return _0x3079a1;})[_0x0e09('0x15')](function(_0x291344){logger[_0x0e09('0x17')](_0x0e09('0x22'),_0x52f297,_0x291344);throw this[_0x0e09('0x17')](0x1f4,_0x291344[_0x0e09('0x16')]);});};