8ae7330741e0406ea5cec8eea2883f31564ec19c
[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 _0x56a4=['where','map','include','model','attributes','then','catch','find','raw','ShowChatQueue','util','moment','bluebird','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','register','request','info','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','message','result','GetChatQueue','options'];(function(_0x49ca6b,_0x3ba842){var _0x1d957f=function(_0x12ef94){while(--_0x12ef94){_0x49ca6b['push'](_0x49ca6b['shift']());}};_0x1d957f(++_0x3ba842);}(_0x56a4,0x73));var _0x456a=function(_0x474a72,_0x439f5a){_0x474a72=_0x474a72-0x0;var _0x304966=_0x56a4[_0x474a72];return _0x304966;};'use strict';var _=require('lodash');var util=require(_0x456a('0x0'));var moment=require(_0x456a('0x1'));var BPromise=require(_0x456a('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x456a('0x3'))['db'];var utils=require(_0x456a('0x4'));var logger=require(_0x456a('0x5'))(_0x456a('0x6'));var config=require(_0x456a('0x7'));var jayson=require(_0x456a('0x8'));var client=jayson[_0x456a('0x9')][_0x456a('0xa')]({'port':0x232a});config['redis']=_['defaults'](config[_0x456a('0xb')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x456a('0xb')]));require('./chatQueue.socket')[_0x456a('0xc')](socket);function respondWithRpcPromise(_0x86bcda,_0x177988,_0x2e5f10){return new BPromise(function(_0x12f945,_0x56f14c){return client[_0x456a('0xd')](_0x86bcda,_0x2e5f10)['then'](function(_0x59f11c){logger[_0x456a('0xe')](_0x456a('0xf'),_0x177988,_0x456a('0x10'));logger[_0x456a('0x11')](_0x456a('0x12'),_0x177988,_0x456a('0x10'),JSON[_0x456a('0x13')](_0x59f11c));if(_0x59f11c['error']){if(_0x59f11c[_0x456a('0x14')]['code']===0x1f4){logger[_0x456a('0x14')]('ChatQueue,\x20%s,\x20%s',_0x177988,_0x59f11c[_0x456a('0x14')]['message']);return _0x56f14c(_0x59f11c[_0x456a('0x14')]['message']);}logger[_0x456a('0x14')]('ChatQueue,\x20%s,\x20%s',_0x177988,_0x59f11c[_0x456a('0x14')][_0x456a('0x15')]);return _0x12f945(_0x59f11c[_0x456a('0x14')][_0x456a('0x15')]);}else{logger['info']('ChatQueue,\x20%s,\x20%s',_0x177988,_0x456a('0x10'));_0x12f945(_0x59f11c[_0x456a('0x16')][_0x456a('0x15')]);}})['catch'](function(_0x5aaf40){logger[_0x456a('0x14')](_0x456a('0xf'),_0x177988,_0x5aaf40);_0x56f14c(_0x5aaf40);});});}exports[_0x456a('0x17')]=function(_0x5aff8b){var _0x202877=this;return new Promise(function(_0x2db147,_0x1378ae){return db['ChatQueue']['findAll']({'raw':_0x5aff8b['options']?_0x5aff8b[_0x456a('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x5aff8b[_0x456a('0x18')]?_0x5aff8b['options'][_0x456a('0x19')]||null:null,'attributes':_0x5aff8b[_0x456a('0x18')]?_0x5aff8b[_0x456a('0x18')]['attributes']||null:null,'limit':_0x5aff8b['options']?_0x5aff8b[_0x456a('0x18')]['limit']||null:null,'include':_0x5aff8b[_0x456a('0x18')]?_0x5aff8b[_0x456a('0x18')]['include']?_[_0x456a('0x1a')](_0x5aff8b[_0x456a('0x18')][_0x456a('0x1b')],function(_0x3f8967){return{'model':db[_0x3f8967[_0x456a('0x1c')]],'as':_0x3f8967['as'],'attributes':_0x3f8967[_0x456a('0x1d')],'include':_0x3f8967['include']?_[_0x456a('0x1a')](_0x3f8967['include'],function(_0x2f7e93){return{'model':db[_0x2f7e93[_0x456a('0x1c')]],'as':_0x2f7e93['as'],'attributes':_0x2f7e93['attributes'],'include':_0x2f7e93[_0x456a('0x1b')]?_['map'](_0x2f7e93[_0x456a('0x1b')],function(_0x3097fb){return{'model':db[_0x3097fb[_0x456a('0x1c')]],'as':_0x3097fb['as'],'attributes':_0x3097fb['attributes']};}):[]};}):[]};}):[]:[]})[_0x456a('0x1e')](function(_0x25287a){logger[_0x456a('0xe')](_0x456a('0x17'),_0x5aff8b);logger[_0x456a('0x11')](_0x456a('0x17'),_0x5aff8b,JSON[_0x456a('0x13')](_0x25287a));_0x2db147(_0x25287a);})[_0x456a('0x1f')](function(_0x1b9af6){logger[_0x456a('0x14')]('GetChatQueue',_0x1b9af6[_0x456a('0x15')],_0x5aff8b);_0x1378ae(_0x202877[_0x456a('0x14')](0x1f4,_0x1b9af6[_0x456a('0x15')]));});});};exports['ShowChatQueue']=function(_0x1ef547){var _0x6d6e3c=this;return new Promise(function(_0x40445d,_0x21f232){return db['ChatQueue'][_0x456a('0x20')]({'raw':_0x1ef547[_0x456a('0x18')]?_0x1ef547[_0x456a('0x18')][_0x456a('0x21')]===undefined?!![]:![]:!![],'where':_0x1ef547['options']?_0x1ef547[_0x456a('0x18')]['where']||null:null,'attributes':_0x1ef547[_0x456a('0x18')]?_0x1ef547[_0x456a('0x18')][_0x456a('0x1d')]||null:null,'include':_0x1ef547['options']?_0x1ef547['options'][_0x456a('0x1b')]?_[_0x456a('0x1a')](_0x1ef547['options']['include'],function(_0x3c308b){return{'model':db[_0x3c308b['model']],'as':_0x3c308b['as'],'attributes':_0x3c308b[_0x456a('0x1d')],'include':_0x3c308b['include']?_[_0x456a('0x1a')](_0x3c308b[_0x456a('0x1b')],function(_0x1b234d){return{'model':db[_0x1b234d[_0x456a('0x1c')]],'as':_0x1b234d['as'],'attributes':_0x1b234d[_0x456a('0x1d')],'include':_0x1b234d[_0x456a('0x1b')]?_[_0x456a('0x1a')](_0x1b234d[_0x456a('0x1b')],function(_0x307440){return{'model':db[_0x307440['model']],'as':_0x307440['as'],'attributes':_0x307440['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x5886ed){logger['info'](_0x456a('0x22'),_0x1ef547);logger[_0x456a('0x11')](_0x456a('0x22'),_0x1ef547,JSON[_0x456a('0x13')](_0x5886ed));_0x40445d(_0x5886ed);})[_0x456a('0x1f')](function(_0x2a8527){logger[_0x456a('0x14')](_0x456a('0x22'),_0x2a8527['message'],_0x1ef547);_0x21f232(_0x6d6e3c[_0x456a('0x14')](0x1f4,_0x2a8527[_0x456a('0x15')]));});});};