7d46d54acc66c5b3069d89e310378e1dff67548e
[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 _0x6351=['ChatQueue,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','catch','GetChatQueue','ChatQueue','options','where','attributes','limit','include','map','model','then','ShowChatQueue','find','raw','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','localhost','./chatQueue.socket','request'];(function(_0x2b90e4,_0x47049c){var _0x42c402=function(_0x48c5c0){while(--_0x48c5c0){_0x2b90e4['push'](_0x2b90e4['shift']());}};_0x42c402(++_0x47049c);}(_0x6351,0x12f));var _0x1635=function(_0x351865,_0x595cbe){_0x351865=_0x351865-0x0;var _0x28e5ff=_0x6351[_0x351865];return _0x28e5ff;};'use strict';var _=require(_0x1635('0x0'));var util=require(_0x1635('0x1'));var moment=require(_0x1635('0x2'));var BPromise=require(_0x1635('0x3'));var rs=require(_0x1635('0x4'));var fs=require('fs');var Redis=require(_0x1635('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x1635('0x6'));var logger=require(_0x1635('0x7'))(_0x1635('0x8'));var config=require(_0x1635('0x9'));var jayson=require(_0x1635('0xa'));var client=jayson[_0x1635('0xb')][_0x1635('0xc')]({'port':0x232a});config[_0x1635('0xd')]=_['defaults'](config[_0x1635('0xd')],{'host':_0x1635('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x1635('0xf'))['register'](socket);function respondWithRpcPromise(_0x171ac7,_0xf373ff,_0x4f109e){return new BPromise(function(_0x114dc4,_0xfcb242){return client[_0x1635('0x10')](_0x171ac7,_0x4f109e)['then'](function(_0x59a50f){logger['info'](_0x1635('0x11'),_0xf373ff,_0x1635('0x12'));logger[_0x1635('0x13')]('ChatQueue,\x20%s,\x20%s,\x20%s',_0xf373ff,'request\x20sent',JSON[_0x1635('0x14')](_0x59a50f));if(_0x59a50f['error']){if(_0x59a50f[_0x1635('0x15')][_0x1635('0x16')]===0x1f4){logger[_0x1635('0x15')](_0x1635('0x11'),_0xf373ff,_0x59a50f[_0x1635('0x15')]['message']);return _0xfcb242(_0x59a50f['error'][_0x1635('0x17')]);}logger[_0x1635('0x15')]('ChatQueue,\x20%s,\x20%s',_0xf373ff,_0x59a50f['error'][_0x1635('0x17')]);return _0x114dc4(_0x59a50f[_0x1635('0x15')][_0x1635('0x17')]);}else{logger[_0x1635('0x18')](_0x1635('0x11'),_0xf373ff,_0x1635('0x12'));_0x114dc4(_0x59a50f[_0x1635('0x19')][_0x1635('0x17')]);}})[_0x1635('0x1a')](function(_0x5e19a3){logger[_0x1635('0x15')](_0x1635('0x11'),_0xf373ff,_0x5e19a3);_0xfcb242(_0x5e19a3);});});}exports[_0x1635('0x1b')]=function(_0x4e1534){var _0x1b4c92=this;return new Promise(function(_0x57c947,_0x29fbbc){return db[_0x1635('0x1c')]['findAll']({'raw':_0x4e1534['options']?_0x4e1534[_0x1635('0x1d')]['raw']===undefined?!![]:![]:!![],'where':_0x4e1534['options']?_0x4e1534['options'][_0x1635('0x1e')]||null:null,'attributes':_0x4e1534[_0x1635('0x1d')]?_0x4e1534[_0x1635('0x1d')][_0x1635('0x1f')]||null:null,'limit':_0x4e1534[_0x1635('0x1d')]?_0x4e1534['options'][_0x1635('0x20')]||null:null,'include':_0x4e1534[_0x1635('0x1d')]?_0x4e1534[_0x1635('0x1d')][_0x1635('0x21')]?_[_0x1635('0x22')](_0x4e1534[_0x1635('0x1d')]['include'],function(_0x21a7ac){return{'model':db[_0x21a7ac['model']],'as':_0x21a7ac['as'],'attributes':_0x21a7ac[_0x1635('0x1f')],'include':_0x21a7ac[_0x1635('0x21')]?_[_0x1635('0x22')](_0x21a7ac['include'],function(_0x4aec56){return{'model':db[_0x4aec56[_0x1635('0x23')]],'as':_0x4aec56['as'],'attributes':_0x4aec56['attributes'],'include':_0x4aec56[_0x1635('0x21')]?_[_0x1635('0x22')](_0x4aec56[_0x1635('0x21')],function(_0x3bff45){return{'model':db[_0x3bff45[_0x1635('0x23')]],'as':_0x3bff45['as'],'attributes':_0x3bff45[_0x1635('0x1f')]};}):[]};}):[]};}):[]:[]})[_0x1635('0x24')](function(_0x57fb1e){logger[_0x1635('0x18')]('GetChatQueue',_0x4e1534);logger['debug'](_0x1635('0x1b'),_0x4e1534,JSON[_0x1635('0x14')](_0x57fb1e));_0x57c947(_0x57fb1e);})['catch'](function(_0x2c5420){logger[_0x1635('0x15')](_0x1635('0x1b'),_0x2c5420[_0x1635('0x17')],_0x4e1534);_0x29fbbc(_0x1b4c92[_0x1635('0x15')](0x1f4,_0x2c5420[_0x1635('0x17')]));});});};exports[_0x1635('0x25')]=function(_0x14333e){var _0x2121fb=this;return new Promise(function(_0x1195f5,_0x636fd9){return db[_0x1635('0x1c')][_0x1635('0x26')]({'raw':_0x14333e[_0x1635('0x1d')]?_0x14333e[_0x1635('0x1d')][_0x1635('0x27')]===undefined?!![]:![]:!![],'where':_0x14333e['options']?_0x14333e[_0x1635('0x1d')][_0x1635('0x1e')]||null:null,'attributes':_0x14333e['options']?_0x14333e[_0x1635('0x1d')][_0x1635('0x1f')]||null:null,'include':_0x14333e[_0x1635('0x1d')]?_0x14333e[_0x1635('0x1d')][_0x1635('0x21')]?_[_0x1635('0x22')](_0x14333e[_0x1635('0x1d')][_0x1635('0x21')],function(_0x2cad12){return{'model':db[_0x2cad12['model']],'as':_0x2cad12['as'],'attributes':_0x2cad12[_0x1635('0x1f')],'include':_0x2cad12[_0x1635('0x21')]?_[_0x1635('0x22')](_0x2cad12[_0x1635('0x21')],function(_0x195ee0){return{'model':db[_0x195ee0[_0x1635('0x23')]],'as':_0x195ee0['as'],'attributes':_0x195ee0[_0x1635('0x1f')],'include':_0x195ee0[_0x1635('0x21')]?_['map'](_0x195ee0[_0x1635('0x21')],function(_0x53d95b){return{'model':db[_0x53d95b[_0x1635('0x23')]],'as':_0x53d95b['as'],'attributes':_0x53d95b[_0x1635('0x1f')]};}):[]};}):[]};}):[]:[]})[_0x1635('0x24')](function(_0x57ab92){logger[_0x1635('0x18')](_0x1635('0x25'),_0x14333e);logger['debug'](_0x1635('0x25'),_0x14333e,JSON[_0x1635('0x14')](_0x57ab92));_0x1195f5(_0x57ab92);})[_0x1635('0x1a')](function(_0x565aab){logger[_0x1635('0x15')]('ShowChatQueue',_0x565aab[_0x1635('0x17')],_0x14333e);_0x636fd9(_0x2121fb[_0x1635('0x15')](0x1f4,_0x565aab[_0x1635('0x17')]));});});};