2c1a3c1257c14eacd44a713a70275c715dc96022
[motion2.git] / server / api / mailQueue / mailQueue.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 _0xb83f=['rpc','../../config/environment','client','redis','defaults','localhost','./mailQueue.socket','register','request','then','info','request\x20sent','debug','MailQueue,\x20%s,\x20%s,\x20%s','error','code','MailQueue,\x20%s,\x20%s','message','findAll','options','raw','attributes','limit','include','map','model','GetMailQueue','stringify','catch','ShowMailQueue','MailQueue','find','moment','randomstring','ioredis','../../mysqldb','../../config/utils'];(function(_0x494d1f,_0x3f72ff){var _0x457b6e=function(_0x38cb16){while(--_0x38cb16){_0x494d1f['push'](_0x494d1f['shift']());}};_0x457b6e(++_0x3f72ff);}(_0xb83f,0x123));var _0xfb83=function(_0x334841,_0x2bbc4c){_0x334841=_0x334841-0x0;var _0x5beb4b=_0xb83f[_0x334841];return _0x5beb4b;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xfb83('0x0'));var BPromise=require('bluebird');var rs=require(_0xfb83('0x1'));var fs=require('fs');var Redis=require(_0xfb83('0x2'));var db=require(_0xfb83('0x3'))['db'];var utils=require(_0xfb83('0x4'));var logger=require('../../config/logger')(_0xfb83('0x5'));var config=require(_0xfb83('0x6'));var jayson=require('jayson/promise');var client=jayson[_0xfb83('0x7')]['http']({'port':0x232a});config[_0xfb83('0x8')]=_[_0xfb83('0x9')](config[_0xfb83('0x8')],{'host':_0xfb83('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xfb83('0xb'))[_0xfb83('0xc')](socket);function respondWithRpcPromise(_0x284b1a,_0xc18160,_0x567fa3){return new BPromise(function(_0xafa787,_0x44e1e7){return client[_0xfb83('0xd')](_0x284b1a,_0x567fa3)[_0xfb83('0xe')](function(_0x28b8d5){logger[_0xfb83('0xf')]('MailQueue,\x20%s,\x20%s',_0xc18160,_0xfb83('0x10'));logger[_0xfb83('0x11')](_0xfb83('0x12'),_0xc18160,_0xfb83('0x10'),JSON['stringify'](_0x28b8d5));if(_0x28b8d5[_0xfb83('0x13')]){if(_0x28b8d5[_0xfb83('0x13')][_0xfb83('0x14')]===0x1f4){logger[_0xfb83('0x13')](_0xfb83('0x15'),_0xc18160,_0x28b8d5['error'][_0xfb83('0x16')]);return _0x44e1e7(_0x28b8d5[_0xfb83('0x13')][_0xfb83('0x16')]);}logger[_0xfb83('0x13')](_0xfb83('0x15'),_0xc18160,_0x28b8d5[_0xfb83('0x13')][_0xfb83('0x16')]);return _0xafa787(_0x28b8d5[_0xfb83('0x13')]['message']);}else{logger[_0xfb83('0xf')](_0xfb83('0x15'),_0xc18160,_0xfb83('0x10'));_0xafa787(_0x28b8d5['result'][_0xfb83('0x16')]);}})['catch'](function(_0x63f144){logger[_0xfb83('0x13')]('MailQueue,\x20%s,\x20%s',_0xc18160,_0x63f144);_0x44e1e7(_0x63f144);});});}exports['GetMailQueue']=function(_0x30e8ba){var _0x466af2=this;return new Promise(function(_0xacd44e,_0x341802){return db['MailQueue'][_0xfb83('0x17')]({'raw':_0x30e8ba[_0xfb83('0x18')]?_0x30e8ba[_0xfb83('0x18')][_0xfb83('0x19')]===undefined?!![]:![]:!![],'where':_0x30e8ba[_0xfb83('0x18')]?_0x30e8ba[_0xfb83('0x18')]['where']||null:null,'attributes':_0x30e8ba['options']?_0x30e8ba[_0xfb83('0x18')][_0xfb83('0x1a')]||null:null,'limit':_0x30e8ba[_0xfb83('0x18')]?_0x30e8ba[_0xfb83('0x18')][_0xfb83('0x1b')]||null:null,'include':_0x30e8ba[_0xfb83('0x18')]?_0x30e8ba['options'][_0xfb83('0x1c')]?_[_0xfb83('0x1d')](_0x30e8ba['options'][_0xfb83('0x1c')],function(_0x2b8c42){return{'model':db[_0x2b8c42[_0xfb83('0x1e')]],'as':_0x2b8c42['as'],'attributes':_0x2b8c42['attributes'],'include':_0x2b8c42['include']?_[_0xfb83('0x1d')](_0x2b8c42['include'],function(_0x2b5a00){return{'model':db[_0x2b5a00[_0xfb83('0x1e')]],'as':_0x2b5a00['as'],'attributes':_0x2b5a00[_0xfb83('0x1a')],'include':_0x2b5a00['include']?_[_0xfb83('0x1d')](_0x2b5a00[_0xfb83('0x1c')],function(_0x30f5fe){return{'model':db[_0x30f5fe['model']],'as':_0x30f5fe['as'],'attributes':_0x30f5fe[_0xfb83('0x1a')]};}):[]};}):[]};}):[]:[]})[_0xfb83('0xe')](function(_0x5e2e44){logger[_0xfb83('0xf')](_0xfb83('0x1f'),_0x30e8ba);logger[_0xfb83('0x11')]('GetMailQueue',_0x30e8ba,JSON[_0xfb83('0x20')](_0x5e2e44));_0xacd44e(_0x5e2e44);})[_0xfb83('0x21')](function(_0x5bb095){logger[_0xfb83('0x13')](_0xfb83('0x1f'),_0x5bb095[_0xfb83('0x16')],_0x30e8ba);_0x341802(_0x466af2[_0xfb83('0x13')](0x1f4,_0x5bb095[_0xfb83('0x16')]));});});};exports[_0xfb83('0x22')]=function(_0x5b2c8f){var _0x33213d=this;return new Promise(function(_0x5782eb,_0x1bc093){return db[_0xfb83('0x23')][_0xfb83('0x24')]({'raw':_0x5b2c8f[_0xfb83('0x18')]?_0x5b2c8f['options']['raw']===undefined?!![]:![]:!![],'where':_0x5b2c8f[_0xfb83('0x18')]?_0x5b2c8f[_0xfb83('0x18')]['where']||null:null,'attributes':_0x5b2c8f[_0xfb83('0x18')]?_0x5b2c8f[_0xfb83('0x18')][_0xfb83('0x1a')]||null:null,'include':_0x5b2c8f[_0xfb83('0x18')]?_0x5b2c8f[_0xfb83('0x18')][_0xfb83('0x1c')]?_[_0xfb83('0x1d')](_0x5b2c8f[_0xfb83('0x18')][_0xfb83('0x1c')],function(_0xe5483a){return{'model':db[_0xe5483a[_0xfb83('0x1e')]],'as':_0xe5483a['as'],'attributes':_0xe5483a['attributes'],'include':_0xe5483a[_0xfb83('0x1c')]?_[_0xfb83('0x1d')](_0xe5483a[_0xfb83('0x1c')],function(_0x5274f2){return{'model':db[_0x5274f2['model']],'as':_0x5274f2['as'],'attributes':_0x5274f2[_0xfb83('0x1a')],'include':_0x5274f2[_0xfb83('0x1c')]?_['map'](_0x5274f2['include'],function(_0x4e7c21){return{'model':db[_0x4e7c21['model']],'as':_0x4e7c21['as'],'attributes':_0x4e7c21[_0xfb83('0x1a')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x33e4ce){logger[_0xfb83('0xf')](_0xfb83('0x22'),_0x5b2c8f);logger[_0xfb83('0x11')](_0xfb83('0x22'),_0x5b2c8f,JSON[_0xfb83('0x20')](_0x33e4ce));_0x5782eb(_0x33e4ce);})[_0xfb83('0x21')](function(_0x4d4753){logger['error'](_0xfb83('0x22'),_0x4d4753[_0xfb83('0x16')],_0x5b2c8f);_0x1bc093(_0x33213d[_0xfb83('0x13')](0x1f4,_0x4d4753[_0xfb83('0x16')]));});});};