Built motion from commit db94841.|2.5.3
[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 _0x00a4=['lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','jayson/promise','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','register','request','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','ChatQueue,\x20%s,\x20%s,\x20%s','code','error','message','result','catch','GetChatQueue','ChatQueue','options','where','attributes','include','map','model','debug','stringify','ShowChatQueue','find','raw'];(function(_0x246a25,_0x2c0c46){var _0x5996f4=function(_0x5ae4bb){while(--_0x5ae4bb){_0x246a25['push'](_0x246a25['shift']());}};_0x5996f4(++_0x2c0c46);}(_0x00a4,0x186));var _0x400a=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0x00a4[_0x2dafbe];return _0x58a45a;};'use strict';var _=require(_0x400a('0x0'));var util=require(_0x400a('0x1'));var moment=require(_0x400a('0x2'));var BPromise=require(_0x400a('0x3'));var rs=require(_0x400a('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x400a('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0x400a('0x6'))(_0x400a('0x7'));var config=require('../../config/environment');var jayson=require(_0x400a('0x8'));var client=jayson['client']['http']({'port':0x232a});config[_0x400a('0x9')]=_[_0x400a('0xa')](config[_0x400a('0x9')],{'host':_0x400a('0xb'),'port':0x18eb});var socket=require(_0x400a('0xc'))(new Redis(config['redis']));require(_0x400a('0xd'))[_0x400a('0xe')](socket);function respondWithRpcPromise(_0x4d938b,_0x4c2f86,_0x46a01b){return new BPromise(function(_0x5cdc4b,_0x5020d4){return client[_0x400a('0xf')](_0x4d938b,_0x46a01b)[_0x400a('0x10')](function(_0x186de4){logger[_0x400a('0x11')](_0x400a('0x12'),_0x4c2f86,_0x400a('0x13'));logger['debug'](_0x400a('0x14'),_0x4c2f86,_0x400a('0x13'),JSON['stringify'](_0x186de4));if(_0x186de4['error']){if(_0x186de4['error'][_0x400a('0x15')]===0x1f4){logger[_0x400a('0x16')](_0x400a('0x12'),_0x4c2f86,_0x186de4[_0x400a('0x16')][_0x400a('0x17')]);return _0x5020d4(_0x186de4[_0x400a('0x16')]['message']);}logger[_0x400a('0x16')](_0x400a('0x12'),_0x4c2f86,_0x186de4[_0x400a('0x16')][_0x400a('0x17')]);return _0x5cdc4b(_0x186de4[_0x400a('0x16')][_0x400a('0x17')]);}else{logger[_0x400a('0x11')]('ChatQueue,\x20%s,\x20%s',_0x4c2f86,_0x400a('0x13'));_0x5cdc4b(_0x186de4[_0x400a('0x18')][_0x400a('0x17')]);}})[_0x400a('0x19')](function(_0x322344){logger[_0x400a('0x16')]('ChatQueue,\x20%s,\x20%s',_0x4c2f86,_0x322344);_0x5020d4(_0x322344);});});}exports[_0x400a('0x1a')]=function(_0x3188e0){var _0x414c3b=this;return new Promise(function(_0x4e156b,_0xd7e75d){return db[_0x400a('0x1b')]['findAll']({'raw':_0x3188e0['options']?_0x3188e0[_0x400a('0x1c')]['raw']===undefined?!![]:![]:!![],'where':_0x3188e0[_0x400a('0x1c')]?_0x3188e0[_0x400a('0x1c')][_0x400a('0x1d')]||null:null,'attributes':_0x3188e0[_0x400a('0x1c')]?_0x3188e0[_0x400a('0x1c')][_0x400a('0x1e')]||null:null,'limit':_0x3188e0[_0x400a('0x1c')]?_0x3188e0[_0x400a('0x1c')]['limit']||null:null,'include':_0x3188e0['options']?_0x3188e0[_0x400a('0x1c')][_0x400a('0x1f')]?_[_0x400a('0x20')](_0x3188e0[_0x400a('0x1c')][_0x400a('0x1f')],function(_0x51edd7){return{'model':db[_0x51edd7[_0x400a('0x21')]],'as':_0x51edd7['as'],'attributes':_0x51edd7[_0x400a('0x1e')],'include':_0x51edd7[_0x400a('0x1f')]?_['map'](_0x51edd7[_0x400a('0x1f')],function(_0x3f8a81){return{'model':db[_0x3f8a81[_0x400a('0x21')]],'as':_0x3f8a81['as'],'attributes':_0x3f8a81['attributes'],'include':_0x3f8a81[_0x400a('0x1f')]?_[_0x400a('0x20')](_0x3f8a81[_0x400a('0x1f')],function(_0x3e7c43){return{'model':db[_0x3e7c43[_0x400a('0x21')]],'as':_0x3e7c43['as'],'attributes':_0x3e7c43[_0x400a('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x400a('0x10')](function(_0x187e5f){logger[_0x400a('0x11')]('GetChatQueue',_0x3188e0);logger[_0x400a('0x22')](_0x400a('0x1a'),_0x3188e0,JSON[_0x400a('0x23')](_0x187e5f));_0x4e156b(_0x187e5f);})[_0x400a('0x19')](function(_0x1597e4){logger[_0x400a('0x16')](_0x400a('0x1a'),_0x1597e4['message'],_0x3188e0);_0xd7e75d(_0x414c3b[_0x400a('0x16')](0x1f4,_0x1597e4['message']));});});};exports[_0x400a('0x24')]=function(_0x1afd1d){var _0x566f8c=this;return new Promise(function(_0x1a666d,_0x54d9c8){return db[_0x400a('0x1b')][_0x400a('0x25')]({'raw':_0x1afd1d['options']?_0x1afd1d[_0x400a('0x1c')][_0x400a('0x26')]===undefined?!![]:![]:!![],'where':_0x1afd1d[_0x400a('0x1c')]?_0x1afd1d[_0x400a('0x1c')][_0x400a('0x1d')]||null:null,'attributes':_0x1afd1d['options']?_0x1afd1d[_0x400a('0x1c')][_0x400a('0x1e')]||null:null,'include':_0x1afd1d['options']?_0x1afd1d[_0x400a('0x1c')]['include']?_[_0x400a('0x20')](_0x1afd1d[_0x400a('0x1c')][_0x400a('0x1f')],function(_0x115881){return{'model':db[_0x115881['model']],'as':_0x115881['as'],'attributes':_0x115881['attributes'],'include':_0x115881[_0x400a('0x1f')]?_[_0x400a('0x20')](_0x115881[_0x400a('0x1f')],function(_0x286029){return{'model':db[_0x286029[_0x400a('0x21')]],'as':_0x286029['as'],'attributes':_0x286029['attributes'],'include':_0x286029[_0x400a('0x1f')]?_['map'](_0x286029[_0x400a('0x1f')],function(_0x6bf8b6){return{'model':db[_0x6bf8b6['model']],'as':_0x6bf8b6['as'],'attributes':_0x6bf8b6[_0x400a('0x1e')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x31cd31){logger['info'](_0x400a('0x24'),_0x1afd1d);logger[_0x400a('0x22')]('ShowChatQueue',_0x1afd1d,JSON['stringify'](_0x31cd31));_0x1a666d(_0x31cd31);})['catch'](function(_0x577a88){logger[_0x400a('0x16')](_0x400a('0x24'),_0x577a88[_0x400a('0x17')],_0x1afd1d);_0x54d9c8(_0x566f8c['error'](0x1f4,_0x577a88['message']));});});};