Built motion from commit 6362bb75.|2.6.13
[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 _0xcf05=['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','util','../../mysqldb','../../utils/iftime','iftime','../../config/logger','rpc','Interval','findAll','options','raw','attributes','limit','include','model','map','info','GetInterval','debug','stringify','error','message','find','then','ShowInterval','catch','all','ifTime','reduce','format','IntervalIftime:\x20intervals\x20=\x20%s\x20(ids\x20=\x20%s)'];(function(_0x2498b5,_0x514ddb){var _0x5c48d8=function(_0xee9bb5){while(--_0xee9bb5){_0x2498b5['push'](_0x2498b5['shift']());}};_0x5c48d8(++_0x514ddb);}(_0xcf05,0x1d1));var _0x5cf0=function(_0x3fd816,_0x367d5c){_0x3fd816=_0x3fd816-0x0;var _0x5b3640=_0xcf05[_0x3fd816];return _0x5b3640;};'use strict';var _=require('lodash');var util=require(_0x5cf0('0x0'));var db=require(_0x5cf0('0x1'))['db'];var iftime=require(_0x5cf0('0x2'))[_0x5cf0('0x3')];var logger=require(_0x5cf0('0x4'))(_0x5cf0('0x5'));exports['GetInterval']=function(_0x426172){var _0x54514c=this;return new Promise(function(_0x5b8177,_0x1d2301){return db[_0x5cf0('0x6')][_0x5cf0('0x7')]({'raw':_0x426172[_0x5cf0('0x8')]?_0x426172[_0x5cf0('0x8')][_0x5cf0('0x9')]===undefined?!![]:![]:!![],'where':_0x426172[_0x5cf0('0x8')]?_0x426172[_0x5cf0('0x8')]['where']||null:null,'attributes':_0x426172[_0x5cf0('0x8')]?_0x426172[_0x5cf0('0x8')][_0x5cf0('0xa')]||null:null,'limit':_0x426172[_0x5cf0('0x8')]?_0x426172[_0x5cf0('0x8')][_0x5cf0('0xb')]||null:null,'include':_0x426172['options']?_0x426172[_0x5cf0('0x8')][_0x5cf0('0xc')]?_['map'](_0x426172[_0x5cf0('0x8')]['include'],function(_0xb47c16){return{'model':db[_0xb47c16[_0x5cf0('0xd')]],'as':_0xb47c16['as'],'attributes':_0xb47c16['attributes'],'include':_0xb47c16[_0x5cf0('0xc')]?_['map'](_0xb47c16[_0x5cf0('0xc')],function(_0x5199a3){return{'model':db[_0x5199a3[_0x5cf0('0xd')]],'as':_0x5199a3['as'],'attributes':_0x5199a3['attributes'],'include':_0x5199a3[_0x5cf0('0xc')]?_[_0x5cf0('0xe')](_0x5199a3['include'],function(_0x11a0f1){return{'model':db[_0x11a0f1[_0x5cf0('0xd')]],'as':_0x11a0f1['as'],'attributes':_0x11a0f1['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x3965d9){logger[_0x5cf0('0xf')](_0x5cf0('0x10'),_0x426172);logger[_0x5cf0('0x11')](_0x5cf0('0x10'),_0x426172,JSON[_0x5cf0('0x12')](_0x3965d9));_0x5b8177(_0x3965d9);})['catch'](function(_0x4d9eaf){logger[_0x5cf0('0x13')](_0x5cf0('0x10'),_0x4d9eaf[_0x5cf0('0x14')],_0x426172);_0x1d2301(_0x54514c[_0x5cf0('0x13')](0x1f4,_0x4d9eaf[_0x5cf0('0x14')]));});});};exports['ShowInterval']=function(_0x4f2e96){var _0x8e1776=this;return new Promise(function(_0x16ba8f,_0x355053){return db[_0x5cf0('0x6')][_0x5cf0('0x15')]({'raw':_0x4f2e96['options']?_0x4f2e96[_0x5cf0('0x8')][_0x5cf0('0x9')]===undefined?!![]:![]:!![],'where':_0x4f2e96['options']?_0x4f2e96[_0x5cf0('0x8')]['where']||null:null,'attributes':_0x4f2e96['options']?_0x4f2e96['options'][_0x5cf0('0xa')]||null:null,'include':_0x4f2e96[_0x5cf0('0x8')]?_0x4f2e96[_0x5cf0('0x8')][_0x5cf0('0xc')]?_[_0x5cf0('0xe')](_0x4f2e96[_0x5cf0('0x8')]['include'],function(_0x2d1e9f){return{'model':db[_0x2d1e9f[_0x5cf0('0xd')]],'as':_0x2d1e9f['as'],'attributes':_0x2d1e9f[_0x5cf0('0xa')],'include':_0x2d1e9f[_0x5cf0('0xc')]?_[_0x5cf0('0xe')](_0x2d1e9f[_0x5cf0('0xc')],function(_0x329093){return{'model':db[_0x329093[_0x5cf0('0xd')]],'as':_0x329093['as'],'attributes':_0x329093[_0x5cf0('0xa')],'include':_0x329093[_0x5cf0('0xc')]?_[_0x5cf0('0xe')](_0x329093['include'],function(_0x3c26cd){return{'model':db[_0x3c26cd[_0x5cf0('0xd')]],'as':_0x3c26cd['as'],'attributes':_0x3c26cd[_0x5cf0('0xa')]};}):[]};}):[]};}):[]:[]})[_0x5cf0('0x16')](function(_0x45b224){logger[_0x5cf0('0xf')](_0x5cf0('0x17'),_0x4f2e96);logger[_0x5cf0('0x11')]('ShowInterval',_0x4f2e96,JSON[_0x5cf0('0x12')](_0x45b224));_0x16ba8f(_0x45b224);})[_0x5cf0('0x18')](function(_0x19e3d4){logger[_0x5cf0('0x13')]('ShowInterval',_0x19e3d4['message'],_0x4f2e96);_0x355053(_0x8e1776['error'](0x1f4,_0x19e3d4[_0x5cf0('0x14')]));});});};function checkArrayOfIntervals(_0x517500,_0x5ceda9){var _0x2f6c9e=[];return db['Interval']['findAll']({'where':{'id':_0x517500}})[_0x5cf0('0x16')](function(_0x16f8f3){_0x2f6c9e=_0x16f8f3;return Promise[_0x5cf0('0x19')](_0x2f6c9e[_0x5cf0('0xe')](function(_0x31f4a5){return _0x31f4a5[_0x5cf0('0x1a')](_0x5ceda9);}));})[_0x5cf0('0x16')](function(_0x283613){var _0x33930b=_0x283613[_0x5cf0('0x1b')](function(_0x3724d0,_0xb58545){return _0x3724d0||_0xb58545;},![]);logger[_0x5cf0('0xf')](util[_0x5cf0('0x1c')](_0x5cf0('0x1d'),_0x2f6c9e[_0x5cf0('0xe')](function(_0x159c10){return _0x159c10[_0x5cf0('0x1e')];})[_0x5cf0('0x1f')](',\x20'),_0x2f6c9e[_0x5cf0('0xe')](function(_0x77b7d8){return _0x77b7d8['id'];})[_0x5cf0('0x1f')](',\x20')));return _0x33930b;});}function checkSingleInterval(_0x1af7e0,_0x69eaa8){return db[_0x5cf0('0x6')][_0x5cf0('0x20')](_0x1af7e0)[_0x5cf0('0x16')](function(_0x579e7f){if(_0x579e7f){logger[_0x5cf0('0xf')](util[_0x5cf0('0x1c')](_0x5cf0('0x21'),_0x579e7f[_0x5cf0('0x1e')],_0x579e7f['id']));return _0x579e7f[_0x5cf0('0x1a')](_0x69eaa8);}});}exports['IntervalIftime']=function(_0x108950){var _0x463223=_0x108950[_0x5cf0('0x22')];var _0x2bc55d=Array[_0x5cf0('0x23')](_0x108950[_0x5cf0('0x24')])?_0x108950[_0x5cf0('0x24')]:typeof _0x108950[_0x5cf0('0x24')]===_0x5cf0('0x25')?[_0x108950[_0x5cf0('0x24')]]:[];var _0x1780ea=_0x108950[_0x5cf0('0x26')]||undefined;var _0x22f7cf=![];if(_0x2bc55d[_0x5cf0('0x27')]){logger[_0x5cf0('0xf')](util[_0x5cf0('0x1c')](_0x5cf0('0x28'),_0x2bc55d[_0x5cf0('0x1f')](';\x20')));}if(_0x1780ea){logger[_0x5cf0('0xf')](util[_0x5cf0('0x1c')](_0x5cf0('0x29'),_0x1780ea));}logger['debug'](_0x5cf0('0x2a'),_0x22f7cf);logger[_0x5cf0('0x2b')](_0x5cf0('0x2c'),_0x108950);return Promise['resolve']()['then'](function(){if(Array[_0x5cf0('0x23')](_0x463223)){return checkArrayOfIntervals(_0x463223,_0x1780ea);}else if(_0x463223){return checkSingleInterval(_0x463223,_0x1780ea);}})[_0x5cf0('0x16')](function(_0xa040c0){var _0x599286=_0x2bc55d[_0x5cf0('0x1b')](function(_0x1fcdfc,_0x2d5619){return _0x1fcdfc||iftime(_0x2d5619,_0x1780ea);},![]);_0x22f7cf=_0xa040c0||_0x599286;return _0x22f7cf;})[_0x5cf0('0x18')](function(_0xb4f571){logger[_0x5cf0('0x13')](_0x5cf0('0x2c'),_0x108950,_0xb4f571);throw this['error'](0x1f4,_0xb4f571[_0x5cf0('0x14')]);});};