Built motion from commit 06eb8eb0.|2.6.31
[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 _0xf281=['http','redis','defaults','socket.io-emitter','./mailQueue.socket','request','then','info','request\x20sent','debug','MailQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','MailQueue,\x20%s,\x20%s','message','result','MailQueue','options','where','limit','map','include','model','attributes','GetMailQueue','catch','ShowMailQueue','find','raw','util','moment','bluebird','ioredis','../../config/logger','rpc','../../config/environment','jayson/promise','client'];(function(_0x1e6f9e,_0x3e91bb){var _0x198686=function(_0x31758f){while(--_0x31758f){_0x1e6f9e['push'](_0x1e6f9e['shift']());}};_0x198686(++_0x3e91bb);}(_0xf281,0xba));var _0x1f28=function(_0x145791,_0x21f198){_0x145791=_0x145791-0x0;var _0x2900ea=_0xf281[_0x145791];return _0x2900ea;};'use strict';var _=require('lodash');var util=require(_0x1f28('0x0'));var moment=require(_0x1f28('0x1'));var BPromise=require(_0x1f28('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x1f28('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x1f28('0x4'))(_0x1f28('0x5'));var config=require(_0x1f28('0x6'));var jayson=require(_0x1f28('0x7'));var client=jayson[_0x1f28('0x8')][_0x1f28('0x9')]({'port':0x232a});config[_0x1f28('0xa')]=_[_0x1f28('0xb')](config[_0x1f28('0xa')],{'host':'localhost','port':0x18eb});var socket=require(_0x1f28('0xc'))(new Redis(config['redis']));require(_0x1f28('0xd'))['register'](socket);function respondWithRpcPromise(_0x13168d,_0x3e16cc,_0x24c01f){return new BPromise(function(_0x55ed8a,_0x25f3fc){return client[_0x1f28('0xe')](_0x13168d,_0x24c01f)[_0x1f28('0xf')](function(_0x16ca28){logger[_0x1f28('0x10')]('MailQueue,\x20%s,\x20%s',_0x3e16cc,_0x1f28('0x11'));logger[_0x1f28('0x12')](_0x1f28('0x13'),_0x3e16cc,_0x1f28('0x11'),JSON[_0x1f28('0x14')](_0x16ca28));if(_0x16ca28['error']){if(_0x16ca28[_0x1f28('0x15')][_0x1f28('0x16')]===0x1f4){logger[_0x1f28('0x15')](_0x1f28('0x17'),_0x3e16cc,_0x16ca28['error'][_0x1f28('0x18')]);return _0x25f3fc(_0x16ca28[_0x1f28('0x15')]['message']);}logger[_0x1f28('0x15')](_0x1f28('0x17'),_0x3e16cc,_0x16ca28['error'][_0x1f28('0x18')]);return _0x55ed8a(_0x16ca28[_0x1f28('0x15')][_0x1f28('0x18')]);}else{logger[_0x1f28('0x10')]('MailQueue,\x20%s,\x20%s',_0x3e16cc,_0x1f28('0x11'));_0x55ed8a(_0x16ca28[_0x1f28('0x19')]['message']);}})['catch'](function(_0xda4243){logger[_0x1f28('0x15')](_0x1f28('0x17'),_0x3e16cc,_0xda4243);_0x25f3fc(_0xda4243);});});}exports['GetMailQueue']=function(_0x4499f6){var _0x1d945e=this;return new Promise(function(_0x12fdb6,_0x526a9d){return db[_0x1f28('0x1a')]['findAll']({'raw':_0x4499f6[_0x1f28('0x1b')]?_0x4499f6[_0x1f28('0x1b')]['raw']===undefined?!![]:![]:!![],'where':_0x4499f6[_0x1f28('0x1b')]?_0x4499f6[_0x1f28('0x1b')][_0x1f28('0x1c')]||null:null,'attributes':_0x4499f6['options']?_0x4499f6[_0x1f28('0x1b')]['attributes']||null:null,'limit':_0x4499f6[_0x1f28('0x1b')]?_0x4499f6[_0x1f28('0x1b')][_0x1f28('0x1d')]||null:null,'include':_0x4499f6[_0x1f28('0x1b')]?_0x4499f6[_0x1f28('0x1b')]['include']?_[_0x1f28('0x1e')](_0x4499f6[_0x1f28('0x1b')][_0x1f28('0x1f')],function(_0x4409d6){return{'model':db[_0x4409d6[_0x1f28('0x20')]],'as':_0x4409d6['as'],'attributes':_0x4409d6[_0x1f28('0x21')],'include':_0x4409d6[_0x1f28('0x1f')]?_[_0x1f28('0x1e')](_0x4409d6[_0x1f28('0x1f')],function(_0x27600f){return{'model':db[_0x27600f[_0x1f28('0x20')]],'as':_0x27600f['as'],'attributes':_0x27600f[_0x1f28('0x21')],'include':_0x27600f['include']?_[_0x1f28('0x1e')](_0x27600f[_0x1f28('0x1f')],function(_0x4aa175){return{'model':db[_0x4aa175[_0x1f28('0x20')]],'as':_0x4aa175['as'],'attributes':_0x4aa175[_0x1f28('0x21')]};}):[]};}):[]};}):[]:[]})[_0x1f28('0xf')](function(_0x119f64){logger[_0x1f28('0x10')](_0x1f28('0x22'),_0x4499f6);logger['debug'](_0x1f28('0x22'),_0x4499f6,JSON['stringify'](_0x119f64));_0x12fdb6(_0x119f64);})[_0x1f28('0x23')](function(_0x2d75ab){logger[_0x1f28('0x15')](_0x1f28('0x22'),_0x2d75ab['message'],_0x4499f6);_0x526a9d(_0x1d945e['error'](0x1f4,_0x2d75ab[_0x1f28('0x18')]));});});};exports[_0x1f28('0x24')]=function(_0x687294){var _0x457c3e=this;return new Promise(function(_0x555595,_0x12d0c4){return db[_0x1f28('0x1a')][_0x1f28('0x25')]({'raw':_0x687294['options']?_0x687294[_0x1f28('0x1b')][_0x1f28('0x26')]===undefined?!![]:![]:!![],'where':_0x687294[_0x1f28('0x1b')]?_0x687294[_0x1f28('0x1b')][_0x1f28('0x1c')]||null:null,'attributes':_0x687294[_0x1f28('0x1b')]?_0x687294[_0x1f28('0x1b')][_0x1f28('0x21')]||null:null,'include':_0x687294[_0x1f28('0x1b')]?_0x687294[_0x1f28('0x1b')]['include']?_[_0x1f28('0x1e')](_0x687294[_0x1f28('0x1b')][_0x1f28('0x1f')],function(_0x2488e4){return{'model':db[_0x2488e4[_0x1f28('0x20')]],'as':_0x2488e4['as'],'attributes':_0x2488e4[_0x1f28('0x21')],'include':_0x2488e4['include']?_['map'](_0x2488e4[_0x1f28('0x1f')],function(_0xe75a3d){return{'model':db[_0xe75a3d[_0x1f28('0x20')]],'as':_0xe75a3d['as'],'attributes':_0xe75a3d[_0x1f28('0x21')],'include':_0xe75a3d[_0x1f28('0x1f')]?_['map'](_0xe75a3d[_0x1f28('0x1f')],function(_0x3eed7e){return{'model':db[_0x3eed7e[_0x1f28('0x20')]],'as':_0x3eed7e['as'],'attributes':_0x3eed7e[_0x1f28('0x21')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x5c496f){logger[_0x1f28('0x10')](_0x1f28('0x24'),_0x687294);logger[_0x1f28('0x12')]('ShowMailQueue',_0x687294,JSON[_0x1f28('0x14')](_0x5c496f));_0x555595(_0x5c496f);})[_0x1f28('0x23')](function(_0x4f8987){logger[_0x1f28('0x15')](_0x1f28('0x24'),_0x4f8987[_0x1f28('0x18')],_0x687294);_0x12d0c4(_0x457c3e[_0x1f28('0x15')](0x1f4,_0x4f8987[_0x1f28('0x18')]));});});};