d3099e6e55056b134ac19a643ff1d4c986f087df
[motion2.git] / server / api / chatQueue / chatQueue.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 _0x7bf2=['raw','where','attributes','limit','include','model','map','GetChatQueue','ShowChatQueue','find','lodash','util','bluebird','randomstring','ioredis','../../config/utils','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','ChatQueue','options'];(function(_0x465a0c,_0x19d4d5){var _0x1e202e=function(_0x27bd8a){while(--_0x27bd8a){_0x465a0c['push'](_0x465a0c['shift']());}};_0x1e202e(++_0x19d4d5);}(_0x7bf2,0xc8));var _0x27bf=function(_0x283dee,_0x4d7e06){_0x283dee=_0x283dee-0x0;var _0x5ad748=_0x7bf2[_0x283dee];return _0x5ad748;};'use strict';var _=require(_0x27bf('0x0'));var util=require(_0x27bf('0x1'));var moment=require('moment');var BPromise=require(_0x27bf('0x2'));var rs=require(_0x27bf('0x3'));var fs=require('fs');var Redis=require(_0x27bf('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x27bf('0x5'));var logger=require('../../config/logger')(_0x27bf('0x6'));var config=require(_0x27bf('0x7'));var jayson=require(_0x27bf('0x8'));var client=jayson[_0x27bf('0x9')][_0x27bf('0xa')]({'port':0x232a});config[_0x27bf('0xb')]=_[_0x27bf('0xc')](config[_0x27bf('0xb')],{'host':_0x27bf('0xd'),'port':0x18eb});var socket=require(_0x27bf('0xe'))(new Redis(config[_0x27bf('0xb')]));require('./chatQueue.socket')['register'](socket);function respondWithRpcPromise(_0x2c6544,_0x3a48a8,_0x1fb6d8){return new BPromise(function(_0x320fee,_0x2f3c38){return client['request'](_0x2c6544,_0x1fb6d8)[_0x27bf('0xf')](function(_0x462326){logger[_0x27bf('0x10')](_0x27bf('0x11'),_0x3a48a8,_0x27bf('0x12'));logger[_0x27bf('0x13')]('ChatQueue,\x20%s,\x20%s,\x20%s',_0x3a48a8,_0x27bf('0x12'),JSON[_0x27bf('0x14')](_0x462326));if(_0x462326[_0x27bf('0x15')]){if(_0x462326['error'][_0x27bf('0x16')]===0x1f4){logger[_0x27bf('0x15')](_0x27bf('0x11'),_0x3a48a8,_0x462326[_0x27bf('0x15')][_0x27bf('0x17')]);return _0x2f3c38(_0x462326['error'][_0x27bf('0x17')]);}logger['error'](_0x27bf('0x11'),_0x3a48a8,_0x462326[_0x27bf('0x15')][_0x27bf('0x17')]);return _0x320fee(_0x462326[_0x27bf('0x15')][_0x27bf('0x17')]);}else{logger[_0x27bf('0x10')](_0x27bf('0x11'),_0x3a48a8,_0x27bf('0x12'));_0x320fee(_0x462326[_0x27bf('0x18')][_0x27bf('0x17')]);}})[_0x27bf('0x19')](function(_0x19b4e3){logger[_0x27bf('0x15')](_0x27bf('0x11'),_0x3a48a8,_0x19b4e3);_0x2f3c38(_0x19b4e3);});});}exports['GetChatQueue']=function(_0x56e82d){var _0xd14bad=this;return new Promise(function(_0x64735,_0x23fbce){return db[_0x27bf('0x1a')]['findAll']({'raw':_0x56e82d[_0x27bf('0x1b')]?_0x56e82d[_0x27bf('0x1b')][_0x27bf('0x1c')]===undefined?!![]:![]:!![],'where':_0x56e82d[_0x27bf('0x1b')]?_0x56e82d[_0x27bf('0x1b')][_0x27bf('0x1d')]||null:null,'attributes':_0x56e82d[_0x27bf('0x1b')]?_0x56e82d[_0x27bf('0x1b')][_0x27bf('0x1e')]||null:null,'limit':_0x56e82d[_0x27bf('0x1b')]?_0x56e82d[_0x27bf('0x1b')][_0x27bf('0x1f')]||null:null,'include':_0x56e82d[_0x27bf('0x1b')]?_0x56e82d[_0x27bf('0x1b')][_0x27bf('0x20')]?_['map'](_0x56e82d[_0x27bf('0x1b')][_0x27bf('0x20')],function(_0x1ea48c){return{'model':db[_0x1ea48c[_0x27bf('0x21')]],'as':_0x1ea48c['as'],'attributes':_0x1ea48c[_0x27bf('0x1e')],'include':_0x1ea48c[_0x27bf('0x20')]?_[_0x27bf('0x22')](_0x1ea48c[_0x27bf('0x20')],function(_0x54635a){return{'model':db[_0x54635a[_0x27bf('0x21')]],'as':_0x54635a['as'],'attributes':_0x54635a['attributes'],'include':_0x54635a[_0x27bf('0x20')]?_[_0x27bf('0x22')](_0x54635a[_0x27bf('0x20')],function(_0x29d9b2){return{'model':db[_0x29d9b2[_0x27bf('0x21')]],'as':_0x29d9b2['as'],'attributes':_0x29d9b2[_0x27bf('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x27bf('0xf')](function(_0x16b71e){logger[_0x27bf('0x10')](_0x27bf('0x23'),_0x56e82d);logger[_0x27bf('0x13')](_0x27bf('0x23'),_0x56e82d,JSON[_0x27bf('0x14')](_0x16b71e));_0x64735(_0x16b71e);})['catch'](function(_0x52ada0){logger[_0x27bf('0x15')](_0x27bf('0x23'),_0x52ada0['message'],_0x56e82d);_0x23fbce(_0xd14bad[_0x27bf('0x15')](0x1f4,_0x52ada0['message']));});});};exports[_0x27bf('0x24')]=function(_0x2081e2){var _0x505bf0=this;return new Promise(function(_0xa8279d,_0xe72ab8){return db['ChatQueue'][_0x27bf('0x25')]({'raw':_0x2081e2['options']?_0x2081e2['options']['raw']===undefined?!![]:![]:!![],'where':_0x2081e2[_0x27bf('0x1b')]?_0x2081e2[_0x27bf('0x1b')][_0x27bf('0x1d')]||null:null,'attributes':_0x2081e2[_0x27bf('0x1b')]?_0x2081e2['options'][_0x27bf('0x1e')]||null:null,'include':_0x2081e2['options']?_0x2081e2[_0x27bf('0x1b')][_0x27bf('0x20')]?_[_0x27bf('0x22')](_0x2081e2['options'][_0x27bf('0x20')],function(_0x3cb61b){return{'model':db[_0x3cb61b[_0x27bf('0x21')]],'as':_0x3cb61b['as'],'attributes':_0x3cb61b[_0x27bf('0x1e')],'include':_0x3cb61b[_0x27bf('0x20')]?_['map'](_0x3cb61b[_0x27bf('0x20')],function(_0x2c88e5){return{'model':db[_0x2c88e5[_0x27bf('0x21')]],'as':_0x2c88e5['as'],'attributes':_0x2c88e5[_0x27bf('0x1e')],'include':_0x2c88e5[_0x27bf('0x20')]?_[_0x27bf('0x22')](_0x2c88e5[_0x27bf('0x20')],function(_0x26c68d){return{'model':db[_0x26c68d['model']],'as':_0x26c68d['as'],'attributes':_0x26c68d[_0x27bf('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x12c240){logger['info'](_0x27bf('0x24'),_0x2081e2);logger[_0x27bf('0x13')](_0x27bf('0x24'),_0x2081e2,JSON['stringify'](_0x12c240));_0xa8279d(_0x12c240);})[_0x27bf('0x19')](function(_0x344056){logger[_0x27bf('0x15')]('ShowChatQueue',_0x344056[_0x27bf('0x17')],_0x2081e2);_0xe72ab8(_0x505bf0[_0x27bf('0x15')](0x1f4,_0x344056[_0x27bf('0x17')]));});});};