2d319bf397f4917a23e613584679e42137a7a4fe
[motion2.git] / server / api / voiceExtension / voiceExtension.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 _0xba34=['../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./voiceExtension.socket','register','then','VoiceExtension,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','info','result','catch','GetVoiceExtension','findAll','options','raw','limit','include','map','model','attributes','lodash','util','moment','bluebird','randomstring','../../config/logger','rpc'];(function(_0xa2049b,_0x7eeb1e){var _0x2fd615=function(_0x7dbb84){while(--_0x7dbb84){_0xa2049b['push'](_0xa2049b['shift']());}};_0x2fd615(++_0x7eeb1e);}(_0xba34,0x119));var _0x4ba3=function(_0xfc29d9,_0x256414){_0xfc29d9=_0xfc29d9-0x0;var _0x50b39b=_0xba34[_0xfc29d9];return _0x50b39b;};'use strict';var _=require(_0x4ba3('0x0'));var util=require(_0x4ba3('0x1'));var moment=require(_0x4ba3('0x2'));var BPromise=require(_0x4ba3('0x3'));var rs=require(_0x4ba3('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x4ba3('0x5'))(_0x4ba3('0x6'));var config=require(_0x4ba3('0x7'));var jayson=require(_0x4ba3('0x8'));var client=jayson[_0x4ba3('0x9')][_0x4ba3('0xa')]({'port':0x232a});config[_0x4ba3('0xb')]=_['defaults'](config[_0x4ba3('0xb')],{'host':_0x4ba3('0xc'),'port':0x18eb});var socket=require(_0x4ba3('0xd'))(new Redis(config[_0x4ba3('0xb')]));require(_0x4ba3('0xe'))[_0x4ba3('0xf')](socket);function respondWithRpcPromise(_0x292f58,_0x3f653c,_0x2ed106){return new BPromise(function(_0x14ebf2,_0x2d215b){return client['request'](_0x292f58,_0x2ed106)[_0x4ba3('0x10')](function(_0x9071){logger['info'](_0x4ba3('0x11'),_0x3f653c,'request\x20sent');logger[_0x4ba3('0x12')]('VoiceExtension,\x20%s,\x20%s,\x20%s',_0x3f653c,_0x4ba3('0x13'),JSON[_0x4ba3('0x14')](_0x9071));if(_0x9071[_0x4ba3('0x15')]){if(_0x9071[_0x4ba3('0x15')][_0x4ba3('0x16')]===0x1f4){logger[_0x4ba3('0x15')](_0x4ba3('0x11'),_0x3f653c,_0x9071[_0x4ba3('0x15')][_0x4ba3('0x17')]);return _0x2d215b(_0x9071[_0x4ba3('0x15')][_0x4ba3('0x17')]);}logger[_0x4ba3('0x15')](_0x4ba3('0x11'),_0x3f653c,_0x9071[_0x4ba3('0x15')][_0x4ba3('0x17')]);return _0x14ebf2(_0x9071[_0x4ba3('0x15')]['message']);}else{logger[_0x4ba3('0x18')](_0x4ba3('0x11'),_0x3f653c,_0x4ba3('0x13'));_0x14ebf2(_0x9071[_0x4ba3('0x19')]['message']);}})[_0x4ba3('0x1a')](function(_0xe4eff9){logger[_0x4ba3('0x15')](_0x4ba3('0x11'),_0x3f653c,_0xe4eff9);_0x2d215b(_0xe4eff9);});});}exports[_0x4ba3('0x1b')]=function(_0x125944){var _0x4b2791=this;return new Promise(function(_0x57de6a,_0x2278b0){return db['VoiceExtension'][_0x4ba3('0x1c')]({'raw':_0x125944[_0x4ba3('0x1d')]?_0x125944[_0x4ba3('0x1d')][_0x4ba3('0x1e')]===undefined?!![]:![]:!![],'where':_0x125944[_0x4ba3('0x1d')]?_0x125944[_0x4ba3('0x1d')]['where']||null:null,'attributes':_0x125944[_0x4ba3('0x1d')]?_0x125944[_0x4ba3('0x1d')]['attributes']||null:null,'limit':_0x125944[_0x4ba3('0x1d')]?_0x125944['options'][_0x4ba3('0x1f')]||null:null,'include':_0x125944[_0x4ba3('0x1d')]?_0x125944[_0x4ba3('0x1d')][_0x4ba3('0x20')]?_[_0x4ba3('0x21')](_0x125944[_0x4ba3('0x1d')][_0x4ba3('0x20')],function(_0xe1f7d2){return{'model':db[_0xe1f7d2[_0x4ba3('0x22')]],'as':_0xe1f7d2['as'],'attributes':_0xe1f7d2[_0x4ba3('0x23')],'include':_0xe1f7d2['include']?_[_0x4ba3('0x21')](_0xe1f7d2[_0x4ba3('0x20')],function(_0x2311ed){return{'model':db[_0x2311ed['model']],'as':_0x2311ed['as'],'attributes':_0x2311ed[_0x4ba3('0x23')],'include':_0x2311ed[_0x4ba3('0x20')]?_[_0x4ba3('0x21')](_0x2311ed['include'],function(_0x10cae6){return{'model':db[_0x10cae6[_0x4ba3('0x22')]],'as':_0x10cae6['as'],'attributes':_0x10cae6[_0x4ba3('0x23')]};}):[]};}):[]};}):[]:[]})[_0x4ba3('0x10')](function(_0x4a339e){logger['info'](_0x4ba3('0x1b'),_0x125944);logger[_0x4ba3('0x12')](_0x4ba3('0x1b'),_0x125944,JSON[_0x4ba3('0x14')](_0x4a339e));_0x57de6a(_0x4a339e);})[_0x4ba3('0x1a')](function(_0x11f88f){logger['error'](_0x4ba3('0x1b'),_0x11f88f[_0x4ba3('0x17')],_0x125944);_0x2278b0(_0x4b2791[_0x4ba3('0x15')](0x1f4,_0x11f88f[_0x4ba3('0x17')]));});});};