66759720fb5d4242fc90d3ebed963a7b7533167b
[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 _0x6130=['options','raw','where','attributes','limit','map','include','model','stringify','ShowVoiceQueue','VoiceQueue','find','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','defaults','localhost','socket.io-emitter','redis','request','then','info','VoiceQueue,\x20%s,\x20%s','request\x20sent','debug','VoiceQueue,\x20%s,\x20%s,\x20%s','error','message','result','catch','GetVoiceQueue'];(function(_0xdeae0f,_0x170034){var _0x3150a9=function(_0x48ec2d){while(--_0x48ec2d){_0xdeae0f['push'](_0xdeae0f['shift']());}};_0x3150a9(++_0x170034);}(_0x6130,0x102));var _0x0613=function(_0x341e0f,_0x4a09d0){_0x341e0f=_0x341e0f-0x0;var _0x59555a=_0x6130[_0x341e0f];return _0x59555a;};'use strict';var _=require(_0x0613('0x0'));var util=require(_0x0613('0x1'));var moment=require(_0x0613('0x2'));var BPromise=require(_0x0613('0x3'));var rs=require(_0x0613('0x4'));var fs=require('fs');var Redis=require(_0x0613('0x5'));var db=require(_0x0613('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0x0613('0x7'))(_0x0613('0x8'));var config=require(_0x0613('0x9'));var jayson=require(_0x0613('0xa'));var client=jayson[_0x0613('0xb')][_0x0613('0xc')]({'port':0x232a});config['redis']=_[_0x0613('0xd')](config['redis'],{'host':_0x0613('0xe'),'port':0x18eb});var socket=require(_0x0613('0xf'))(new Redis(config[_0x0613('0x10')]));require('./voiceQueue.socket')['register'](socket);function respondWithRpcPromise(_0x581037,_0xdf271d,_0x4c2855){return new BPromise(function(_0x30cbd6,_0x5ae5d5){return client[_0x0613('0x11')](_0x581037,_0x4c2855)[_0x0613('0x12')](function(_0x38e79a){logger[_0x0613('0x13')](_0x0613('0x14'),_0xdf271d,_0x0613('0x15'));logger[_0x0613('0x16')](_0x0613('0x17'),_0xdf271d,_0x0613('0x15'),JSON['stringify'](_0x38e79a));if(_0x38e79a[_0x0613('0x18')]){if(_0x38e79a[_0x0613('0x18')]['code']===0x1f4){logger[_0x0613('0x18')](_0x0613('0x14'),_0xdf271d,_0x38e79a[_0x0613('0x18')][_0x0613('0x19')]);return _0x5ae5d5(_0x38e79a[_0x0613('0x18')][_0x0613('0x19')]);}logger[_0x0613('0x18')](_0x0613('0x14'),_0xdf271d,_0x38e79a[_0x0613('0x18')]['message']);return _0x30cbd6(_0x38e79a[_0x0613('0x18')][_0x0613('0x19')]);}else{logger['info']('VoiceQueue,\x20%s,\x20%s',_0xdf271d,_0x0613('0x15'));_0x30cbd6(_0x38e79a[_0x0613('0x1a')][_0x0613('0x19')]);}})[_0x0613('0x1b')](function(_0x32fefd){logger[_0x0613('0x18')](_0x0613('0x14'),_0xdf271d,_0x32fefd);_0x5ae5d5(_0x32fefd);});});}exports[_0x0613('0x1c')]=function(_0x4f646c){var _0x1814c2=this;return new Promise(function(_0x22ea46,_0x329960){return db['VoiceQueue']['findAll']({'raw':_0x4f646c['options']?_0x4f646c[_0x0613('0x1d')][_0x0613('0x1e')]===undefined?!![]:![]:!![],'where':_0x4f646c[_0x0613('0x1d')]?_0x4f646c['options'][_0x0613('0x1f')]||null:null,'attributes':_0x4f646c[_0x0613('0x1d')]?_0x4f646c[_0x0613('0x1d')][_0x0613('0x20')]||null:null,'limit':_0x4f646c[_0x0613('0x1d')]?_0x4f646c[_0x0613('0x1d')][_0x0613('0x21')]||null:null,'include':_0x4f646c[_0x0613('0x1d')]?_0x4f646c['options']['include']?_[_0x0613('0x22')](_0x4f646c[_0x0613('0x1d')][_0x0613('0x23')],function(_0x4c0f4f){return{'model':db[_0x4c0f4f[_0x0613('0x24')]],'as':_0x4c0f4f['as'],'attributes':_0x4c0f4f[_0x0613('0x20')],'include':_0x4c0f4f[_0x0613('0x23')]?_['map'](_0x4c0f4f[_0x0613('0x23')],function(_0x5f499b){return{'model':db[_0x5f499b['model']],'as':_0x5f499b['as'],'attributes':_0x5f499b['attributes'],'include':_0x5f499b[_0x0613('0x23')]?_['map'](_0x5f499b[_0x0613('0x23')],function(_0x5a8019){return{'model':db[_0x5a8019[_0x0613('0x24')]],'as':_0x5a8019['as'],'attributes':_0x5a8019[_0x0613('0x20')]};}):[]};}):[]};}):[]:[]})['then'](function(_0xa83a46){logger[_0x0613('0x13')](_0x0613('0x1c'),_0x4f646c);logger[_0x0613('0x16')](_0x0613('0x1c'),_0x4f646c,JSON[_0x0613('0x25')](_0xa83a46));_0x22ea46(_0xa83a46);})[_0x0613('0x1b')](function(_0x4dff3b){logger[_0x0613('0x18')]('GetVoiceQueue',_0x4dff3b[_0x0613('0x19')],_0x4f646c);_0x329960(_0x1814c2[_0x0613('0x18')](0x1f4,_0x4dff3b[_0x0613('0x19')]));});});};exports[_0x0613('0x26')]=function(_0x644d8f){var _0x1c491b=this;return new Promise(function(_0x112f57,_0x59c9a7){return db[_0x0613('0x27')][_0x0613('0x28')]({'raw':_0x644d8f[_0x0613('0x1d')]?_0x644d8f[_0x0613('0x1d')][_0x0613('0x1e')]===undefined?!![]:![]:!![],'where':_0x644d8f[_0x0613('0x1d')]?_0x644d8f['options'][_0x0613('0x1f')]||null:null,'attributes':_0x644d8f['options']?_0x644d8f[_0x0613('0x1d')][_0x0613('0x20')]||null:null,'include':_0x644d8f['options']?_0x644d8f[_0x0613('0x1d')][_0x0613('0x23')]?_['map'](_0x644d8f[_0x0613('0x1d')]['include'],function(_0x29e7bc){return{'model':db[_0x29e7bc[_0x0613('0x24')]],'as':_0x29e7bc['as'],'attributes':_0x29e7bc[_0x0613('0x20')],'include':_0x29e7bc[_0x0613('0x23')]?_[_0x0613('0x22')](_0x29e7bc[_0x0613('0x23')],function(_0x91ebe){return{'model':db[_0x91ebe[_0x0613('0x24')]],'as':_0x91ebe['as'],'attributes':_0x91ebe[_0x0613('0x20')],'include':_0x91ebe['include']?_[_0x0613('0x22')](_0x91ebe[_0x0613('0x23')],function(_0x3eabac){return{'model':db[_0x3eabac[_0x0613('0x24')]],'as':_0x3eabac['as'],'attributes':_0x3eabac[_0x0613('0x20')]};}):[]};}):[]};}):[]:[]})[_0x0613('0x12')](function(_0xdcc236){logger[_0x0613('0x13')]('ShowVoiceQueue',_0x644d8f);logger[_0x0613('0x16')](_0x0613('0x26'),_0x644d8f,JSON[_0x0613('0x25')](_0xdcc236));_0x112f57(_0xdcc236);})[_0x0613('0x1b')](function(_0x3381db){logger[_0x0613('0x18')](_0x0613('0x26'),_0x3381db[_0x0613('0x19')],_0x644d8f);_0x59c9a7(_0x1c491b['error'](0x1f4,_0x3381db['message']));});});};