aef306777fe8c149a12679ab4f4204b2a4acf241
[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 _0x2200=['raw','attributes','limit','include','map','model','debug','ShowChatQueue','ChatQueue','lodash','util','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','redis','defaults','localhost','socket.io-emitter','register','request','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','GetChatQueue','options'];(function(_0x1c51ab,_0x58c3ad){var _0x1ef191=function(_0x2c7037){while(--_0x2c7037){_0x1c51ab['push'](_0x1c51ab['shift']());}};_0x1ef191(++_0x58c3ad);}(_0x2200,0x17b));var _0x0220=function(_0x27c24e,_0x5db1c7){_0x27c24e=_0x27c24e-0x0;var _0x39004a=_0x2200[_0x27c24e];return _0x39004a;};'use strict';var _=require(_0x0220('0x0'));var util=require(_0x0220('0x1'));var moment=require('moment');var BPromise=require(_0x0220('0x2'));var rs=require(_0x0220('0x3'));var fs=require('fs');var Redis=require(_0x0220('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x0220('0x5'));var logger=require(_0x0220('0x6'))(_0x0220('0x7'));var config=require(_0x0220('0x8'));var jayson=require(_0x0220('0x9'));var client=jayson['client']['http']({'port':0x232a});config[_0x0220('0xa')]=_[_0x0220('0xb')](config['redis'],{'host':_0x0220('0xc'),'port':0x18eb});var socket=require(_0x0220('0xd'))(new Redis(config[_0x0220('0xa')]));require('./chatQueue.socket')[_0x0220('0xe')](socket);function respondWithRpcPromise(_0x54305a,_0xc9dcdf,_0x42545f){return new BPromise(function(_0x55f2b3,_0x7d357){return client[_0x0220('0xf')](_0x54305a,_0x42545f)[_0x0220('0x10')](function(_0x5c6fbe){logger[_0x0220('0x11')](_0x0220('0x12'),_0xc9dcdf,_0x0220('0x13'));logger['debug']('ChatQueue,\x20%s,\x20%s,\x20%s',_0xc9dcdf,'request\x20sent',JSON[_0x0220('0x14')](_0x5c6fbe));if(_0x5c6fbe[_0x0220('0x15')]){if(_0x5c6fbe[_0x0220('0x15')][_0x0220('0x16')]===0x1f4){logger[_0x0220('0x15')]('ChatQueue,\x20%s,\x20%s',_0xc9dcdf,_0x5c6fbe[_0x0220('0x15')][_0x0220('0x17')]);return _0x7d357(_0x5c6fbe[_0x0220('0x15')][_0x0220('0x17')]);}logger[_0x0220('0x15')]('ChatQueue,\x20%s,\x20%s',_0xc9dcdf,_0x5c6fbe[_0x0220('0x15')]['message']);return _0x55f2b3(_0x5c6fbe[_0x0220('0x15')]['message']);}else{logger[_0x0220('0x11')](_0x0220('0x12'),_0xc9dcdf,_0x0220('0x13'));_0x55f2b3(_0x5c6fbe[_0x0220('0x18')][_0x0220('0x17')]);}})[_0x0220('0x19')](function(_0x258fb1){logger['error'](_0x0220('0x12'),_0xc9dcdf,_0x258fb1);_0x7d357(_0x258fb1);});});}exports[_0x0220('0x1a')]=function(_0x26d626){var _0x39722b=this;return new Promise(function(_0x324976,_0x58f82e){return db['ChatQueue']['findAll']({'raw':_0x26d626[_0x0220('0x1b')]?_0x26d626[_0x0220('0x1b')][_0x0220('0x1c')]===undefined?!![]:![]:!![],'where':_0x26d626['options']?_0x26d626['options']['where']||null:null,'attributes':_0x26d626[_0x0220('0x1b')]?_0x26d626[_0x0220('0x1b')][_0x0220('0x1d')]||null:null,'limit':_0x26d626[_0x0220('0x1b')]?_0x26d626['options'][_0x0220('0x1e')]||null:null,'include':_0x26d626[_0x0220('0x1b')]?_0x26d626[_0x0220('0x1b')][_0x0220('0x1f')]?_[_0x0220('0x20')](_0x26d626[_0x0220('0x1b')][_0x0220('0x1f')],function(_0x40ef1d){return{'model':db[_0x40ef1d[_0x0220('0x21')]],'as':_0x40ef1d['as'],'attributes':_0x40ef1d['attributes'],'include':_0x40ef1d[_0x0220('0x1f')]?_[_0x0220('0x20')](_0x40ef1d['include'],function(_0x45c394){return{'model':db[_0x45c394[_0x0220('0x21')]],'as':_0x45c394['as'],'attributes':_0x45c394['attributes'],'include':_0x45c394['include']?_[_0x0220('0x20')](_0x45c394[_0x0220('0x1f')],function(_0x2ef452){return{'model':db[_0x2ef452[_0x0220('0x21')]],'as':_0x2ef452['as'],'attributes':_0x2ef452[_0x0220('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x276a63){logger['info'](_0x0220('0x1a'),_0x26d626);logger[_0x0220('0x22')](_0x0220('0x1a'),_0x26d626,JSON[_0x0220('0x14')](_0x276a63));_0x324976(_0x276a63);})[_0x0220('0x19')](function(_0x22c61e){logger[_0x0220('0x15')]('GetChatQueue',_0x22c61e[_0x0220('0x17')],_0x26d626);_0x58f82e(_0x39722b[_0x0220('0x15')](0x1f4,_0x22c61e[_0x0220('0x17')]));});});};exports[_0x0220('0x23')]=function(_0x5f30d1){var _0x247c49=this;return new Promise(function(_0x2867bd,_0x52dfc0){return db[_0x0220('0x24')]['find']({'raw':_0x5f30d1[_0x0220('0x1b')]?_0x5f30d1[_0x0220('0x1b')][_0x0220('0x1c')]===undefined?!![]:![]:!![],'where':_0x5f30d1[_0x0220('0x1b')]?_0x5f30d1[_0x0220('0x1b')]['where']||null:null,'attributes':_0x5f30d1[_0x0220('0x1b')]?_0x5f30d1[_0x0220('0x1b')]['attributes']||null:null,'include':_0x5f30d1[_0x0220('0x1b')]?_0x5f30d1['options'][_0x0220('0x1f')]?_['map'](_0x5f30d1[_0x0220('0x1b')][_0x0220('0x1f')],function(_0x2da816){return{'model':db[_0x2da816[_0x0220('0x21')]],'as':_0x2da816['as'],'attributes':_0x2da816[_0x0220('0x1d')],'include':_0x2da816[_0x0220('0x1f')]?_['map'](_0x2da816[_0x0220('0x1f')],function(_0xcd670){return{'model':db[_0xcd670[_0x0220('0x21')]],'as':_0xcd670['as'],'attributes':_0xcd670[_0x0220('0x1d')],'include':_0xcd670[_0x0220('0x1f')]?_[_0x0220('0x20')](_0xcd670[_0x0220('0x1f')],function(_0x11b4f0){return{'model':db[_0x11b4f0[_0x0220('0x21')]],'as':_0x11b4f0['as'],'attributes':_0x11b4f0[_0x0220('0x1d')]};}):[]};}):[]};}):[]:[]})[_0x0220('0x10')](function(_0x224f0d){logger[_0x0220('0x11')](_0x0220('0x23'),_0x5f30d1);logger[_0x0220('0x22')](_0x0220('0x23'),_0x5f30d1,JSON['stringify'](_0x224f0d));_0x2867bd(_0x224f0d);})[_0x0220('0x19')](function(_0x50a658){logger['error']('ShowChatQueue',_0x50a658['message'],_0x5f30d1);_0x52dfc0(_0x247c49['error'](0x1f4,_0x50a658[_0x0220('0x17')]));});});};