81390ac4c5651484e99706e8527c6feb15c2aecb
[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 _0xc9cc=['catch','MailQueue','find','ShowMailQueue','util','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','client','http','redis','localhost','socket.io-emitter','./mailQueue.socket','register','then','request\x20sent','debug','stringify','error','message','info','MailQueue,\x20%s,\x20%s','result','options','raw','where','attributes','limit','map','include','model','GetMailQueue'];(function(_0x5e5568,_0x300d0d){var _0x557045=function(_0x2ee76c){while(--_0x2ee76c){_0x5e5568['push'](_0x5e5568['shift']());}};_0x557045(++_0x300d0d);}(_0xc9cc,0x162));var _0xcc9c=function(_0x35b07e,_0x4c5a33){_0x35b07e=_0x35b07e-0x0;var _0xcb745e=_0xc9cc[_0x35b07e];return _0xcb745e;};'use strict';var _=require('lodash');var util=require(_0xcc9c('0x0'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0xcc9c('0x1'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xcc9c('0x2'))['db'];var utils=require(_0xcc9c('0x3'));var logger=require(_0xcc9c('0x4'))(_0xcc9c('0x5'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xcc9c('0x6')][_0xcc9c('0x7')]({'port':0x232a});config[_0xcc9c('0x8')]=_['defaults'](config['redis'],{'host':_0xcc9c('0x9'),'port':0x18eb});var socket=require(_0xcc9c('0xa'))(new Redis(config[_0xcc9c('0x8')]));require(_0xcc9c('0xb'))[_0xcc9c('0xc')](socket);function respondWithRpcPromise(_0x250fcd,_0x14168e,_0x3bfe67){return new BPromise(function(_0x5b995b,_0x2d4950){return client['request'](_0x250fcd,_0x3bfe67)[_0xcc9c('0xd')](function(_0x9a16b5){logger['info']('MailQueue,\x20%s,\x20%s',_0x14168e,_0xcc9c('0xe'));logger[_0xcc9c('0xf')]('MailQueue,\x20%s,\x20%s,\x20%s',_0x14168e,_0xcc9c('0xe'),JSON[_0xcc9c('0x10')](_0x9a16b5));if(_0x9a16b5[_0xcc9c('0x11')]){if(_0x9a16b5[_0xcc9c('0x11')]['code']===0x1f4){logger['error']('MailQueue,\x20%s,\x20%s',_0x14168e,_0x9a16b5[_0xcc9c('0x11')][_0xcc9c('0x12')]);return _0x2d4950(_0x9a16b5[_0xcc9c('0x11')][_0xcc9c('0x12')]);}logger['error']('MailQueue,\x20%s,\x20%s',_0x14168e,_0x9a16b5[_0xcc9c('0x11')][_0xcc9c('0x12')]);return _0x5b995b(_0x9a16b5[_0xcc9c('0x11')]['message']);}else{logger[_0xcc9c('0x13')](_0xcc9c('0x14'),_0x14168e,_0xcc9c('0xe'));_0x5b995b(_0x9a16b5[_0xcc9c('0x15')][_0xcc9c('0x12')]);}})['catch'](function(_0x2e32bc){logger['error'](_0xcc9c('0x14'),_0x14168e,_0x2e32bc);_0x2d4950(_0x2e32bc);});});}exports['GetMailQueue']=function(_0x2d0f17){var _0x364c29=this;return new Promise(function(_0x5725e8,_0x1928d7){return db['MailQueue']['findAll']({'raw':_0x2d0f17[_0xcc9c('0x16')]?_0x2d0f17[_0xcc9c('0x16')][_0xcc9c('0x17')]===undefined?!![]:![]:!![],'where':_0x2d0f17[_0xcc9c('0x16')]?_0x2d0f17[_0xcc9c('0x16')][_0xcc9c('0x18')]||null:null,'attributes':_0x2d0f17[_0xcc9c('0x16')]?_0x2d0f17[_0xcc9c('0x16')][_0xcc9c('0x19')]||null:null,'limit':_0x2d0f17[_0xcc9c('0x16')]?_0x2d0f17[_0xcc9c('0x16')][_0xcc9c('0x1a')]||null:null,'include':_0x2d0f17[_0xcc9c('0x16')]?_0x2d0f17[_0xcc9c('0x16')]['include']?_[_0xcc9c('0x1b')](_0x2d0f17[_0xcc9c('0x16')][_0xcc9c('0x1c')],function(_0x436f3f){return{'model':db[_0x436f3f[_0xcc9c('0x1d')]],'as':_0x436f3f['as'],'attributes':_0x436f3f['attributes'],'include':_0x436f3f[_0xcc9c('0x1c')]?_['map'](_0x436f3f[_0xcc9c('0x1c')],function(_0x930b33){return{'model':db[_0x930b33['model']],'as':_0x930b33['as'],'attributes':_0x930b33[_0xcc9c('0x19')],'include':_0x930b33[_0xcc9c('0x1c')]?_[_0xcc9c('0x1b')](_0x930b33[_0xcc9c('0x1c')],function(_0x5c1840){return{'model':db[_0x5c1840[_0xcc9c('0x1d')]],'as':_0x5c1840['as'],'attributes':_0x5c1840[_0xcc9c('0x19')]};}):[]};}):[]};}):[]:[]})[_0xcc9c('0xd')](function(_0xaeb0bd){logger['info'](_0xcc9c('0x1e'),_0x2d0f17);logger[_0xcc9c('0xf')](_0xcc9c('0x1e'),_0x2d0f17,JSON[_0xcc9c('0x10')](_0xaeb0bd));_0x5725e8(_0xaeb0bd);})[_0xcc9c('0x1f')](function(_0x351d22){logger['error'](_0xcc9c('0x1e'),_0x351d22[_0xcc9c('0x12')],_0x2d0f17);_0x1928d7(_0x364c29['error'](0x1f4,_0x351d22[_0xcc9c('0x12')]));});});};exports['ShowMailQueue']=function(_0x23a1db){var _0x1e73aa=this;return new Promise(function(_0x39e241,_0x46a081){return db[_0xcc9c('0x20')][_0xcc9c('0x21')]({'raw':_0x23a1db[_0xcc9c('0x16')]?_0x23a1db['options'][_0xcc9c('0x17')]===undefined?!![]:![]:!![],'where':_0x23a1db[_0xcc9c('0x16')]?_0x23a1db[_0xcc9c('0x16')][_0xcc9c('0x18')]||null:null,'attributes':_0x23a1db[_0xcc9c('0x16')]?_0x23a1db[_0xcc9c('0x16')]['attributes']||null:null,'include':_0x23a1db[_0xcc9c('0x16')]?_0x23a1db[_0xcc9c('0x16')]['include']?_[_0xcc9c('0x1b')](_0x23a1db[_0xcc9c('0x16')][_0xcc9c('0x1c')],function(_0x56ea0e){return{'model':db[_0x56ea0e[_0xcc9c('0x1d')]],'as':_0x56ea0e['as'],'attributes':_0x56ea0e[_0xcc9c('0x19')],'include':_0x56ea0e[_0xcc9c('0x1c')]?_[_0xcc9c('0x1b')](_0x56ea0e[_0xcc9c('0x1c')],function(_0x263b71){return{'model':db[_0x263b71[_0xcc9c('0x1d')]],'as':_0x263b71['as'],'attributes':_0x263b71[_0xcc9c('0x19')],'include':_0x263b71[_0xcc9c('0x1c')]?_[_0xcc9c('0x1b')](_0x263b71['include'],function(_0x3372ed){return{'model':db[_0x3372ed['model']],'as':_0x3372ed['as'],'attributes':_0x3372ed[_0xcc9c('0x19')]};}):[]};}):[]};}):[]:[]})[_0xcc9c('0xd')](function(_0xa58ae2){logger[_0xcc9c('0x13')](_0xcc9c('0x22'),_0x23a1db);logger['debug'](_0xcc9c('0x22'),_0x23a1db,JSON['stringify'](_0xa58ae2));_0x39e241(_0xa58ae2);})[_0xcc9c('0x1f')](function(_0x19c9e6){logger[_0xcc9c('0x11')]('ShowMailQueue',_0x19c9e6['message'],_0x23a1db);_0x46a081(_0x1e73aa[_0xcc9c('0x11')](0x1f4,_0x19c9e6[_0xcc9c('0x12')]));});});};