dbf81db30c4a608680b46eb79ea86b5cb9e8d9d4
[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 _0x1619=['map','model','attributes','info','debug','find','raw','ShowChatQueue','moment','randomstring','ioredis','../../mysqldb','../../config/logger','../../config/environment','http','redis','localhost','register','request','then','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatQueue,\x20%s,\x20%s','message','request\x20sent','catch','GetChatQueue','ChatQueue','findAll','options','where','limit','include'];(function(_0x2a880e,_0x44beb7){var _0x45e0ce=function(_0x10cbc2){while(--_0x10cbc2){_0x2a880e['push'](_0x2a880e['shift']());}};_0x45e0ce(++_0x44beb7);}(_0x1619,0x189));var _0x9161=function(_0x27fffe,_0x2ec37c){_0x27fffe=_0x27fffe-0x0;var _0x43e20a=_0x1619[_0x27fffe];return _0x43e20a;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x9161('0x0'));var BPromise=require('bluebird');var rs=require(_0x9161('0x1'));var fs=require('fs');var Redis=require(_0x9161('0x2'));var db=require(_0x9161('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0x9161('0x4'))('rpc');var config=require(_0x9161('0x5'));var jayson=require('jayson/promise');var client=jayson['client'][_0x9161('0x6')]({'port':0x232a});config[_0x9161('0x7')]=_['defaults'](config[_0x9161('0x7')],{'host':_0x9161('0x8'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x9161('0x7')]));require('./chatQueue.socket')[_0x9161('0x9')](socket);function respondWithRpcPromise(_0x571c28,_0x191452,_0x321b97){return new BPromise(function(_0x20526d,_0x251ee2){return client[_0x9161('0xa')](_0x571c28,_0x321b97)[_0x9161('0xb')](function(_0x32ef57){logger['info']('ChatQueue,\x20%s,\x20%s',_0x191452,'request\x20sent');logger['debug'](_0x9161('0xc'),_0x191452,'request\x20sent',JSON[_0x9161('0xd')](_0x32ef57));if(_0x32ef57[_0x9161('0xe')]){if(_0x32ef57[_0x9161('0xe')][_0x9161('0xf')]===0x1f4){logger[_0x9161('0xe')](_0x9161('0x10'),_0x191452,_0x32ef57[_0x9161('0xe')][_0x9161('0x11')]);return _0x251ee2(_0x32ef57['error'][_0x9161('0x11')]);}logger[_0x9161('0xe')](_0x9161('0x10'),_0x191452,_0x32ef57['error'][_0x9161('0x11')]);return _0x20526d(_0x32ef57[_0x9161('0xe')][_0x9161('0x11')]);}else{logger['info'](_0x9161('0x10'),_0x191452,_0x9161('0x12'));_0x20526d(_0x32ef57['result'][_0x9161('0x11')]);}})[_0x9161('0x13')](function(_0x1b89f3){logger[_0x9161('0xe')](_0x9161('0x10'),_0x191452,_0x1b89f3);_0x251ee2(_0x1b89f3);});});}exports[_0x9161('0x14')]=function(_0x1171fc){var _0x4fd55d=this;return new Promise(function(_0x73d1cc,_0x53b67e){return db[_0x9161('0x15')][_0x9161('0x16')]({'raw':_0x1171fc[_0x9161('0x17')]?_0x1171fc['options']['raw']===undefined?!![]:![]:!![],'where':_0x1171fc['options']?_0x1171fc[_0x9161('0x17')][_0x9161('0x18')]||null:null,'attributes':_0x1171fc['options']?_0x1171fc['options']['attributes']||null:null,'limit':_0x1171fc['options']?_0x1171fc[_0x9161('0x17')][_0x9161('0x19')]||null:null,'include':_0x1171fc[_0x9161('0x17')]?_0x1171fc[_0x9161('0x17')][_0x9161('0x1a')]?_[_0x9161('0x1b')](_0x1171fc[_0x9161('0x17')]['include'],function(_0x8c4949){return{'model':db[_0x8c4949[_0x9161('0x1c')]],'as':_0x8c4949['as'],'attributes':_0x8c4949[_0x9161('0x1d')],'include':_0x8c4949[_0x9161('0x1a')]?_[_0x9161('0x1b')](_0x8c4949[_0x9161('0x1a')],function(_0x3102f7){return{'model':db[_0x3102f7[_0x9161('0x1c')]],'as':_0x3102f7['as'],'attributes':_0x3102f7[_0x9161('0x1d')],'include':_0x3102f7[_0x9161('0x1a')]?_[_0x9161('0x1b')](_0x3102f7['include'],function(_0x13bf83){return{'model':db[_0x13bf83[_0x9161('0x1c')]],'as':_0x13bf83['as'],'attributes':_0x13bf83['attributes']};}):[]};}):[]};}):[]:[]})[_0x9161('0xb')](function(_0x374f81){logger[_0x9161('0x1e')](_0x9161('0x14'),_0x1171fc);logger[_0x9161('0x1f')](_0x9161('0x14'),_0x1171fc,JSON['stringify'](_0x374f81));_0x73d1cc(_0x374f81);})[_0x9161('0x13')](function(_0x11cbbc){logger[_0x9161('0xe')]('GetChatQueue',_0x11cbbc[_0x9161('0x11')],_0x1171fc);_0x53b67e(_0x4fd55d[_0x9161('0xe')](0x1f4,_0x11cbbc[_0x9161('0x11')]));});});};exports['ShowChatQueue']=function(_0x3ed469){var _0x27959f=this;return new Promise(function(_0x187825,_0x207519){return db[_0x9161('0x15')][_0x9161('0x20')]({'raw':_0x3ed469[_0x9161('0x17')]?_0x3ed469[_0x9161('0x17')][_0x9161('0x21')]===undefined?!![]:![]:!![],'where':_0x3ed469[_0x9161('0x17')]?_0x3ed469[_0x9161('0x17')][_0x9161('0x18')]||null:null,'attributes':_0x3ed469[_0x9161('0x17')]?_0x3ed469[_0x9161('0x17')][_0x9161('0x1d')]||null:null,'include':_0x3ed469[_0x9161('0x17')]?_0x3ed469[_0x9161('0x17')][_0x9161('0x1a')]?_[_0x9161('0x1b')](_0x3ed469[_0x9161('0x17')][_0x9161('0x1a')],function(_0x2a5262){return{'model':db[_0x2a5262['model']],'as':_0x2a5262['as'],'attributes':_0x2a5262['attributes'],'include':_0x2a5262['include']?_[_0x9161('0x1b')](_0x2a5262[_0x9161('0x1a')],function(_0x16706b){return{'model':db[_0x16706b[_0x9161('0x1c')]],'as':_0x16706b['as'],'attributes':_0x16706b[_0x9161('0x1d')],'include':_0x16706b['include']?_[_0x9161('0x1b')](_0x16706b['include'],function(_0x47b714){return{'model':db[_0x47b714[_0x9161('0x1c')]],'as':_0x47b714['as'],'attributes':_0x47b714[_0x9161('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x1e9ce3){logger[_0x9161('0x1e')]('ShowChatQueue',_0x3ed469);logger[_0x9161('0x1f')]('ShowChatQueue',_0x3ed469,JSON['stringify'](_0x1e9ce3));_0x187825(_0x1e9ce3);})[_0x9161('0x13')](function(_0x4a3b3a){logger[_0x9161('0xe')](_0x9161('0x22'),_0x4a3b3a['message'],_0x3ed469);_0x207519(_0x27959f['error'](0x1f4,_0x4a3b3a[_0x9161('0x11')]));});});};