8e3f6f927657f9a5160669a6258bc22da4a1147c
[motion2.git] / server / api / trunk / trunk.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 _0xe7d6=['rpc','../../config/environment','jayson/promise','client','http','request','then','info','Trunk,\x20%s,\x20%s','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','message','request\x20sent','result','catch','GetTrunk','findAll','options','raw','include','map','model','attributes','debug','Trunk','find','ShowTrunk','moment','bluebird','randomstring','../../mysqldb','../../config/logger'];(function(_0x1b5433,_0x3b89ae){var _0x58e0de=function(_0x5aeb0f){while(--_0x5aeb0f){_0x1b5433['push'](_0x1b5433['shift']());}};_0x58e0de(++_0x3b89ae);}(_0xe7d6,0x124));var _0x6e7d=function(_0x3253a4,_0x43a815){_0x3253a4=_0x3253a4-0x0;var _0xb6a170=_0xe7d6[_0x3253a4];return _0xb6a170;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x6e7d('0x0'));var BPromise=require(_0x6e7d('0x1'));var rs=require(_0x6e7d('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x6e7d('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0x6e7d('0x4'))(_0x6e7d('0x5'));var config=require(_0x6e7d('0x6'));var jayson=require(_0x6e7d('0x7'));var client=jayson[_0x6e7d('0x8')][_0x6e7d('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x309a77,_0x32cdcf,_0x15d97b){return new BPromise(function(_0x3e8200,_0x527001){return client[_0x6e7d('0xa')](_0x309a77,_0x15d97b)[_0x6e7d('0xb')](function(_0xa87072){logger[_0x6e7d('0xc')](_0x6e7d('0xd'),_0x32cdcf,'request\x20sent');logger['debug'](_0x6e7d('0xe'),_0x32cdcf,'request\x20sent',JSON[_0x6e7d('0xf')](_0xa87072));if(_0xa87072[_0x6e7d('0x10')]){if(_0xa87072[_0x6e7d('0x10')]['code']===0x1f4){logger[_0x6e7d('0x10')]('Trunk,\x20%s,\x20%s',_0x32cdcf,_0xa87072[_0x6e7d('0x10')][_0x6e7d('0x11')]);return _0x527001(_0xa87072[_0x6e7d('0x10')][_0x6e7d('0x11')]);}logger['error']('Trunk,\x20%s,\x20%s',_0x32cdcf,_0xa87072[_0x6e7d('0x10')]['message']);return _0x3e8200(_0xa87072['error'][_0x6e7d('0x11')]);}else{logger[_0x6e7d('0xc')]('Trunk,\x20%s,\x20%s',_0x32cdcf,_0x6e7d('0x12'));_0x3e8200(_0xa87072[_0x6e7d('0x13')][_0x6e7d('0x11')]);}})[_0x6e7d('0x14')](function(_0x52c33b){logger[_0x6e7d('0x10')](_0x6e7d('0xd'),_0x32cdcf,_0x52c33b);_0x527001(_0x52c33b);});});}exports[_0x6e7d('0x15')]=function(_0x2dfc12){var _0x6e0da0=this;return new Promise(function(_0x390086,_0x55c3f6){return db['Trunk'][_0x6e7d('0x16')]({'raw':_0x2dfc12[_0x6e7d('0x17')]?_0x2dfc12[_0x6e7d('0x17')][_0x6e7d('0x18')]===undefined?!![]:![]:!![],'where':_0x2dfc12['options']?_0x2dfc12[_0x6e7d('0x17')]['where']||null:null,'attributes':_0x2dfc12[_0x6e7d('0x17')]?_0x2dfc12[_0x6e7d('0x17')]['attributes']||null:null,'limit':_0x2dfc12[_0x6e7d('0x17')]?_0x2dfc12[_0x6e7d('0x17')]['limit']||null:null,'include':_0x2dfc12['options']?_0x2dfc12[_0x6e7d('0x17')][_0x6e7d('0x19')]?_[_0x6e7d('0x1a')](_0x2dfc12['options'][_0x6e7d('0x19')],function(_0x505aa8){return{'model':db[_0x505aa8[_0x6e7d('0x1b')]],'as':_0x505aa8['as'],'attributes':_0x505aa8[_0x6e7d('0x1c')],'include':_0x505aa8['include']?_[_0x6e7d('0x1a')](_0x505aa8[_0x6e7d('0x19')],function(_0x4b86d5){return{'model':db[_0x4b86d5[_0x6e7d('0x1b')]],'as':_0x4b86d5['as'],'attributes':_0x4b86d5[_0x6e7d('0x1c')],'include':_0x4b86d5[_0x6e7d('0x19')]?_[_0x6e7d('0x1a')](_0x4b86d5[_0x6e7d('0x19')],function(_0x17a886){return{'model':db[_0x17a886[_0x6e7d('0x1b')]],'as':_0x17a886['as'],'attributes':_0x17a886['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x8e05fa){logger[_0x6e7d('0xc')](_0x6e7d('0x15'),_0x2dfc12);logger[_0x6e7d('0x1d')](_0x6e7d('0x15'),_0x2dfc12,JSON['stringify'](_0x8e05fa));_0x390086(_0x8e05fa);})[_0x6e7d('0x14')](function(_0x270ad7){logger[_0x6e7d('0x10')](_0x6e7d('0x15'),_0x270ad7[_0x6e7d('0x11')],_0x2dfc12);_0x55c3f6(_0x6e0da0[_0x6e7d('0x10')](0x1f4,_0x270ad7[_0x6e7d('0x11')]));});});};exports['ShowTrunk']=function(_0x4e97ad){var _0x550c1c=this;return new Promise(function(_0x1716b0,_0x3488e4){return db[_0x6e7d('0x1e')][_0x6e7d('0x1f')]({'raw':_0x4e97ad[_0x6e7d('0x17')]?_0x4e97ad['options']['raw']===undefined?!![]:![]:!![],'where':_0x4e97ad[_0x6e7d('0x17')]?_0x4e97ad['options']['where']||null:null,'attributes':_0x4e97ad[_0x6e7d('0x17')]?_0x4e97ad['options']['attributes']||null:null,'include':_0x4e97ad[_0x6e7d('0x17')]?_0x4e97ad[_0x6e7d('0x17')][_0x6e7d('0x19')]?_[_0x6e7d('0x1a')](_0x4e97ad[_0x6e7d('0x17')][_0x6e7d('0x19')],function(_0x131a0e){return{'model':db[_0x131a0e[_0x6e7d('0x1b')]],'as':_0x131a0e['as'],'attributes':_0x131a0e[_0x6e7d('0x1c')],'include':_0x131a0e[_0x6e7d('0x19')]?_[_0x6e7d('0x1a')](_0x131a0e[_0x6e7d('0x19')],function(_0x3fd581){return{'model':db[_0x3fd581[_0x6e7d('0x1b')]],'as':_0x3fd581['as'],'attributes':_0x3fd581[_0x6e7d('0x1c')],'include':_0x3fd581[_0x6e7d('0x19')]?_[_0x6e7d('0x1a')](_0x3fd581[_0x6e7d('0x19')],function(_0x19f0fe){return{'model':db[_0x19f0fe[_0x6e7d('0x1b')]],'as':_0x19f0fe['as'],'attributes':_0x19f0fe[_0x6e7d('0x1c')]};}):[]};}):[]};}):[]:[]})[_0x6e7d('0xb')](function(_0x544685){logger[_0x6e7d('0xc')](_0x6e7d('0x20'),_0x4e97ad);logger[_0x6e7d('0x1d')](_0x6e7d('0x20'),_0x4e97ad,JSON[_0x6e7d('0xf')](_0x544685));_0x1716b0(_0x544685);})[_0x6e7d('0x14')](function(_0x25ae4b){logger['error']('ShowTrunk',_0x25ae4b['message'],_0x4e97ad);_0x3488e4(_0x550c1c[_0x6e7d('0x10')](0x1f4,_0x25ae4b['message']));});});};