8ac2f785cb994768b48d2df78677ef44b1745955
[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 _0xafe8=['limit','include','map','model','GetTrunk','catch','ShowTrunk','find','lodash','util','moment','bluebird','ioredis','../../config/utils','../../config/environment','jayson/promise','client','http','request','then','info','Trunk,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','Trunk','findAll','options','raw','where','attributes'];(function(_0x54b062,_0x264bb5){var _0x255e41=function(_0x3c7e6f){while(--_0x3c7e6f){_0x54b062['push'](_0x54b062['shift']());}};_0x255e41(++_0x264bb5);}(_0xafe8,0x166));var _0x8afe=function(_0x39cad6,_0x1edf41){_0x39cad6=_0x39cad6-0x0;var _0x5a82f2=_0xafe8[_0x39cad6];return _0x5a82f2;};'use strict';var _=require(_0x8afe('0x0'));var util=require(_0x8afe('0x1'));var moment=require(_0x8afe('0x2'));var BPromise=require(_0x8afe('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x8afe('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x8afe('0x5'));var logger=require('../../config/logger')('rpc');var config=require(_0x8afe('0x6'));var jayson=require(_0x8afe('0x7'));var client=jayson[_0x8afe('0x8')][_0x8afe('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x4fdb36,_0x4c2db3,_0x1f57dc){return new BPromise(function(_0x379abe,_0x5457bb){return client[_0x8afe('0xa')](_0x4fdb36,_0x1f57dc)[_0x8afe('0xb')](function(_0x3fc62c){logger[_0x8afe('0xc')](_0x8afe('0xd'),_0x4c2db3,_0x8afe('0xe'));logger[_0x8afe('0xf')]('Trunk,\x20%s,\x20%s,\x20%s',_0x4c2db3,_0x8afe('0xe'),JSON[_0x8afe('0x10')](_0x3fc62c));if(_0x3fc62c[_0x8afe('0x11')]){if(_0x3fc62c[_0x8afe('0x11')][_0x8afe('0x12')]===0x1f4){logger[_0x8afe('0x11')](_0x8afe('0xd'),_0x4c2db3,_0x3fc62c[_0x8afe('0x11')][_0x8afe('0x13')]);return _0x5457bb(_0x3fc62c[_0x8afe('0x11')]['message']);}logger[_0x8afe('0x11')](_0x8afe('0xd'),_0x4c2db3,_0x3fc62c[_0x8afe('0x11')][_0x8afe('0x13')]);return _0x379abe(_0x3fc62c[_0x8afe('0x11')][_0x8afe('0x13')]);}else{logger['info'](_0x8afe('0xd'),_0x4c2db3,_0x8afe('0xe'));_0x379abe(_0x3fc62c[_0x8afe('0x14')][_0x8afe('0x13')]);}})['catch'](function(_0x5c2cea){logger[_0x8afe('0x11')](_0x8afe('0xd'),_0x4c2db3,_0x5c2cea);_0x5457bb(_0x5c2cea);});});}exports['GetTrunk']=function(_0x76ba11){var _0x1257bb=this;return new Promise(function(_0x20314e,_0x219e63){return db[_0x8afe('0x15')][_0x8afe('0x16')]({'raw':_0x76ba11['options']?_0x76ba11[_0x8afe('0x17')][_0x8afe('0x18')]===undefined?!![]:![]:!![],'where':_0x76ba11[_0x8afe('0x17')]?_0x76ba11[_0x8afe('0x17')][_0x8afe('0x19')]||null:null,'attributes':_0x76ba11[_0x8afe('0x17')]?_0x76ba11[_0x8afe('0x17')][_0x8afe('0x1a')]||null:null,'limit':_0x76ba11['options']?_0x76ba11['options'][_0x8afe('0x1b')]||null:null,'include':_0x76ba11[_0x8afe('0x17')]?_0x76ba11[_0x8afe('0x17')][_0x8afe('0x1c')]?_[_0x8afe('0x1d')](_0x76ba11[_0x8afe('0x17')][_0x8afe('0x1c')],function(_0x320c0f){return{'model':db[_0x320c0f[_0x8afe('0x1e')]],'as':_0x320c0f['as'],'attributes':_0x320c0f['attributes'],'include':_0x320c0f[_0x8afe('0x1c')]?_[_0x8afe('0x1d')](_0x320c0f[_0x8afe('0x1c')],function(_0x1c0bc0){return{'model':db[_0x1c0bc0[_0x8afe('0x1e')]],'as':_0x1c0bc0['as'],'attributes':_0x1c0bc0['attributes'],'include':_0x1c0bc0['include']?_[_0x8afe('0x1d')](_0x1c0bc0['include'],function(_0x2554b0){return{'model':db[_0x2554b0[_0x8afe('0x1e')]],'as':_0x2554b0['as'],'attributes':_0x2554b0[_0x8afe('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x8afe('0xb')](function(_0x1c34fb){logger[_0x8afe('0xc')](_0x8afe('0x1f'),_0x76ba11);logger['debug'](_0x8afe('0x1f'),_0x76ba11,JSON[_0x8afe('0x10')](_0x1c34fb));_0x20314e(_0x1c34fb);})[_0x8afe('0x20')](function(_0x4e01b0){logger['error'](_0x8afe('0x1f'),_0x4e01b0[_0x8afe('0x13')],_0x76ba11);_0x219e63(_0x1257bb[_0x8afe('0x11')](0x1f4,_0x4e01b0[_0x8afe('0x13')]));});});};exports[_0x8afe('0x21')]=function(_0x2d281c){var _0x435b04=this;return new Promise(function(_0xd2d8b7,_0x461199){return db[_0x8afe('0x15')][_0x8afe('0x22')]({'raw':_0x2d281c['options']?_0x2d281c[_0x8afe('0x17')][_0x8afe('0x18')]===undefined?!![]:![]:!![],'where':_0x2d281c[_0x8afe('0x17')]?_0x2d281c[_0x8afe('0x17')]['where']||null:null,'attributes':_0x2d281c[_0x8afe('0x17')]?_0x2d281c[_0x8afe('0x17')][_0x8afe('0x1a')]||null:null,'include':_0x2d281c[_0x8afe('0x17')]?_0x2d281c['options'][_0x8afe('0x1c')]?_[_0x8afe('0x1d')](_0x2d281c['options']['include'],function(_0x484297){return{'model':db[_0x484297['model']],'as':_0x484297['as'],'attributes':_0x484297[_0x8afe('0x1a')],'include':_0x484297[_0x8afe('0x1c')]?_[_0x8afe('0x1d')](_0x484297['include'],function(_0x3e9c6e){return{'model':db[_0x3e9c6e['model']],'as':_0x3e9c6e['as'],'attributes':_0x3e9c6e['attributes'],'include':_0x3e9c6e['include']?_[_0x8afe('0x1d')](_0x3e9c6e[_0x8afe('0x1c')],function(_0xa06687){return{'model':db[_0xa06687[_0x8afe('0x1e')]],'as':_0xa06687['as'],'attributes':_0xa06687[_0x8afe('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x8afe('0xb')](function(_0x3e27bf){logger[_0x8afe('0xc')](_0x8afe('0x21'),_0x2d281c);logger[_0x8afe('0xf')](_0x8afe('0x21'),_0x2d281c,JSON[_0x8afe('0x10')](_0x3e27bf));_0xd2d8b7(_0x3e27bf);})['catch'](function(_0x1c657){logger['error'](_0x8afe('0x21'),_0x1c657[_0x8afe('0x13')],_0x2d281c);_0x461199(_0x435b04['error'](0x1f4,_0x1c657[_0x8afe('0x13')]));});});};