d2a7c1c7f274348a26faa5cc02af9e6c31418678
[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 _0x349f=['model','map','ChatQueue','ShowChatQueue','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','defaults','redis','localhost','socket.io-emitter','./chatQueue.socket','register','request','then','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatQueue,\x20%s,\x20%s','message','info','catch','GetChatQueue','findAll','options','where','attributes','include'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x349f,0xa8));var _0xf349=function(_0x55b6cc,_0x33f45a){_0x55b6cc=_0x55b6cc-0x0;var _0xa7dee3=_0x349f[_0x55b6cc];return _0xa7dee3;};'use strict';var _=require(_0xf349('0x0'));var util=require(_0xf349('0x1'));var moment=require(_0xf349('0x2'));var BPromise=require('bluebird');var rs=require(_0xf349('0x3'));var fs=require('fs');var Redis=require(_0xf349('0x4'));var db=require(_0xf349('0x5'))['db'];var utils=require(_0xf349('0x6'));var logger=require(_0xf349('0x7'))(_0xf349('0x8'));var config=require(_0xf349('0x9'));var jayson=require(_0xf349('0xa'));var client=jayson[_0xf349('0xb')][_0xf349('0xc')]({'port':0x232a});config['redis']=_[_0xf349('0xd')](config[_0xf349('0xe')],{'host':_0xf349('0xf'),'port':0x18eb});var socket=require(_0xf349('0x10'))(new Redis(config[_0xf349('0xe')]));require(_0xf349('0x11'))[_0xf349('0x12')](socket);function respondWithRpcPromise(_0x5e30ef,_0x50652e,_0x1e2abf){return new BPromise(function(_0x2eb18e,_0x459747){return client[_0xf349('0x13')](_0x5e30ef,_0x1e2abf)[_0xf349('0x14')](function(_0x497611){logger['info']('ChatQueue,\x20%s,\x20%s',_0x50652e,_0xf349('0x15'));logger[_0xf349('0x16')](_0xf349('0x17'),_0x50652e,_0xf349('0x15'),JSON[_0xf349('0x18')](_0x497611));if(_0x497611['error']){if(_0x497611[_0xf349('0x19')][_0xf349('0x1a')]===0x1f4){logger['error'](_0xf349('0x1b'),_0x50652e,_0x497611[_0xf349('0x19')]['message']);return _0x459747(_0x497611[_0xf349('0x19')]['message']);}logger[_0xf349('0x19')](_0xf349('0x1b'),_0x50652e,_0x497611[_0xf349('0x19')][_0xf349('0x1c')]);return _0x2eb18e(_0x497611[_0xf349('0x19')][_0xf349('0x1c')]);}else{logger[_0xf349('0x1d')]('ChatQueue,\x20%s,\x20%s',_0x50652e,_0xf349('0x15'));_0x2eb18e(_0x497611['result'][_0xf349('0x1c')]);}})[_0xf349('0x1e')](function(_0x296894){logger[_0xf349('0x19')](_0xf349('0x1b'),_0x50652e,_0x296894);_0x459747(_0x296894);});});}exports[_0xf349('0x1f')]=function(_0x27c6de){var _0x104f9b=this;return new Promise(function(_0x5ccd87,_0x282cc8){return db['ChatQueue'][_0xf349('0x20')]({'raw':_0x27c6de[_0xf349('0x21')]?_0x27c6de[_0xf349('0x21')]['raw']===undefined?!![]:![]:!![],'where':_0x27c6de[_0xf349('0x21')]?_0x27c6de[_0xf349('0x21')][_0xf349('0x22')]||null:null,'attributes':_0x27c6de['options']?_0x27c6de[_0xf349('0x21')][_0xf349('0x23')]||null:null,'limit':_0x27c6de['options']?_0x27c6de['options']['limit']||null:null,'include':_0x27c6de[_0xf349('0x21')]?_0x27c6de[_0xf349('0x21')][_0xf349('0x24')]?_['map'](_0x27c6de[_0xf349('0x21')][_0xf349('0x24')],function(_0x11dc06){return{'model':db[_0x11dc06[_0xf349('0x25')]],'as':_0x11dc06['as'],'attributes':_0x11dc06[_0xf349('0x23')],'include':_0x11dc06[_0xf349('0x24')]?_[_0xf349('0x26')](_0x11dc06[_0xf349('0x24')],function(_0x439d32){return{'model':db[_0x439d32[_0xf349('0x25')]],'as':_0x439d32['as'],'attributes':_0x439d32[_0xf349('0x23')],'include':_0x439d32[_0xf349('0x24')]?_[_0xf349('0x26')](_0x439d32[_0xf349('0x24')],function(_0x53aa55){return{'model':db[_0x53aa55['model']],'as':_0x53aa55['as'],'attributes':_0x53aa55['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x38d1e5){logger['info'](_0xf349('0x1f'),_0x27c6de);logger['debug']('GetChatQueue',_0x27c6de,JSON['stringify'](_0x38d1e5));_0x5ccd87(_0x38d1e5);})['catch'](function(_0x1a3ec6){logger[_0xf349('0x19')](_0xf349('0x1f'),_0x1a3ec6[_0xf349('0x1c')],_0x27c6de);_0x282cc8(_0x104f9b[_0xf349('0x19')](0x1f4,_0x1a3ec6['message']));});});};exports['ShowChatQueue']=function(_0x2c0f9c){var _0x1b9b26=this;return new Promise(function(_0xa25152,_0x3c104a){return db[_0xf349('0x27')]['find']({'raw':_0x2c0f9c[_0xf349('0x21')]?_0x2c0f9c[_0xf349('0x21')]['raw']===undefined?!![]:![]:!![],'where':_0x2c0f9c['options']?_0x2c0f9c['options'][_0xf349('0x22')]||null:null,'attributes':_0x2c0f9c[_0xf349('0x21')]?_0x2c0f9c[_0xf349('0x21')]['attributes']||null:null,'include':_0x2c0f9c[_0xf349('0x21')]?_0x2c0f9c[_0xf349('0x21')][_0xf349('0x24')]?_[_0xf349('0x26')](_0x2c0f9c[_0xf349('0x21')]['include'],function(_0x6dea95){return{'model':db[_0x6dea95['model']],'as':_0x6dea95['as'],'attributes':_0x6dea95[_0xf349('0x23')],'include':_0x6dea95[_0xf349('0x24')]?_[_0xf349('0x26')](_0x6dea95[_0xf349('0x24')],function(_0x125de4){return{'model':db[_0x125de4[_0xf349('0x25')]],'as':_0x125de4['as'],'attributes':_0x125de4[_0xf349('0x23')],'include':_0x125de4['include']?_['map'](_0x125de4['include'],function(_0x3f7bc8){return{'model':db[_0x3f7bc8[_0xf349('0x25')]],'as':_0x3f7bc8['as'],'attributes':_0x3f7bc8['attributes']};}):[]};}):[]};}):[]:[]})[_0xf349('0x14')](function(_0x1159dc){logger['info'](_0xf349('0x28'),_0x2c0f9c);logger[_0xf349('0x16')](_0xf349('0x28'),_0x2c0f9c,JSON[_0xf349('0x18')](_0x1159dc));_0xa25152(_0x1159dc);})[_0xf349('0x1e')](function(_0x452249){logger['error'](_0xf349('0x28'),_0x452249['message'],_0x2c0f9c);_0x3c104a(_0x1b9b26['error'](0x1f4,_0x452249[_0xf349('0x1c')]));});});};