c181a5baa012e68c9cb9d210fe4d250bdb68506f
[motion2.git] / server / api / cmHopper / cmHopper.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 _0x65f3=['randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','http','then','CmHopper,\x20%s,\x20%s','request\x20sent','CmHopper,\x20%s,\x20%s,\x20%s','error','code','message','info','result','catch','GetCmHopper','CmHopper','options','raw','where','attributes','map','include','model','debug','stringify','find','ShowCmHopper','CreateCmHopper','UpdateCmHopper','update','limit','DestroyCmHopper','destroy','CmContact','describe','transaction','findAll','order','LOCK','UPDATE','Contact','keys','push','body','all','GetContactDialer','MoveContactManagedDialer','sequelize','CmHopperFinal','create','CountReScheduled','COUNT','`scheduledat`\x20>=\x20','\x22%s\x22','\x20,\x201,\x20null','contactsRescheduled','GetContactRecallMe','UserId','length','util','moment','bluebird'];(function(_0xc7ed33,_0x4650ee){var _0x47e1f1=function(_0xb4a8cb){while(--_0xb4a8cb){_0xc7ed33['push'](_0xc7ed33['shift']());}};_0x47e1f1(++_0x4650ee);}(_0x65f3,0x1cb));var _0x365f=function(_0x525889,_0x136fdc){_0x525889=_0x525889-0x0;var _0x12237d=_0x65f3[_0x525889];return _0x12237d;};'use strict';var _=require('lodash');var util=require(_0x365f('0x0'));var moment=require(_0x365f('0x1'));var BPromise=require(_0x365f('0x2'));var rs=require(_0x365f('0x3'));var fs=require('fs');var Redis=require(_0x365f('0x4'));var db=require(_0x365f('0x5'))['db'];var utils=require(_0x365f('0x6'));var logger=require(_0x365f('0x7'))('rpc');var config=require(_0x365f('0x8'));var jayson=require(_0x365f('0x9'));var client=jayson['client'][_0x365f('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x46cebc,_0x53f58f,_0x5ebfdf){return new BPromise(function(_0xf9f5e8,_0x1d64f9){return client['request'](_0x46cebc,_0x5ebfdf)[_0x365f('0xb')](function(_0xec6f10){logger['info'](_0x365f('0xc'),_0x53f58f,_0x365f('0xd'));logger['debug'](_0x365f('0xe'),_0x53f58f,_0x365f('0xd'),JSON['stringify'](_0xec6f10));if(_0xec6f10[_0x365f('0xf')]){if(_0xec6f10[_0x365f('0xf')][_0x365f('0x10')]===0x1f4){logger['error']('CmHopper,\x20%s,\x20%s',_0x53f58f,_0xec6f10[_0x365f('0xf')][_0x365f('0x11')]);return _0x1d64f9(_0xec6f10[_0x365f('0xf')]['message']);}logger[_0x365f('0xf')]('CmHopper,\x20%s,\x20%s',_0x53f58f,_0xec6f10[_0x365f('0xf')][_0x365f('0x11')]);return _0xf9f5e8(_0xec6f10['error']['message']);}else{logger[_0x365f('0x12')](_0x365f('0xc'),_0x53f58f,_0x365f('0xd'));_0xf9f5e8(_0xec6f10[_0x365f('0x13')][_0x365f('0x11')]);}})[_0x365f('0x14')](function(_0x4c3a73){logger['error'](_0x365f('0xc'),_0x53f58f,_0x4c3a73);_0x1d64f9(_0x4c3a73);});});}exports[_0x365f('0x15')]=function(_0x417f49){var _0x27f083=this;return new Promise(function(_0x4ebd7b,_0x94d56b){return db[_0x365f('0x16')]['findAll']({'raw':_0x417f49[_0x365f('0x17')]?_0x417f49[_0x365f('0x17')][_0x365f('0x18')]===undefined?!![]:![]:!![],'where':_0x417f49[_0x365f('0x17')]?_0x417f49['options'][_0x365f('0x19')]||null:null,'attributes':_0x417f49[_0x365f('0x17')]?_0x417f49[_0x365f('0x17')][_0x365f('0x1a')]||null:null,'limit':_0x417f49[_0x365f('0x17')]?_0x417f49['options']['limit']||null:null,'include':_0x417f49[_0x365f('0x17')]?_0x417f49[_0x365f('0x17')]['include']?_[_0x365f('0x1b')](_0x417f49[_0x365f('0x17')]['include'],function(_0x4d2433){return{'model':db[_0x4d2433['model']],'as':_0x4d2433['as'],'attributes':_0x4d2433[_0x365f('0x1a')],'include':_0x4d2433[_0x365f('0x1c')]?_['map'](_0x4d2433[_0x365f('0x1c')],function(_0x3e873c){return{'model':db[_0x3e873c[_0x365f('0x1d')]],'as':_0x3e873c['as'],'attributes':_0x3e873c[_0x365f('0x1a')],'include':_0x3e873c[_0x365f('0x1c')]?_['map'](_0x3e873c[_0x365f('0x1c')],function(_0x399be5){return{'model':db[_0x399be5['model']],'as':_0x399be5['as'],'attributes':_0x399be5[_0x365f('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x365f('0xb')](function(_0x2b08b2){logger[_0x365f('0x12')]('GetCmHopper',_0x417f49);logger[_0x365f('0x1e')]('GetCmHopper',_0x417f49,JSON[_0x365f('0x1f')](_0x2b08b2));_0x4ebd7b(_0x2b08b2);})[_0x365f('0x14')](function(_0x48494e){logger[_0x365f('0xf')](_0x365f('0x15'),_0x48494e['message'],_0x417f49);_0x94d56b(_0x27f083[_0x365f('0xf')](0x1f4,_0x48494e['message']));});});};exports['ShowCmHopper']=function(_0x199631){var _0x1898e0=this;return new Promise(function(_0x43f9ff,_0x59b174){return db['CmHopper'][_0x365f('0x20')]({'raw':_0x199631[_0x365f('0x17')]?_0x199631[_0x365f('0x17')][_0x365f('0x18')]===undefined?!![]:![]:!![],'where':_0x199631[_0x365f('0x17')]?_0x199631[_0x365f('0x17')][_0x365f('0x19')]||null:null,'attributes':_0x199631[_0x365f('0x17')]?_0x199631['options'][_0x365f('0x1a')]||null:null,'include':_0x199631[_0x365f('0x17')]?_0x199631['options'][_0x365f('0x1c')]?_[_0x365f('0x1b')](_0x199631[_0x365f('0x17')][_0x365f('0x1c')],function(_0xa55f7){return{'model':db[_0xa55f7[_0x365f('0x1d')]],'as':_0xa55f7['as'],'attributes':_0xa55f7[_0x365f('0x1a')],'include':_0xa55f7[_0x365f('0x1c')]?_['map'](_0xa55f7[_0x365f('0x1c')],function(_0x35f56d){return{'model':db[_0x35f56d[_0x365f('0x1d')]],'as':_0x35f56d['as'],'attributes':_0x35f56d[_0x365f('0x1a')],'include':_0x35f56d['include']?_['map'](_0x35f56d[_0x365f('0x1c')],function(_0x4e233f){return{'model':db[_0x4e233f[_0x365f('0x1d')]],'as':_0x4e233f['as'],'attributes':_0x4e233f[_0x365f('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x365f('0xb')](function(_0x1f535b){logger[_0x365f('0x12')]('ShowCmHopper',_0x199631);logger[_0x365f('0x1e')](_0x365f('0x21'),_0x199631,JSON[_0x365f('0x1f')](_0x1f535b));_0x43f9ff(_0x1f535b);})[_0x365f('0x14')](function(_0x33ccab){logger[_0x365f('0xf')]('ShowCmHopper',_0x33ccab[_0x365f('0x11')],_0x199631);_0x59b174(_0x1898e0[_0x365f('0xf')](0x1f4,_0x33ccab[_0x365f('0x11')]));});});};exports[_0x365f('0x22')]=function(_0x15c203){var _0x5e3c83=this;return new Promise(function(_0x3fce89,_0x32503b){return db[_0x365f('0x16')]['create'](_0x15c203['body'],{'raw':_0x15c203[_0x365f('0x17')]?_0x15c203[_0x365f('0x17')][_0x365f('0x18')]===undefined?!![]:![]:!![]})[_0x365f('0xb')](function(_0x378948){logger[_0x365f('0x12')](_0x365f('0x22'),_0x15c203);logger[_0x365f('0x1e')](_0x365f('0x22'),_0x15c203,JSON[_0x365f('0x1f')](_0x378948));_0x3fce89(_0x378948);})[_0x365f('0x14')](function(_0xb1b8e8){logger[_0x365f('0xf')](_0x365f('0x22'),_0xb1b8e8[_0x365f('0x11')],_0x15c203);_0x32503b(_0x5e3c83[_0x365f('0xf')](0x1f4,_0xb1b8e8[_0x365f('0x11')]));});});};exports[_0x365f('0x23')]=function(_0x1e33d4){var _0x2ce8fa=this;return new Promise(function(_0x234b6c,_0x216f41){return db[_0x365f('0x16')][_0x365f('0x24')](_0x1e33d4['body'],{'raw':_0x1e33d4[_0x365f('0x17')]?_0x1e33d4[_0x365f('0x17')][_0x365f('0x18')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1e33d4[_0x365f('0x17')]?_0x1e33d4[_0x365f('0x17')][_0x365f('0x19')]||null:null,'attributes':_0x1e33d4['options']?_0x1e33d4['options']['attributes']||null:null,'limit':_0x1e33d4[_0x365f('0x17')]?_0x1e33d4[_0x365f('0x17')][_0x365f('0x25')]||null:null})[_0x365f('0xb')](function(_0x50e229){logger[_0x365f('0x12')]('UpdateCmHopper',_0x1e33d4);logger[_0x365f('0x1e')](_0x365f('0x23'),_0x1e33d4,JSON[_0x365f('0x1f')](_0x50e229));_0x234b6c(_0x50e229);})['catch'](function(_0x5bcfd6){logger['error'](_0x365f('0x23'),_0x5bcfd6[_0x365f('0x11')],_0x1e33d4);_0x216f41(_0x2ce8fa[_0x365f('0xf')](0x1f4,_0x5bcfd6['message']));});});};exports[_0x365f('0x26')]=function(_0x46b05b){var _0x4560c5=this;return new Promise(function(_0x5e33e6,_0x44b0d7){return db[_0x365f('0x16')][_0x365f('0x27')]({'where':_0x46b05b[_0x365f('0x17')]?_0x46b05b[_0x365f('0x17')]['where']||null:null})['then'](function(_0x10fae5){logger[_0x365f('0x12')](_0x365f('0x26'),_0x46b05b);logger[_0x365f('0x1e')](_0x365f('0x26'),_0x46b05b,JSON[_0x365f('0x1f')](_0x10fae5));_0x5e33e6(_0x10fae5);})[_0x365f('0x14')](function(_0x43d0fa){logger['error']('DestroyCmHopper',_0x43d0fa['message'],_0x46b05b);_0x44b0d7(_0x4560c5[_0x365f('0xf')](0x1f4,_0x43d0fa[_0x365f('0x11')]));});});};exports['GetContactDialer']=function(_0x349b8c){var _0x33bfbe=this;return new Promise(function(_0x1a5bc3,_0x392be2){return db[_0x365f('0x28')][_0x365f('0x29')]()[_0x365f('0xb')](function(_0x39a45c){return db['sequelize'][_0x365f('0x2a')](function(_0x161263){return db[_0x365f('0x16')][_0x365f('0x2b')]({'where':_0x349b8c['options']?_0x349b8c[_0x365f('0x17')][_0x365f('0x19')]||null:null,'attributes':_0x349b8c[_0x365f('0x17')]?_0x349b8c[_0x365f('0x17')][_0x365f('0x1a')]||null:null,'limit':_0x349b8c[_0x365f('0x17')]?_0x349b8c[_0x365f('0x17')][_0x365f('0x25')]||null:null,'order':_0x349b8c[_0x365f('0x17')]?_0x349b8c[_0x365f('0x17')][_0x365f('0x2c')]||null:null,'transaction':_0x161263,'lock':_0x161263[_0x365f('0x2d')][_0x365f('0x2e')],'include':[{'model':db[_0x365f('0x28')],'as':_0x365f('0x2f'),'attributes':_[_0x365f('0x30')](_0x39a45c)}]})[_0x365f('0xb')](function(_0xf0a6b3){var _0x18eb8a=[];for(var _0x1129e7=0x0;_0x1129e7<_0xf0a6b3['length'];_0x1129e7+=0x1){_0x18eb8a[_0x365f('0x31')](_0xf0a6b3[_0x1129e7]['update'](_0x349b8c[_0x365f('0x32')],{'transaction':_0x161263}));}return BPromise[_0x365f('0x33')](_0x18eb8a);});})[_0x365f('0xb')](function(_0x1d938d){logger[_0x365f('0x12')](_0x365f('0x34'),_0x349b8c);logger[_0x365f('0x1e')](_0x365f('0x34'),_0x349b8c,JSON['stringify'](_0x1d938d));_0x1a5bc3(_0x1d938d);})[_0x365f('0x14')](function(_0x2aecec){logger[_0x365f('0xf')](_0x365f('0x34'),_0x2aecec[_0x365f('0x11')],_0x349b8c);_0x392be2(_0x33bfbe[_0x365f('0xf')](0x1f4,_0x2aecec[_0x365f('0x11')]));});});});};exports[_0x365f('0x35')]=function(_0x57a7ca){var _0x362ae6=this;return new Promise(function(_0x5d5cbf,_0x3ca52a){return db[_0x365f('0x36')]['transaction'](function(_0x3a8d2c){return db[_0x365f('0x37')][_0x365f('0x38')](_0x57a7ca['body'],{'raw':_0x57a7ca['options']?_0x57a7ca[_0x365f('0x17')][_0x365f('0x18')]===undefined?!![]:![]:!![],'transaction':_0x3a8d2c})[_0x365f('0xb')](function(){return db[_0x365f('0x16')]['destroy']({'where':_0x57a7ca[_0x365f('0x17')]?_0x57a7ca[_0x365f('0x17')][_0x365f('0x19')]||null:null,'transaction':_0x3a8d2c});});})[_0x365f('0xb')](function(_0x29d767){logger[_0x365f('0x12')](_0x365f('0x35'),_0x57a7ca);logger['debug']('MoveContactManagedDialer',_0x57a7ca,JSON['stringify'](_0x29d767));_0x5d5cbf(_0x29d767);})['catch'](function(_0x51ae9d){logger[_0x365f('0xf')](_0x365f('0x35'),_0x51ae9d[_0x365f('0x11')],_0x57a7ca);_0x3ca52a(_0x362ae6[_0x365f('0xf')](0x1f4,_0x51ae9d[_0x365f('0x11')]));});});};exports[_0x365f('0x39')]=function(_0x388959){var _0x46669b=this;return new Promise(function(_0x62a83e,_0x2faca9){return db['CmHopper'][_0x365f('0x2b')]({'raw':_0x388959[_0x365f('0x17')]?_0x388959['options'][_0x365f('0x18')]===undefined?!![]:![]:!![],'where':_0x388959[_0x365f('0x17')]?_0x388959[_0x365f('0x17')][_0x365f('0x19')]||null:null,'attributes':[[db[_0x365f('0x36')]['fn'](_0x365f('0x3a'),db['sequelize']['fn']('IF',db[_0x365f('0x36')]['literal'](_0x365f('0x3b')+util['format'](_0x365f('0x3c'),moment()['format']('YYYY-MM-DD\x20HH:mm:ss'))+_0x365f('0x3d')))),_0x365f('0x3e')]]})[_0x365f('0xb')](function(_0x1f6169){logger[_0x365f('0x12')](_0x365f('0x39'),_0x388959);logger[_0x365f('0x1e')](_0x365f('0x39'),_0x388959,JSON[_0x365f('0x1f')](_0x1f6169));_0x62a83e(_0x1f6169);})[_0x365f('0x14')](function(_0x57cb77){logger['error'](_0x365f('0x39'),_0x57cb77[_0x365f('0x11')],_0x388959);_0x2faca9(_0x46669b['error'](0x1f4,_0x57cb77[_0x365f('0x11')]));});});};exports[_0x365f('0x3f')]=function(_0x591dc7){var _0x16e0fe=this;return new Promise(function(_0x38e3fa,_0x22c392){return db[_0x365f('0x28')][_0x365f('0x29')]()[_0x365f('0xb')](function(_0x1d453d){return db['sequelize'][_0x365f('0x2a')](function(_0x494dd1){return db['CmHopper'][_0x365f('0x2b')]({'where':_0x591dc7[_0x365f('0x17')]?_0x591dc7[_0x365f('0x17')][_0x365f('0x19')]||null:null,'attributes':_0x591dc7[_0x365f('0x17')]?_0x591dc7[_0x365f('0x17')][_0x365f('0x1a')]||null:null,'limit':0x1,'order':_0x591dc7['options']?_0x591dc7[_0x365f('0x17')][_0x365f('0x2c')]||null:null,'group':db[_0x365f('0x16')][_0x365f('0x40')],'transaction':_0x494dd1,'lock':_0x494dd1['LOCK'][_0x365f('0x2e')],'include':_0x591dc7[_0x365f('0x17')]?_0x591dc7[_0x365f('0x17')][_0x365f('0x1c')]?_[_0x365f('0x1b')](_0x591dc7[_0x365f('0x17')][_0x365f('0x1c')],function(_0x164ccc){return{'model':db[_0x164ccc[_0x365f('0x1d')]],'as':_0x164ccc['as'],'attributes':_0x164ccc[_0x365f('0x1a')],'include':_0x164ccc[_0x365f('0x1c')]?_['map'](_0x164ccc[_0x365f('0x1c')],function(_0x22fb8d){return{'model':db[_0x22fb8d[_0x365f('0x1d')]],'as':_0x22fb8d['as'],'attributes':_0x22fb8d[_0x365f('0x1a')],'include':_0x22fb8d[_0x365f('0x1c')]?_[_0x365f('0x1b')](_0x22fb8d[_0x365f('0x1c')],function(_0x4b9a10){return{'model':db[_0x4b9a10[_0x365f('0x1d')]],'as':_0x4b9a10['as'],'attributes':_0x4b9a10[_0x365f('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x365f('0xb')](function(_0x3cbed5){var _0x460177=[];for(var _0x2fd2b3=0x0;_0x2fd2b3<_0x3cbed5[_0x365f('0x41')];_0x2fd2b3+=0x1){_0x460177[_0x365f('0x31')](_0x3cbed5[_0x2fd2b3][_0x365f('0x24')](_0x591dc7['body'],{'transaction':_0x494dd1}));}return BPromise[_0x365f('0x33')](_0x460177);});})[_0x365f('0xb')](function(_0x40bc80){logger[_0x365f('0x12')](_0x365f('0x3f'),_0x591dc7);logger[_0x365f('0x1e')](_0x365f('0x3f'),_0x591dc7,JSON[_0x365f('0x1f')](_0x40bc80));_0x38e3fa(_0x40bc80);})[_0x365f('0x14')](function(_0x5db507){logger[_0x365f('0xf')]('GetContactRecallMe',_0x5db507[_0x365f('0x11')],_0x591dc7);_0x22c392(_0x16e0fe[_0x365f('0xf')](0x1f4,_0x5db507[_0x365f('0x11')]));});});});};