ecedcfb99d2af524b2251881f32d10b97f0111c6
[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 _0x62ff=['map','model','then','ShowChatQueue','raw','lodash','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','redis','localhost','socket.io-emitter','./chatQueue.socket','register','info','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetChatQueue','ChatQueue','findAll','options','attributes','limit','include'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x62ff,0x1e5));var _0xf62f=function(_0x32f7d7,_0x54231b){_0x32f7d7=_0x32f7d7-0x0;var _0x133d09=_0x62ff[_0x32f7d7];return _0x133d09;};'use strict';var _=require(_0xf62f('0x0'));var util=require(_0xf62f('0x1'));var moment=require('moment');var BPromise=require(_0xf62f('0x2'));var rs=require(_0xf62f('0x3'));var fs=require('fs');var Redis=require(_0xf62f('0x4'));var db=require(_0xf62f('0x5'))['db'];var utils=require(_0xf62f('0x6'));var logger=require(_0xf62f('0x7'))(_0xf62f('0x8'));var config=require('../../config/environment');var jayson=require(_0xf62f('0x9'));var client=jayson[_0xf62f('0xa')][_0xf62f('0xb')]({'port':0x232a});config['redis']=_['defaults'](config[_0xf62f('0xc')],{'host':_0xf62f('0xd'),'port':0x18eb});var socket=require(_0xf62f('0xe'))(new Redis(config[_0xf62f('0xc')]));require(_0xf62f('0xf'))[_0xf62f('0x10')](socket);function respondWithRpcPromise(_0x5c10ee,_0x1ca783,_0x52624a){return new BPromise(function(_0x6e5ead,_0x226349){return client['request'](_0x5c10ee,_0x52624a)['then'](function(_0x3da720){logger[_0xf62f('0x11')](_0xf62f('0x12'),_0x1ca783,_0xf62f('0x13'));logger[_0xf62f('0x14')](_0xf62f('0x15'),_0x1ca783,_0xf62f('0x13'),JSON[_0xf62f('0x16')](_0x3da720));if(_0x3da720[_0xf62f('0x17')]){if(_0x3da720['error'][_0xf62f('0x18')]===0x1f4){logger[_0xf62f('0x17')](_0xf62f('0x12'),_0x1ca783,_0x3da720[_0xf62f('0x17')]['message']);return _0x226349(_0x3da720['error']['message']);}logger[_0xf62f('0x17')]('ChatQueue,\x20%s,\x20%s',_0x1ca783,_0x3da720[_0xf62f('0x17')][_0xf62f('0x19')]);return _0x6e5ead(_0x3da720[_0xf62f('0x17')][_0xf62f('0x19')]);}else{logger['info']('ChatQueue,\x20%s,\x20%s',_0x1ca783,_0xf62f('0x13'));_0x6e5ead(_0x3da720[_0xf62f('0x1a')]['message']);}})[_0xf62f('0x1b')](function(_0x20255a){logger[_0xf62f('0x17')](_0xf62f('0x12'),_0x1ca783,_0x20255a);_0x226349(_0x20255a);});});}exports[_0xf62f('0x1c')]=function(_0x233009){var _0x334c48=this;return new Promise(function(_0x6e3326,_0x2f8a91){return db[_0xf62f('0x1d')][_0xf62f('0x1e')]({'raw':_0x233009['options']?_0x233009['options']['raw']===undefined?!![]:![]:!![],'where':_0x233009[_0xf62f('0x1f')]?_0x233009[_0xf62f('0x1f')]['where']||null:null,'attributes':_0x233009[_0xf62f('0x1f')]?_0x233009[_0xf62f('0x1f')][_0xf62f('0x20')]||null:null,'limit':_0x233009[_0xf62f('0x1f')]?_0x233009['options'][_0xf62f('0x21')]||null:null,'include':_0x233009['options']?_0x233009['options'][_0xf62f('0x22')]?_['map'](_0x233009['options'][_0xf62f('0x22')],function(_0x1fa792){return{'model':db[_0x1fa792['model']],'as':_0x1fa792['as'],'attributes':_0x1fa792['attributes'],'include':_0x1fa792['include']?_[_0xf62f('0x23')](_0x1fa792['include'],function(_0x3c8d64){return{'model':db[_0x3c8d64[_0xf62f('0x24')]],'as':_0x3c8d64['as'],'attributes':_0x3c8d64[_0xf62f('0x20')],'include':_0x3c8d64[_0xf62f('0x22')]?_[_0xf62f('0x23')](_0x3c8d64[_0xf62f('0x22')],function(_0x23dec6){return{'model':db[_0x23dec6[_0xf62f('0x24')]],'as':_0x23dec6['as'],'attributes':_0x23dec6[_0xf62f('0x20')]};}):[]};}):[]};}):[]:[]})[_0xf62f('0x25')](function(_0x1b2f33){logger[_0xf62f('0x11')](_0xf62f('0x1c'),_0x233009);logger[_0xf62f('0x14')]('GetChatQueue',_0x233009,JSON[_0xf62f('0x16')](_0x1b2f33));_0x6e3326(_0x1b2f33);})[_0xf62f('0x1b')](function(_0x2020dc){logger[_0xf62f('0x17')]('GetChatQueue',_0x2020dc[_0xf62f('0x19')],_0x233009);_0x2f8a91(_0x334c48[_0xf62f('0x17')](0x1f4,_0x2020dc[_0xf62f('0x19')]));});});};exports[_0xf62f('0x26')]=function(_0x529d6b){var _0x567da2=this;return new Promise(function(_0xd7e5b8,_0x10e00f){return db[_0xf62f('0x1d')]['find']({'raw':_0x529d6b['options']?_0x529d6b[_0xf62f('0x1f')][_0xf62f('0x27')]===undefined?!![]:![]:!![],'where':_0x529d6b[_0xf62f('0x1f')]?_0x529d6b['options']['where']||null:null,'attributes':_0x529d6b[_0xf62f('0x1f')]?_0x529d6b[_0xf62f('0x1f')]['attributes']||null:null,'include':_0x529d6b[_0xf62f('0x1f')]?_0x529d6b[_0xf62f('0x1f')][_0xf62f('0x22')]?_[_0xf62f('0x23')](_0x529d6b[_0xf62f('0x1f')][_0xf62f('0x22')],function(_0x4ed9ee){return{'model':db[_0x4ed9ee[_0xf62f('0x24')]],'as':_0x4ed9ee['as'],'attributes':_0x4ed9ee[_0xf62f('0x20')],'include':_0x4ed9ee[_0xf62f('0x22')]?_[_0xf62f('0x23')](_0x4ed9ee['include'],function(_0x36fb4c){return{'model':db[_0x36fb4c[_0xf62f('0x24')]],'as':_0x36fb4c['as'],'attributes':_0x36fb4c[_0xf62f('0x20')],'include':_0x36fb4c[_0xf62f('0x22')]?_[_0xf62f('0x23')](_0x36fb4c[_0xf62f('0x22')],function(_0x4c6e5e){return{'model':db[_0x4c6e5e[_0xf62f('0x24')]],'as':_0x4c6e5e['as'],'attributes':_0x4c6e5e[_0xf62f('0x20')]};}):[]};}):[]};}):[]:[]})[_0xf62f('0x25')](function(_0x11cdcf){logger[_0xf62f('0x11')](_0xf62f('0x26'),_0x529d6b);logger['debug']('ShowChatQueue',_0x529d6b,JSON[_0xf62f('0x16')](_0x11cdcf));_0xd7e5b8(_0x11cdcf);})[_0xf62f('0x1b')](function(_0x5d3649){logger[_0xf62f('0x17')](_0xf62f('0x26'),_0x5d3649[_0xf62f('0x19')],_0x529d6b);_0x10e00f(_0x567da2[_0xf62f('0x17')](0x1f4,_0x5d3649[_0xf62f('0x19')]));});});};