632100fc20da30fb31de6ba03d7999d32b32aa75
[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 _0xdb2b=['jayson/promise','client','http','redis','localhost','socket.io-emitter','./chatQueue.socket','register','request','info','ChatQueue,\x20%s,\x20%s','debug','ChatQueue,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','ChatQueue','findAll','options','raw','include','attributes','map','model','then','catch','GetChatQueue','ShowChatQueue','find','where','lodash','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0x47f7ec,_0x369f9d){var _0x415101=function(_0x41317a){while(--_0x41317a){_0x47f7ec['push'](_0x47f7ec['shift']());}};_0x415101(++_0x369f9d);}(_0xdb2b,0xa2));var _0xbdb2=function(_0x137ef8,_0x3384dc){_0x137ef8=_0x137ef8-0x0;var _0x3b7d28=_0xdb2b[_0x137ef8];return _0x3b7d28;};'use strict';var _=require(_0xbdb2('0x0'));var util=require('util');var moment=require(_0xbdb2('0x1'));var BPromise=require(_0xbdb2('0x2'));var rs=require(_0xbdb2('0x3'));var fs=require('fs');var Redis=require(_0xbdb2('0x4'));var db=require(_0xbdb2('0x5'))['db'];var utils=require(_0xbdb2('0x6'));var logger=require(_0xbdb2('0x7'))(_0xbdb2('0x8'));var config=require(_0xbdb2('0x9'));var jayson=require(_0xbdb2('0xa'));var client=jayson[_0xbdb2('0xb')][_0xbdb2('0xc')]({'port':0x232a});config['redis']=_['defaults'](config[_0xbdb2('0xd')],{'host':_0xbdb2('0xe'),'port':0x18eb});var socket=require(_0xbdb2('0xf'))(new Redis(config[_0xbdb2('0xd')]));require(_0xbdb2('0x10'))[_0xbdb2('0x11')](socket);function respondWithRpcPromise(_0x4cbf3b,_0xeae40,_0x4582bf){return new BPromise(function(_0x493c97,_0x209b90){return client[_0xbdb2('0x12')](_0x4cbf3b,_0x4582bf)['then'](function(_0x3fcedd){logger[_0xbdb2('0x13')](_0xbdb2('0x14'),_0xeae40,'request\x20sent');logger[_0xbdb2('0x15')](_0xbdb2('0x16'),_0xeae40,_0xbdb2('0x17'),JSON[_0xbdb2('0x18')](_0x3fcedd));if(_0x3fcedd['error']){if(_0x3fcedd[_0xbdb2('0x19')][_0xbdb2('0x1a')]===0x1f4){logger['error']('ChatQueue,\x20%s,\x20%s',_0xeae40,_0x3fcedd[_0xbdb2('0x19')][_0xbdb2('0x1b')]);return _0x209b90(_0x3fcedd[_0xbdb2('0x19')][_0xbdb2('0x1b')]);}logger[_0xbdb2('0x19')](_0xbdb2('0x14'),_0xeae40,_0x3fcedd[_0xbdb2('0x19')][_0xbdb2('0x1b')]);return _0x493c97(_0x3fcedd['error'][_0xbdb2('0x1b')]);}else{logger['info'](_0xbdb2('0x14'),_0xeae40,_0xbdb2('0x17'));_0x493c97(_0x3fcedd[_0xbdb2('0x1c')]['message']);}})['catch'](function(_0xd912eb){logger[_0xbdb2('0x19')]('ChatQueue,\x20%s,\x20%s',_0xeae40,_0xd912eb);_0x209b90(_0xd912eb);});});}exports['GetChatQueue']=function(_0x59ac40){var _0x2bb1ed=this;return new Promise(function(_0x20a754,_0x3a9629){return db[_0xbdb2('0x1d')][_0xbdb2('0x1e')]({'raw':_0x59ac40[_0xbdb2('0x1f')]?_0x59ac40['options'][_0xbdb2('0x20')]===undefined?!![]:![]:!![],'where':_0x59ac40['options']?_0x59ac40[_0xbdb2('0x1f')]['where']||null:null,'attributes':_0x59ac40[_0xbdb2('0x1f')]?_0x59ac40[_0xbdb2('0x1f')]['attributes']||null:null,'limit':_0x59ac40[_0xbdb2('0x1f')]?_0x59ac40[_0xbdb2('0x1f')]['limit']||null:null,'include':_0x59ac40[_0xbdb2('0x1f')]?_0x59ac40[_0xbdb2('0x1f')][_0xbdb2('0x21')]?_['map'](_0x59ac40['options'][_0xbdb2('0x21')],function(_0x386af6){return{'model':db[_0x386af6['model']],'as':_0x386af6['as'],'attributes':_0x386af6[_0xbdb2('0x22')],'include':_0x386af6[_0xbdb2('0x21')]?_['map'](_0x386af6['include'],function(_0x4bb221){return{'model':db[_0x4bb221['model']],'as':_0x4bb221['as'],'attributes':_0x4bb221['attributes'],'include':_0x4bb221[_0xbdb2('0x21')]?_[_0xbdb2('0x23')](_0x4bb221[_0xbdb2('0x21')],function(_0x49aace){return{'model':db[_0x49aace[_0xbdb2('0x24')]],'as':_0x49aace['as'],'attributes':_0x49aace[_0xbdb2('0x22')]};}):[]};}):[]};}):[]:[]})[_0xbdb2('0x25')](function(_0x3c3bae){logger['info']('GetChatQueue',_0x59ac40);logger['debug']('GetChatQueue',_0x59ac40,JSON[_0xbdb2('0x18')](_0x3c3bae));_0x20a754(_0x3c3bae);})[_0xbdb2('0x26')](function(_0xcc2e74){logger[_0xbdb2('0x19')](_0xbdb2('0x27'),_0xcc2e74[_0xbdb2('0x1b')],_0x59ac40);_0x3a9629(_0x2bb1ed['error'](0x1f4,_0xcc2e74['message']));});});};exports[_0xbdb2('0x28')]=function(_0x13ad0e){var _0x41c264=this;return new Promise(function(_0x2d8969,_0x58a686){return db[_0xbdb2('0x1d')][_0xbdb2('0x29')]({'raw':_0x13ad0e[_0xbdb2('0x1f')]?_0x13ad0e[_0xbdb2('0x1f')]['raw']===undefined?!![]:![]:!![],'where':_0x13ad0e[_0xbdb2('0x1f')]?_0x13ad0e[_0xbdb2('0x1f')][_0xbdb2('0x2a')]||null:null,'attributes':_0x13ad0e[_0xbdb2('0x1f')]?_0x13ad0e[_0xbdb2('0x1f')][_0xbdb2('0x22')]||null:null,'include':_0x13ad0e[_0xbdb2('0x1f')]?_0x13ad0e['options'][_0xbdb2('0x21')]?_['map'](_0x13ad0e[_0xbdb2('0x1f')][_0xbdb2('0x21')],function(_0x3ccdec){return{'model':db[_0x3ccdec[_0xbdb2('0x24')]],'as':_0x3ccdec['as'],'attributes':_0x3ccdec[_0xbdb2('0x22')],'include':_0x3ccdec[_0xbdb2('0x21')]?_['map'](_0x3ccdec[_0xbdb2('0x21')],function(_0xc53a09){return{'model':db[_0xc53a09[_0xbdb2('0x24')]],'as':_0xc53a09['as'],'attributes':_0xc53a09['attributes'],'include':_0xc53a09['include']?_[_0xbdb2('0x23')](_0xc53a09[_0xbdb2('0x21')],function(_0x58b83c){return{'model':db[_0x58b83c[_0xbdb2('0x24')]],'as':_0x58b83c['as'],'attributes':_0x58b83c[_0xbdb2('0x22')]};}):[]};}):[]};}):[]:[]})[_0xbdb2('0x25')](function(_0x364290){logger['info']('ShowChatQueue',_0x13ad0e);logger[_0xbdb2('0x15')](_0xbdb2('0x28'),_0x13ad0e,JSON['stringify'](_0x364290));_0x2d8969(_0x364290);})[_0xbdb2('0x26')](function(_0x36e957){logger[_0xbdb2('0x19')](_0xbdb2('0x28'),_0x36e957['message'],_0x13ad0e);_0x58a686(_0x41c264[_0xbdb2('0x19')](0x1f4,_0x36e957[_0xbdb2('0x1b')]));});});};