6c10411bd1443a182ec35e6d714f3dac82e75609
[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 _0xaab2=['Trunk,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','GetTrunk','Trunk','findAll','options','raw','where','attributes','limit','include','map','model','stringify','ShowTrunk','find','debug','util','moment','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','http','request','then','info','Trunk,\x20%s,\x20%s'];(function(_0xb38e3,_0x2f9824){var _0x1cc20d=function(_0x3a6049){while(--_0x3a6049){_0xb38e3['push'](_0xb38e3['shift']());}};_0x1cc20d(++_0x2f9824);}(_0xaab2,0xca));var _0x2aab=function(_0x110c3d,_0x12ee06){_0x110c3d=_0x110c3d-0x0;var _0x226d67=_0xaab2[_0x110c3d];return _0x226d67;};'use strict';var _=require('lodash');var util=require(_0x2aab('0x0'));var moment=require(_0x2aab('0x1'));var BPromise=require(_0x2aab('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x2aab('0x3'));var db=require(_0x2aab('0x4'))['db'];var utils=require(_0x2aab('0x5'));var logger=require(_0x2aab('0x6'))(_0x2aab('0x7'));var config=require('../../config/environment');var jayson=require(_0x2aab('0x8'));var client=jayson['client'][_0x2aab('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x276906,_0x4fe8a5,_0x2970cb){return new BPromise(function(_0x494216,_0xf6602a){return client[_0x2aab('0xa')](_0x276906,_0x2970cb)[_0x2aab('0xb')](function(_0x5d47ad){logger[_0x2aab('0xc')](_0x2aab('0xd'),_0x4fe8a5,'request\x20sent');logger['debug'](_0x2aab('0xe'),_0x4fe8a5,_0x2aab('0xf'),JSON['stringify'](_0x5d47ad));if(_0x5d47ad[_0x2aab('0x10')]){if(_0x5d47ad[_0x2aab('0x10')][_0x2aab('0x11')]===0x1f4){logger['error'](_0x2aab('0xd'),_0x4fe8a5,_0x5d47ad[_0x2aab('0x10')][_0x2aab('0x12')]);return _0xf6602a(_0x5d47ad[_0x2aab('0x10')][_0x2aab('0x12')]);}logger[_0x2aab('0x10')]('Trunk,\x20%s,\x20%s',_0x4fe8a5,_0x5d47ad['error'][_0x2aab('0x12')]);return _0x494216(_0x5d47ad['error']['message']);}else{logger[_0x2aab('0xc')](_0x2aab('0xd'),_0x4fe8a5,_0x2aab('0xf'));_0x494216(_0x5d47ad[_0x2aab('0x13')][_0x2aab('0x12')]);}})[_0x2aab('0x14')](function(_0x543ca0){logger[_0x2aab('0x10')]('Trunk,\x20%s,\x20%s',_0x4fe8a5,_0x543ca0);_0xf6602a(_0x543ca0);});});}exports[_0x2aab('0x15')]=function(_0x332d6b){var _0x1baf22=this;return new Promise(function(_0x10af82,_0x9b5ca){return db[_0x2aab('0x16')][_0x2aab('0x17')]({'raw':_0x332d6b[_0x2aab('0x18')]?_0x332d6b[_0x2aab('0x18')][_0x2aab('0x19')]===undefined?!![]:![]:!![],'where':_0x332d6b[_0x2aab('0x18')]?_0x332d6b[_0x2aab('0x18')][_0x2aab('0x1a')]||null:null,'attributes':_0x332d6b[_0x2aab('0x18')]?_0x332d6b[_0x2aab('0x18')][_0x2aab('0x1b')]||null:null,'limit':_0x332d6b[_0x2aab('0x18')]?_0x332d6b[_0x2aab('0x18')][_0x2aab('0x1c')]||null:null,'include':_0x332d6b[_0x2aab('0x18')]?_0x332d6b['options'][_0x2aab('0x1d')]?_[_0x2aab('0x1e')](_0x332d6b[_0x2aab('0x18')]['include'],function(_0x163a50){return{'model':db[_0x163a50[_0x2aab('0x1f')]],'as':_0x163a50['as'],'attributes':_0x163a50[_0x2aab('0x1b')],'include':_0x163a50[_0x2aab('0x1d')]?_[_0x2aab('0x1e')](_0x163a50['include'],function(_0x429481){return{'model':db[_0x429481[_0x2aab('0x1f')]],'as':_0x429481['as'],'attributes':_0x429481[_0x2aab('0x1b')],'include':_0x429481[_0x2aab('0x1d')]?_['map'](_0x429481[_0x2aab('0x1d')],function(_0x117bbb){return{'model':db[_0x117bbb['model']],'as':_0x117bbb['as'],'attributes':_0x117bbb[_0x2aab('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x2aab('0xb')](function(_0x86cbd3){logger[_0x2aab('0xc')]('GetTrunk',_0x332d6b);logger['debug'](_0x2aab('0x15'),_0x332d6b,JSON[_0x2aab('0x20')](_0x86cbd3));_0x10af82(_0x86cbd3);})[_0x2aab('0x14')](function(_0x308ceb){logger[_0x2aab('0x10')](_0x2aab('0x15'),_0x308ceb[_0x2aab('0x12')],_0x332d6b);_0x9b5ca(_0x1baf22[_0x2aab('0x10')](0x1f4,_0x308ceb[_0x2aab('0x12')]));});});};exports[_0x2aab('0x21')]=function(_0x4233ac){var _0x5b53a6=this;return new Promise(function(_0x150676,_0x325cb9){return db[_0x2aab('0x16')][_0x2aab('0x22')]({'raw':_0x4233ac['options']?_0x4233ac[_0x2aab('0x18')][_0x2aab('0x19')]===undefined?!![]:![]:!![],'where':_0x4233ac[_0x2aab('0x18')]?_0x4233ac[_0x2aab('0x18')][_0x2aab('0x1a')]||null:null,'attributes':_0x4233ac['options']?_0x4233ac[_0x2aab('0x18')]['attributes']||null:null,'include':_0x4233ac[_0x2aab('0x18')]?_0x4233ac[_0x2aab('0x18')][_0x2aab('0x1d')]?_[_0x2aab('0x1e')](_0x4233ac['options'][_0x2aab('0x1d')],function(_0x48d63a){return{'model':db[_0x48d63a[_0x2aab('0x1f')]],'as':_0x48d63a['as'],'attributes':_0x48d63a[_0x2aab('0x1b')],'include':_0x48d63a[_0x2aab('0x1d')]?_[_0x2aab('0x1e')](_0x48d63a[_0x2aab('0x1d')],function(_0x458d86){return{'model':db[_0x458d86[_0x2aab('0x1f')]],'as':_0x458d86['as'],'attributes':_0x458d86[_0x2aab('0x1b')],'include':_0x458d86[_0x2aab('0x1d')]?_[_0x2aab('0x1e')](_0x458d86[_0x2aab('0x1d')],function(_0x591df6){return{'model':db[_0x591df6[_0x2aab('0x1f')]],'as':_0x591df6['as'],'attributes':_0x591df6[_0x2aab('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x4ee39f){logger[_0x2aab('0xc')](_0x2aab('0x21'),_0x4233ac);logger[_0x2aab('0x23')]('ShowTrunk',_0x4233ac,JSON['stringify'](_0x4ee39f));_0x150676(_0x4ee39f);})[_0x2aab('0x14')](function(_0x2377eb){logger[_0x2aab('0x10')]('ShowTrunk',_0x2377eb['message'],_0x4233ac);_0x325cb9(_0x5b53a6['error'](0x1f4,_0x2377eb[_0x2aab('0x12')]));});});};