b219e005698bf9932b532d4db789e47085f764d4
[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 _0x3d45=['moment','bluebird','randomstring','../../mysqldb','../../config/utils','rpc','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','register','request','then','info','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatQueue,\x20%s,\x20%s','message','result','catch','GetChatQueue','ChatQueue','raw','options','where','attributes','limit','include','map','model','ShowChatQueue','find','lodash','util'];(function(_0x23e894,_0x584c78){var _0x2aecbd=function(_0x26f546){while(--_0x26f546){_0x23e894['push'](_0x23e894['shift']());}};_0x2aecbd(++_0x584c78);}(_0x3d45,0x1d2));var _0x53d4=function(_0x4154a6,_0x2c0b8e){_0x4154a6=_0x4154a6-0x0;var _0x3b2786=_0x3d45[_0x4154a6];return _0x3b2786;};'use strict';var _=require(_0x53d4('0x0'));var util=require(_0x53d4('0x1'));var moment=require(_0x53d4('0x2'));var BPromise=require(_0x53d4('0x3'));var rs=require(_0x53d4('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x53d4('0x5'))['db'];var utils=require(_0x53d4('0x6'));var logger=require('../../config/logger')(_0x53d4('0x7'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232a});config[_0x53d4('0x8')]=_[_0x53d4('0x9')](config[_0x53d4('0x8')],{'host':_0x53d4('0xa'),'port':0x18eb});var socket=require(_0x53d4('0xb'))(new Redis(config['redis']));require(_0x53d4('0xc'))[_0x53d4('0xd')](socket);function respondWithRpcPromise(_0x449c1c,_0x4e8993,_0x1abe33){return new BPromise(function(_0x523abb,_0x2c4975){return client[_0x53d4('0xe')](_0x449c1c,_0x1abe33)[_0x53d4('0xf')](function(_0x209860){logger[_0x53d4('0x10')]('ChatQueue,\x20%s,\x20%s',_0x4e8993,_0x53d4('0x11'));logger[_0x53d4('0x12')](_0x53d4('0x13'),_0x4e8993,'request\x20sent',JSON[_0x53d4('0x14')](_0x209860));if(_0x209860[_0x53d4('0x15')]){if(_0x209860['error'][_0x53d4('0x16')]===0x1f4){logger['error'](_0x53d4('0x17'),_0x4e8993,_0x209860[_0x53d4('0x15')][_0x53d4('0x18')]);return _0x2c4975(_0x209860['error'][_0x53d4('0x18')]);}logger[_0x53d4('0x15')](_0x53d4('0x17'),_0x4e8993,_0x209860[_0x53d4('0x15')][_0x53d4('0x18')]);return _0x523abb(_0x209860['error'][_0x53d4('0x18')]);}else{logger[_0x53d4('0x10')]('ChatQueue,\x20%s,\x20%s',_0x4e8993,'request\x20sent');_0x523abb(_0x209860[_0x53d4('0x19')][_0x53d4('0x18')]);}})[_0x53d4('0x1a')](function(_0x56015f){logger[_0x53d4('0x15')](_0x53d4('0x17'),_0x4e8993,_0x56015f);_0x2c4975(_0x56015f);});});}exports[_0x53d4('0x1b')]=function(_0x16e505){var _0x3fcb51=this;return new Promise(function(_0x9bd09,_0x25ed73){return db[_0x53d4('0x1c')]['findAll']({'raw':_0x16e505['options']?_0x16e505['options'][_0x53d4('0x1d')]===undefined?!![]:![]:!![],'where':_0x16e505['options']?_0x16e505[_0x53d4('0x1e')][_0x53d4('0x1f')]||null:null,'attributes':_0x16e505[_0x53d4('0x1e')]?_0x16e505[_0x53d4('0x1e')][_0x53d4('0x20')]||null:null,'limit':_0x16e505[_0x53d4('0x1e')]?_0x16e505[_0x53d4('0x1e')][_0x53d4('0x21')]||null:null,'include':_0x16e505[_0x53d4('0x1e')]?_0x16e505[_0x53d4('0x1e')][_0x53d4('0x22')]?_[_0x53d4('0x23')](_0x16e505[_0x53d4('0x1e')][_0x53d4('0x22')],function(_0xcb69ef){return{'model':db[_0xcb69ef[_0x53d4('0x24')]],'as':_0xcb69ef['as'],'attributes':_0xcb69ef[_0x53d4('0x20')],'include':_0xcb69ef[_0x53d4('0x22')]?_[_0x53d4('0x23')](_0xcb69ef['include'],function(_0x4f7946){return{'model':db[_0x4f7946[_0x53d4('0x24')]],'as':_0x4f7946['as'],'attributes':_0x4f7946[_0x53d4('0x20')],'include':_0x4f7946[_0x53d4('0x22')]?_['map'](_0x4f7946[_0x53d4('0x22')],function(_0x445cc3){return{'model':db[_0x445cc3['model']],'as':_0x445cc3['as'],'attributes':_0x445cc3['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x423ee6){logger[_0x53d4('0x10')](_0x53d4('0x1b'),_0x16e505);logger[_0x53d4('0x12')](_0x53d4('0x1b'),_0x16e505,JSON['stringify'](_0x423ee6));_0x9bd09(_0x423ee6);})[_0x53d4('0x1a')](function(_0x5a3d55){logger[_0x53d4('0x15')](_0x53d4('0x1b'),_0x5a3d55[_0x53d4('0x18')],_0x16e505);_0x25ed73(_0x3fcb51[_0x53d4('0x15')](0x1f4,_0x5a3d55[_0x53d4('0x18')]));});});};exports[_0x53d4('0x25')]=function(_0x5b3c3d){var _0x4d38ac=this;return new Promise(function(_0x2c9a6d,_0x5a7de6){return db['ChatQueue'][_0x53d4('0x26')]({'raw':_0x5b3c3d[_0x53d4('0x1e')]?_0x5b3c3d[_0x53d4('0x1e')][_0x53d4('0x1d')]===undefined?!![]:![]:!![],'where':_0x5b3c3d['options']?_0x5b3c3d['options'][_0x53d4('0x1f')]||null:null,'attributes':_0x5b3c3d[_0x53d4('0x1e')]?_0x5b3c3d[_0x53d4('0x1e')][_0x53d4('0x20')]||null:null,'include':_0x5b3c3d[_0x53d4('0x1e')]?_0x5b3c3d[_0x53d4('0x1e')][_0x53d4('0x22')]?_[_0x53d4('0x23')](_0x5b3c3d[_0x53d4('0x1e')][_0x53d4('0x22')],function(_0x1ea183){return{'model':db[_0x1ea183[_0x53d4('0x24')]],'as':_0x1ea183['as'],'attributes':_0x1ea183[_0x53d4('0x20')],'include':_0x1ea183['include']?_[_0x53d4('0x23')](_0x1ea183[_0x53d4('0x22')],function(_0x252dee){return{'model':db[_0x252dee[_0x53d4('0x24')]],'as':_0x252dee['as'],'attributes':_0x252dee[_0x53d4('0x20')],'include':_0x252dee[_0x53d4('0x22')]?_[_0x53d4('0x23')](_0x252dee[_0x53d4('0x22')],function(_0x3d5344){return{'model':db[_0x3d5344[_0x53d4('0x24')]],'as':_0x3d5344['as'],'attributes':_0x3d5344['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x2e82d4){logger[_0x53d4('0x10')]('ShowChatQueue',_0x5b3c3d);logger[_0x53d4('0x12')]('ShowChatQueue',_0x5b3c3d,JSON[_0x53d4('0x14')](_0x2e82d4));_0x2c9a6d(_0x2e82d4);})['catch'](function(_0x3b9a02){logger[_0x53d4('0x15')](_0x53d4('0x25'),_0x3b9a02[_0x53d4('0x18')],_0x5b3c3d);_0x5a7de6(_0x4d38ac[_0x53d4('0x15')](0x1f4,_0x3b9a02['message']));});});};