0e263fe8af3f7bd3f23fa4ba12ffe79425e8da45
[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 _0x40f6=['jayson/promise','http','defaults','localhost','socket.io-emitter','./mailQueue.socket','register','request','then','info','request\x20sent','debug','MailQueue,\x20%s,\x20%s,\x20%s','error','code','message','MailQueue,\x20%s,\x20%s','result','catch','GetMailQueue','MailQueue','findAll','options','raw','attributes','limit','include','map','model','stringify','ShowMailQueue','find','where','moment','bluebird','../../mysqldb','../../config/utils','../../config/environment'];(function(_0x47d30b,_0x3666c6){var _0x26a9af=function(_0x3d2f67){while(--_0x3d2f67){_0x47d30b['push'](_0x47d30b['shift']());}};_0x26a9af(++_0x3666c6);}(_0x40f6,0x151));var _0x640f=function(_0x4f746b,_0x10d164){_0x4f746b=_0x4f746b-0x0;var _0x21787e=_0x40f6[_0x4f746b];return _0x21787e;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x640f('0x0'));var BPromise=require(_0x640f('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x640f('0x2'))['db'];var utils=require(_0x640f('0x3'));var logger=require('../../config/logger')('rpc');var config=require(_0x640f('0x4'));var jayson=require(_0x640f('0x5'));var client=jayson['client'][_0x640f('0x6')]({'port':0x232a});config['redis']=_[_0x640f('0x7')](config['redis'],{'host':_0x640f('0x8'),'port':0x18eb});var socket=require(_0x640f('0x9'))(new Redis(config['redis']));require(_0x640f('0xa'))[_0x640f('0xb')](socket);function respondWithRpcPromise(_0x25d8d2,_0x4ca9c6,_0x43a00e){return new BPromise(function(_0x3fe165,_0x4445bc){return client[_0x640f('0xc')](_0x25d8d2,_0x43a00e)[_0x640f('0xd')](function(_0x3b1776){logger[_0x640f('0xe')]('MailQueue,\x20%s,\x20%s',_0x4ca9c6,_0x640f('0xf'));logger[_0x640f('0x10')](_0x640f('0x11'),_0x4ca9c6,_0x640f('0xf'),JSON['stringify'](_0x3b1776));if(_0x3b1776[_0x640f('0x12')]){if(_0x3b1776[_0x640f('0x12')][_0x640f('0x13')]===0x1f4){logger['error']('MailQueue,\x20%s,\x20%s',_0x4ca9c6,_0x3b1776[_0x640f('0x12')]['message']);return _0x4445bc(_0x3b1776['error'][_0x640f('0x14')]);}logger[_0x640f('0x12')](_0x640f('0x15'),_0x4ca9c6,_0x3b1776['error'][_0x640f('0x14')]);return _0x3fe165(_0x3b1776[_0x640f('0x12')][_0x640f('0x14')]);}else{logger[_0x640f('0xe')](_0x640f('0x15'),_0x4ca9c6,'request\x20sent');_0x3fe165(_0x3b1776[_0x640f('0x16')][_0x640f('0x14')]);}})[_0x640f('0x17')](function(_0x1d6be5){logger[_0x640f('0x12')](_0x640f('0x15'),_0x4ca9c6,_0x1d6be5);_0x4445bc(_0x1d6be5);});});}exports[_0x640f('0x18')]=function(_0x51333f){var _0x3de38d=this;return new Promise(function(_0x552082,_0x16df70){return db[_0x640f('0x19')][_0x640f('0x1a')]({'raw':_0x51333f[_0x640f('0x1b')]?_0x51333f['options'][_0x640f('0x1c')]===undefined?!![]:![]:!![],'where':_0x51333f['options']?_0x51333f[_0x640f('0x1b')]['where']||null:null,'attributes':_0x51333f[_0x640f('0x1b')]?_0x51333f[_0x640f('0x1b')][_0x640f('0x1d')]||null:null,'limit':_0x51333f['options']?_0x51333f[_0x640f('0x1b')][_0x640f('0x1e')]||null:null,'include':_0x51333f[_0x640f('0x1b')]?_0x51333f[_0x640f('0x1b')][_0x640f('0x1f')]?_['map'](_0x51333f[_0x640f('0x1b')][_0x640f('0x1f')],function(_0x2fb992){return{'model':db[_0x2fb992['model']],'as':_0x2fb992['as'],'attributes':_0x2fb992[_0x640f('0x1d')],'include':_0x2fb992['include']?_['map'](_0x2fb992['include'],function(_0x19d3c5){return{'model':db[_0x19d3c5['model']],'as':_0x19d3c5['as'],'attributes':_0x19d3c5[_0x640f('0x1d')],'include':_0x19d3c5[_0x640f('0x1f')]?_[_0x640f('0x20')](_0x19d3c5[_0x640f('0x1f')],function(_0x38f592){return{'model':db[_0x38f592[_0x640f('0x21')]],'as':_0x38f592['as'],'attributes':_0x38f592['attributes']};}):[]};}):[]};}):[]:[]})[_0x640f('0xd')](function(_0x4af338){logger[_0x640f('0xe')]('GetMailQueue',_0x51333f);logger[_0x640f('0x10')](_0x640f('0x18'),_0x51333f,JSON[_0x640f('0x22')](_0x4af338));_0x552082(_0x4af338);})[_0x640f('0x17')](function(_0x5de2ed){logger[_0x640f('0x12')](_0x640f('0x18'),_0x5de2ed[_0x640f('0x14')],_0x51333f);_0x16df70(_0x3de38d[_0x640f('0x12')](0x1f4,_0x5de2ed['message']));});});};exports[_0x640f('0x23')]=function(_0x5da5e7){var _0x1a2886=this;return new Promise(function(_0x404800,_0x2251df){return db[_0x640f('0x19')][_0x640f('0x24')]({'raw':_0x5da5e7[_0x640f('0x1b')]?_0x5da5e7[_0x640f('0x1b')][_0x640f('0x1c')]===undefined?!![]:![]:!![],'where':_0x5da5e7[_0x640f('0x1b')]?_0x5da5e7['options'][_0x640f('0x25')]||null:null,'attributes':_0x5da5e7['options']?_0x5da5e7[_0x640f('0x1b')][_0x640f('0x1d')]||null:null,'include':_0x5da5e7[_0x640f('0x1b')]?_0x5da5e7['options'][_0x640f('0x1f')]?_[_0x640f('0x20')](_0x5da5e7[_0x640f('0x1b')][_0x640f('0x1f')],function(_0x13ab8c){return{'model':db[_0x13ab8c[_0x640f('0x21')]],'as':_0x13ab8c['as'],'attributes':_0x13ab8c['attributes'],'include':_0x13ab8c['include']?_['map'](_0x13ab8c[_0x640f('0x1f')],function(_0x4b9f0e){return{'model':db[_0x4b9f0e[_0x640f('0x21')]],'as':_0x4b9f0e['as'],'attributes':_0x4b9f0e[_0x640f('0x1d')],'include':_0x4b9f0e['include']?_['map'](_0x4b9f0e[_0x640f('0x1f')],function(_0x4a427f){return{'model':db[_0x4a427f[_0x640f('0x21')]],'as':_0x4a427f['as'],'attributes':_0x4a427f[_0x640f('0x1d')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x25a821){logger[_0x640f('0xe')]('ShowMailQueue',_0x5da5e7);logger['debug'](_0x640f('0x23'),_0x5da5e7,JSON['stringify'](_0x25a821));_0x404800(_0x25a821);})[_0x640f('0x17')](function(_0xe03756){logger['error']('ShowMailQueue',_0xe03756[_0x640f('0x14')],_0x5da5e7);_0x2251df(_0x1a2886[_0x640f('0x12')](0x1f4,_0xe03756[_0x640f('0x14')]));});});};