Built motion from commit 85328c08.|2.5.50
[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 _0xff26=['model','find','where','ShowTrunk','util','moment','bluebird','randomstring','ioredis','../../config/logger','client','http','then','info','Trunk,\x20%s,\x20%s','request\x20sent','debug','Trunk,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','GetTrunk','findAll','options','attributes','limit','include','map'];(function(_0x1e9d6a,_0x3e5cab){var _0x222bd1=function(_0x3e9c8f){while(--_0x3e9c8f){_0x1e9d6a['push'](_0x1e9d6a['shift']());}};_0x222bd1(++_0x3e5cab);}(_0xff26,0x1b6));var _0x6ff2=function(_0x174202,_0x5c5292){_0x174202=_0x174202-0x0;var _0x4daa4a=_0xff26[_0x174202];return _0x4daa4a;};'use strict';var _=require('lodash');var util=require(_0x6ff2('0x0'));var moment=require(_0x6ff2('0x1'));var BPromise=require(_0x6ff2('0x2'));var rs=require(_0x6ff2('0x3'));var fs=require('fs');var Redis=require(_0x6ff2('0x4'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x6ff2('0x5'))('rpc');var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x6ff2('0x6')][_0x6ff2('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x5a8b5b,_0x4b1765,_0x1ae8c9){return new BPromise(function(_0x4a3f09,_0x1118e0){return client['request'](_0x5a8b5b,_0x1ae8c9)[_0x6ff2('0x8')](function(_0x26ff82){logger[_0x6ff2('0x9')](_0x6ff2('0xa'),_0x4b1765,_0x6ff2('0xb'));logger[_0x6ff2('0xc')](_0x6ff2('0xd'),_0x4b1765,_0x6ff2('0xb'),JSON[_0x6ff2('0xe')](_0x26ff82));if(_0x26ff82['error']){if(_0x26ff82['error'][_0x6ff2('0xf')]===0x1f4){logger[_0x6ff2('0x10')]('Trunk,\x20%s,\x20%s',_0x4b1765,_0x26ff82[_0x6ff2('0x10')][_0x6ff2('0x11')]);return _0x1118e0(_0x26ff82[_0x6ff2('0x10')]['message']);}logger[_0x6ff2('0x10')](_0x6ff2('0xa'),_0x4b1765,_0x26ff82[_0x6ff2('0x10')][_0x6ff2('0x11')]);return _0x4a3f09(_0x26ff82[_0x6ff2('0x10')][_0x6ff2('0x11')]);}else{logger['info'](_0x6ff2('0xa'),_0x4b1765,_0x6ff2('0xb'));_0x4a3f09(_0x26ff82[_0x6ff2('0x12')][_0x6ff2('0x11')]);}})[_0x6ff2('0x13')](function(_0x3d0049){logger[_0x6ff2('0x10')](_0x6ff2('0xa'),_0x4b1765,_0x3d0049);_0x1118e0(_0x3d0049);});});}exports[_0x6ff2('0x14')]=function(_0x50a9d8){var _0x585be5=this;return new Promise(function(_0x53377e,_0x5267b0){return db['Trunk'][_0x6ff2('0x15')]({'raw':_0x50a9d8[_0x6ff2('0x16')]?_0x50a9d8[_0x6ff2('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x50a9d8[_0x6ff2('0x16')]?_0x50a9d8['options']['where']||null:null,'attributes':_0x50a9d8[_0x6ff2('0x16')]?_0x50a9d8[_0x6ff2('0x16')][_0x6ff2('0x17')]||null:null,'limit':_0x50a9d8[_0x6ff2('0x16')]?_0x50a9d8[_0x6ff2('0x16')][_0x6ff2('0x18')]||null:null,'include':_0x50a9d8[_0x6ff2('0x16')]?_0x50a9d8[_0x6ff2('0x16')][_0x6ff2('0x19')]?_[_0x6ff2('0x1a')](_0x50a9d8[_0x6ff2('0x16')][_0x6ff2('0x19')],function(_0x2ce554){return{'model':db[_0x2ce554['model']],'as':_0x2ce554['as'],'attributes':_0x2ce554['attributes'],'include':_0x2ce554['include']?_[_0x6ff2('0x1a')](_0x2ce554[_0x6ff2('0x19')],function(_0x3a1eee){return{'model':db[_0x3a1eee[_0x6ff2('0x1b')]],'as':_0x3a1eee['as'],'attributes':_0x3a1eee[_0x6ff2('0x17')],'include':_0x3a1eee[_0x6ff2('0x19')]?_[_0x6ff2('0x1a')](_0x3a1eee['include'],function(_0xdd4b8c){return{'model':db[_0xdd4b8c[_0x6ff2('0x1b')]],'as':_0xdd4b8c['as'],'attributes':_0xdd4b8c[_0x6ff2('0x17')]};}):[]};}):[]};}):[]:[]})['then'](function(_0xef8dc1){logger[_0x6ff2('0x9')](_0x6ff2('0x14'),_0x50a9d8);logger['debug'](_0x6ff2('0x14'),_0x50a9d8,JSON['stringify'](_0xef8dc1));_0x53377e(_0xef8dc1);})[_0x6ff2('0x13')](function(_0x1040fd){logger[_0x6ff2('0x10')](_0x6ff2('0x14'),_0x1040fd[_0x6ff2('0x11')],_0x50a9d8);_0x5267b0(_0x585be5[_0x6ff2('0x10')](0x1f4,_0x1040fd['message']));});});};exports['ShowTrunk']=function(_0x55b67b){var _0x5f5b09=this;return new Promise(function(_0x546c56,_0x589c22){return db['Trunk'][_0x6ff2('0x1c')]({'raw':_0x55b67b['options']?_0x55b67b[_0x6ff2('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x55b67b[_0x6ff2('0x16')]?_0x55b67b[_0x6ff2('0x16')][_0x6ff2('0x1d')]||null:null,'attributes':_0x55b67b[_0x6ff2('0x16')]?_0x55b67b[_0x6ff2('0x16')][_0x6ff2('0x17')]||null:null,'include':_0x55b67b['options']?_0x55b67b[_0x6ff2('0x16')][_0x6ff2('0x19')]?_[_0x6ff2('0x1a')](_0x55b67b[_0x6ff2('0x16')][_0x6ff2('0x19')],function(_0x33dc74){return{'model':db[_0x33dc74[_0x6ff2('0x1b')]],'as':_0x33dc74['as'],'attributes':_0x33dc74[_0x6ff2('0x17')],'include':_0x33dc74['include']?_['map'](_0x33dc74[_0x6ff2('0x19')],function(_0x484a1c){return{'model':db[_0x484a1c[_0x6ff2('0x1b')]],'as':_0x484a1c['as'],'attributes':_0x484a1c[_0x6ff2('0x17')],'include':_0x484a1c['include']?_[_0x6ff2('0x1a')](_0x484a1c[_0x6ff2('0x19')],function(_0x5f3248){return{'model':db[_0x5f3248[_0x6ff2('0x1b')]],'as':_0x5f3248['as'],'attributes':_0x5f3248['attributes']};}):[]};}):[]};}):[]:[]})[_0x6ff2('0x8')](function(_0x1ca6ab){logger[_0x6ff2('0x9')]('ShowTrunk',_0x55b67b);logger[_0x6ff2('0xc')](_0x6ff2('0x1e'),_0x55b67b,JSON['stringify'](_0x1ca6ab));_0x546c56(_0x1ca6ab);})['catch'](function(_0x1ec444){logger[_0x6ff2('0x10')](_0x6ff2('0x1e'),_0x1ec444['message'],_0x55b67b);_0x589c22(_0x5f5b09[_0x6ff2('0x10')](0x1f4,_0x1ec444['message']));});});};