f1fc5c5296581248994923826a54dd04769ee331
[motion2.git] / server / api / voiceQueue / voiceQueue.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 _0x25b4=['debug','VoiceQueue,\x20%s,\x20%s,\x20%s','error','code','message','VoiceQueue,\x20%s,\x20%s','result','catch','VoiceQueue','findAll','options','where','attributes','include','map','model','stringify','GetVoiceQueue','ShowVoiceQueue','find','raw','then','lodash','util','bluebird','ioredis','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','./voiceQueue.socket','register','request','info','request\x20sent'];(function(_0x1aa9c3,_0x53483d){var _0x29403a=function(_0x24d40c){while(--_0x24d40c){_0x1aa9c3['push'](_0x1aa9c3['shift']());}};_0x29403a(++_0x53483d);}(_0x25b4,0xd4));var _0x425b=function(_0x35b7d4,_0x5a5c43){_0x35b7d4=_0x35b7d4-0x0;var _0x4e8cee=_0x25b4[_0x35b7d4];return _0x4e8cee;};'use strict';var _=require(_0x425b('0x0'));var util=require(_0x425b('0x1'));var moment=require('moment');var BPromise=require(_0x425b('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x425b('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x425b('0x4'))(_0x425b('0x5'));var config=require(_0x425b('0x6'));var jayson=require(_0x425b('0x7'));var client=jayson[_0x425b('0x8')]['http']({'port':0x232a});config[_0x425b('0x9')]=_[_0x425b('0xa')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x425b('0x9')]));require(_0x425b('0xb'))[_0x425b('0xc')](socket);function respondWithRpcPromise(_0x5e00d5,_0x3c4ed6,_0x396bb1){return new BPromise(function(_0x55e08c,_0x1d79dd){return client[_0x425b('0xd')](_0x5e00d5,_0x396bb1)['then'](function(_0x188c03){logger[_0x425b('0xe')]('VoiceQueue,\x20%s,\x20%s',_0x3c4ed6,_0x425b('0xf'));logger[_0x425b('0x10')](_0x425b('0x11'),_0x3c4ed6,_0x425b('0xf'),JSON['stringify'](_0x188c03));if(_0x188c03[_0x425b('0x12')]){if(_0x188c03['error'][_0x425b('0x13')]===0x1f4){logger[_0x425b('0x12')]('VoiceQueue,\x20%s,\x20%s',_0x3c4ed6,_0x188c03[_0x425b('0x12')][_0x425b('0x14')]);return _0x1d79dd(_0x188c03['error'][_0x425b('0x14')]);}logger[_0x425b('0x12')](_0x425b('0x15'),_0x3c4ed6,_0x188c03[_0x425b('0x12')][_0x425b('0x14')]);return _0x55e08c(_0x188c03[_0x425b('0x12')]['message']);}else{logger[_0x425b('0xe')](_0x425b('0x15'),_0x3c4ed6,'request\x20sent');_0x55e08c(_0x188c03[_0x425b('0x16')][_0x425b('0x14')]);}})[_0x425b('0x17')](function(_0x3f0953){logger[_0x425b('0x12')]('VoiceQueue,\x20%s,\x20%s',_0x3c4ed6,_0x3f0953);_0x1d79dd(_0x3f0953);});});}exports['GetVoiceQueue']=function(_0x124626){var _0xcb1dcb=this;return new Promise(function(_0x833cad,_0x16065d){return db[_0x425b('0x18')][_0x425b('0x19')]({'raw':_0x124626[_0x425b('0x1a')]?_0x124626[_0x425b('0x1a')]['raw']===undefined?!![]:![]:!![],'where':_0x124626['options']?_0x124626[_0x425b('0x1a')][_0x425b('0x1b')]||null:null,'attributes':_0x124626[_0x425b('0x1a')]?_0x124626['options'][_0x425b('0x1c')]||null:null,'limit':_0x124626[_0x425b('0x1a')]?_0x124626[_0x425b('0x1a')]['limit']||null:null,'include':_0x124626[_0x425b('0x1a')]?_0x124626[_0x425b('0x1a')][_0x425b('0x1d')]?_[_0x425b('0x1e')](_0x124626[_0x425b('0x1a')][_0x425b('0x1d')],function(_0x4276e8){return{'model':db[_0x4276e8['model']],'as':_0x4276e8['as'],'attributes':_0x4276e8['attributes'],'include':_0x4276e8['include']?_[_0x425b('0x1e')](_0x4276e8[_0x425b('0x1d')],function(_0x37ec10){return{'model':db[_0x37ec10[_0x425b('0x1f')]],'as':_0x37ec10['as'],'attributes':_0x37ec10['attributes'],'include':_0x37ec10[_0x425b('0x1d')]?_[_0x425b('0x1e')](_0x37ec10['include'],function(_0x100762){return{'model':db[_0x100762[_0x425b('0x1f')]],'as':_0x100762['as'],'attributes':_0x100762[_0x425b('0x1c')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x60fdcb){logger['info']('GetVoiceQueue',_0x124626);logger[_0x425b('0x10')]('GetVoiceQueue',_0x124626,JSON[_0x425b('0x20')](_0x60fdcb));_0x833cad(_0x60fdcb);})[_0x425b('0x17')](function(_0xdd5849){logger['error'](_0x425b('0x21'),_0xdd5849[_0x425b('0x14')],_0x124626);_0x16065d(_0xcb1dcb[_0x425b('0x12')](0x1f4,_0xdd5849[_0x425b('0x14')]));});});};exports[_0x425b('0x22')]=function(_0x561773){var _0x369b67=this;return new Promise(function(_0x4f081e,_0x19dcf0){return db[_0x425b('0x18')][_0x425b('0x23')]({'raw':_0x561773[_0x425b('0x1a')]?_0x561773[_0x425b('0x1a')][_0x425b('0x24')]===undefined?!![]:![]:!![],'where':_0x561773['options']?_0x561773[_0x425b('0x1a')][_0x425b('0x1b')]||null:null,'attributes':_0x561773['options']?_0x561773['options'][_0x425b('0x1c')]||null:null,'include':_0x561773['options']?_0x561773[_0x425b('0x1a')][_0x425b('0x1d')]?_[_0x425b('0x1e')](_0x561773[_0x425b('0x1a')][_0x425b('0x1d')],function(_0x4cf85a){return{'model':db[_0x4cf85a[_0x425b('0x1f')]],'as':_0x4cf85a['as'],'attributes':_0x4cf85a[_0x425b('0x1c')],'include':_0x4cf85a[_0x425b('0x1d')]?_[_0x425b('0x1e')](_0x4cf85a[_0x425b('0x1d')],function(_0x29dee5){return{'model':db[_0x29dee5[_0x425b('0x1f')]],'as':_0x29dee5['as'],'attributes':_0x29dee5['attributes'],'include':_0x29dee5[_0x425b('0x1d')]?_['map'](_0x29dee5['include'],function(_0x5847c1){return{'model':db[_0x5847c1['model']],'as':_0x5847c1['as'],'attributes':_0x5847c1[_0x425b('0x1c')]};}):[]};}):[]};}):[]:[]})[_0x425b('0x25')](function(_0x559f25){logger['info'](_0x425b('0x22'),_0x561773);logger['debug']('ShowVoiceQueue',_0x561773,JSON[_0x425b('0x20')](_0x559f25));_0x4f081e(_0x559f25);})['catch'](function(_0x26ec19){logger[_0x425b('0x12')](_0x425b('0x22'),_0x26ec19[_0x425b('0x14')],_0x561773);_0x19dcf0(_0x369b67[_0x425b('0x12')](0x1f4,_0x26ec19[_0x425b('0x14')]));});});};