8e1d1923b105a134a755583d6a8848da77d673c2
[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 _0x3b5b=['attributes','limit','include','map','model','then','debug','stringify','catch','message','error','ShowInterval','find','where','info','all','ifTime','format','name','join','findById','IntervalIftime:\x20interval\x20=\x20%s\x20(id\x20=\x20%s)','intervalIds','isArray','intervals','string','timezone','length','IntervalIftime:\x20interval\x20strings\x20=\x20%s','IntervalIftime:\x20timezone\x20=\x20%s','Iftime','silly','IntervalIftime','resolve','util','iftime','../../config/logger','rpc','Interval','findAll','options'];(function(_0x122d9f,_0x2c9e5b){var _0x41a09e=function(_0x3d9564){while(--_0x3d9564){_0x122d9f['push'](_0x122d9f['shift']());}};_0x41a09e(++_0x2c9e5b);}(_0x3b5b,0x16a));var _0xb3b5=function(_0x102b9f,_0x661060){_0x102b9f=_0x102b9f-0x0;var _0x42c57d=_0x3b5b[_0x102b9f];return _0x42c57d;};'use strict';var _=require('lodash');var util=require(_0xb3b5('0x0'));var db=require('../../mysqldb')['db'];var iftime=require('../../utils/iftime')[_0xb3b5('0x1')];var logger=require(_0xb3b5('0x2'))(_0xb3b5('0x3'));exports['GetInterval']=function(_0x4cae1c){var _0x1e47e7=this;return new Promise(function(_0x39f291,_0x50b325){return db[_0xb3b5('0x4')][_0xb3b5('0x5')]({'raw':_0x4cae1c[_0xb3b5('0x6')]?_0x4cae1c[_0xb3b5('0x6')]['raw']===undefined?!![]:![]:!![],'where':_0x4cae1c[_0xb3b5('0x6')]?_0x4cae1c['options']['where']||null:null,'attributes':_0x4cae1c['options']?_0x4cae1c[_0xb3b5('0x6')][_0xb3b5('0x7')]||null:null,'limit':_0x4cae1c[_0xb3b5('0x6')]?_0x4cae1c[_0xb3b5('0x6')][_0xb3b5('0x8')]||null:null,'include':_0x4cae1c[_0xb3b5('0x6')]?_0x4cae1c[_0xb3b5('0x6')][_0xb3b5('0x9')]?_[_0xb3b5('0xa')](_0x4cae1c[_0xb3b5('0x6')][_0xb3b5('0x9')],function(_0x416499){return{'model':db[_0x416499['model']],'as':_0x416499['as'],'attributes':_0x416499[_0xb3b5('0x7')],'include':_0x416499['include']?_[_0xb3b5('0xa')](_0x416499[_0xb3b5('0x9')],function(_0xafe49){return{'model':db[_0xafe49['model']],'as':_0xafe49['as'],'attributes':_0xafe49[_0xb3b5('0x7')],'include':_0xafe49[_0xb3b5('0x9')]?_[_0xb3b5('0xa')](_0xafe49['include'],function(_0xa2952d){return{'model':db[_0xa2952d[_0xb3b5('0xb')]],'as':_0xa2952d['as'],'attributes':_0xa2952d[_0xb3b5('0x7')]};}):[]};}):[]};}):[]:[]})[_0xb3b5('0xc')](function(_0x83fce4){logger['info']('GetInterval',_0x4cae1c);logger[_0xb3b5('0xd')]('GetInterval',_0x4cae1c,JSON[_0xb3b5('0xe')](_0x83fce4));_0x39f291(_0x83fce4);})[_0xb3b5('0xf')](function(_0xca8930){logger['error']('GetInterval',_0xca8930[_0xb3b5('0x10')],_0x4cae1c);_0x50b325(_0x1e47e7[_0xb3b5('0x11')](0x1f4,_0xca8930[_0xb3b5('0x10')]));});});};exports[_0xb3b5('0x12')]=function(_0x2db956){var _0x3c2fa3=this;return new Promise(function(_0x138fdc,_0x2c3e83){return db[_0xb3b5('0x4')][_0xb3b5('0x13')]({'raw':_0x2db956[_0xb3b5('0x6')]?_0x2db956[_0xb3b5('0x6')]['raw']===undefined?!![]:![]:!![],'where':_0x2db956[_0xb3b5('0x6')]?_0x2db956[_0xb3b5('0x6')][_0xb3b5('0x14')]||null:null,'attributes':_0x2db956[_0xb3b5('0x6')]?_0x2db956[_0xb3b5('0x6')][_0xb3b5('0x7')]||null:null,'include':_0x2db956['options']?_0x2db956['options'][_0xb3b5('0x9')]?_[_0xb3b5('0xa')](_0x2db956[_0xb3b5('0x6')][_0xb3b5('0x9')],function(_0x591a9e){return{'model':db[_0x591a9e[_0xb3b5('0xb')]],'as':_0x591a9e['as'],'attributes':_0x591a9e['attributes'],'include':_0x591a9e[_0xb3b5('0x9')]?_['map'](_0x591a9e[_0xb3b5('0x9')],function(_0x16b98e){return{'model':db[_0x16b98e[_0xb3b5('0xb')]],'as':_0x16b98e['as'],'attributes':_0x16b98e['attributes'],'include':_0x16b98e[_0xb3b5('0x9')]?_[_0xb3b5('0xa')](_0x16b98e[_0xb3b5('0x9')],function(_0x29d5e9){return{'model':db[_0x29d5e9[_0xb3b5('0xb')]],'as':_0x29d5e9['as'],'attributes':_0x29d5e9[_0xb3b5('0x7')]};}):[]};}):[]};}):[]:[]})[_0xb3b5('0xc')](function(_0x165f98){logger[_0xb3b5('0x15')](_0xb3b5('0x12'),_0x2db956);logger[_0xb3b5('0xd')](_0xb3b5('0x12'),_0x2db956,JSON[_0xb3b5('0xe')](_0x165f98));_0x138fdc(_0x165f98);})[_0xb3b5('0xf')](function(_0x4b70b9){logger[_0xb3b5('0x11')](_0xb3b5('0x12'),_0x4b70b9[_0xb3b5('0x10')],_0x2db956);_0x2c3e83(_0x3c2fa3[_0xb3b5('0x11')](0x1f4,_0x4b70b9[_0xb3b5('0x10')]));});});};function checkArrayOfIntervals(_0xc559ce,_0x303c7d){var _0x53bc99=[];return db['Interval'][_0xb3b5('0x5')]({'where':{'id':_0xc559ce}})[_0xb3b5('0xc')](function(_0x522fa0){_0x53bc99=_0x522fa0;return Promise[_0xb3b5('0x16')](_0x53bc99[_0xb3b5('0xa')](function(_0x4a188f){return _0x4a188f[_0xb3b5('0x17')](_0x303c7d);}));})[_0xb3b5('0xc')](function(_0x457a55){var _0x237471=_0x457a55['reduce'](function(_0x1dfafb,_0x420078){return _0x1dfafb||_0x420078;},![]);logger[_0xb3b5('0x15')](util[_0xb3b5('0x18')]('IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)',_0x53bc99[_0xb3b5('0xa')](function(_0x1f8b36){return _0x1f8b36[_0xb3b5('0x19')];})[_0xb3b5('0x1a')](',\x20'),_0x53bc99['map'](function(_0x3adf92){return _0x3adf92['id'];})[_0xb3b5('0x1a')](',\x20')));return _0x237471;});}function checkSingleInterval(_0x3f19c7,_0x4c06ba){return db[_0xb3b5('0x4')][_0xb3b5('0x1b')](_0x3f19c7)[_0xb3b5('0xc')](function(_0x2a8548){if(_0x2a8548){logger['info'](util[_0xb3b5('0x18')](_0xb3b5('0x1c'),_0x2a8548['name'],_0x2a8548['id']));return _0x2a8548[_0xb3b5('0x17')](_0x4c06ba);}});}exports['IntervalIftime']=function(_0x37bf97){var _0x417ef=_0x37bf97[_0xb3b5('0x1d')];var _0x3ce3d3=Array[_0xb3b5('0x1e')](_0x37bf97[_0xb3b5('0x1f')])?_0x37bf97['intervals']:typeof _0x37bf97['intervals']===_0xb3b5('0x20')?[_0x37bf97[_0xb3b5('0x1f')]]:[];var _0x57f018=_0x37bf97[_0xb3b5('0x21')]||undefined;var _0x48835b=![];if(_0x3ce3d3[_0xb3b5('0x22')]){logger[_0xb3b5('0x15')](util[_0xb3b5('0x18')](_0xb3b5('0x23'),_0x3ce3d3['join'](';\x20')));}if(_0x57f018){logger[_0xb3b5('0x15')](util[_0xb3b5('0x18')](_0xb3b5('0x24'),_0x57f018));}logger[_0xb3b5('0xd')](_0xb3b5('0x25'),_0x48835b);logger[_0xb3b5('0x26')](_0xb3b5('0x27'),_0x37bf97);return Promise[_0xb3b5('0x28')]()[_0xb3b5('0xc')](function(){if(Array[_0xb3b5('0x1e')](_0x417ef)){return checkArrayOfIntervals(_0x417ef,_0x57f018);}else if(_0x417ef){return checkSingleInterval(_0x417ef,_0x57f018);}})[_0xb3b5('0xc')](function(_0x387f2a){var _0x6e92ad=_0x3ce3d3['reduce'](function(_0x40a2cf,_0x3aee99){return _0x40a2cf||iftime(_0x3aee99,_0x57f018);},![]);_0x48835b=_0x387f2a||_0x6e92ad;return _0x48835b;})[_0xb3b5('0xf')](function(_0x4da202){logger[_0xb3b5('0x11')]('IntervalIftime',_0x37bf97,_0x4da202);throw this[_0xb3b5('0x11')](0x1f4,_0x4da202[_0xb3b5('0x10')]);});};