bf5d715c2cc2263b7327b49e1fc3566fcfeaf62c
[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 _0x2356=['debug','MailQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','GetMailQueue','options','raw','where','attributes','limit','include','model','map','ShowMailQueue','find','util','moment','ioredis','../../mysqldb','rpc','client','http','redis','socket.io-emitter','./mailQueue.socket','register','request','then','MailQueue,\x20%s,\x20%s','request\x20sent'];(function(_0x52f14e,_0x14b5d2){var _0x5c6398=function(_0x1d03b5){while(--_0x1d03b5){_0x52f14e['push'](_0x52f14e['shift']());}};_0x5c6398(++_0x14b5d2);}(_0x2356,0x14f));var _0x6235=function(_0x589cd1,_0x428041){_0x589cd1=_0x589cd1-0x0;var _0x59bb7e=_0x2356[_0x589cd1];return _0x59bb7e;};'use strict';var _=require('lodash');var util=require(_0x6235('0x0'));var moment=require(_0x6235('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x6235('0x2'));var db=require(_0x6235('0x3'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x6235('0x4'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x6235('0x5')][_0x6235('0x6')]({'port':0x232a});config[_0x6235('0x7')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x6235('0x8'))(new Redis(config['redis']));require(_0x6235('0x9'))[_0x6235('0xa')](socket);function respondWithRpcPromise(_0x3e0f96,_0x31fc6e,_0x5de19a){return new BPromise(function(_0x46fecf,_0x1b34a5){return client[_0x6235('0xb')](_0x3e0f96,_0x5de19a)[_0x6235('0xc')](function(_0x14342d){logger['info'](_0x6235('0xd'),_0x31fc6e,_0x6235('0xe'));logger[_0x6235('0xf')](_0x6235('0x10'),_0x31fc6e,'request\x20sent',JSON[_0x6235('0x11')](_0x14342d));if(_0x14342d[_0x6235('0x12')]){if(_0x14342d['error'][_0x6235('0x13')]===0x1f4){logger['error'](_0x6235('0xd'),_0x31fc6e,_0x14342d[_0x6235('0x12')]['message']);return _0x1b34a5(_0x14342d[_0x6235('0x12')][_0x6235('0x14')]);}logger[_0x6235('0x12')](_0x6235('0xd'),_0x31fc6e,_0x14342d['error'][_0x6235('0x14')]);return _0x46fecf(_0x14342d[_0x6235('0x12')][_0x6235('0x14')]);}else{logger[_0x6235('0x15')](_0x6235('0xd'),_0x31fc6e,_0x6235('0xe'));_0x46fecf(_0x14342d[_0x6235('0x16')][_0x6235('0x14')]);}})[_0x6235('0x17')](function(_0x1f8cd3){logger['error'](_0x6235('0xd'),_0x31fc6e,_0x1f8cd3);_0x1b34a5(_0x1f8cd3);});});}exports[_0x6235('0x18')]=function(_0x4a9846){var _0x534dab=this;return new Promise(function(_0x19075e,_0x4f0aa2){return db['MailQueue']['findAll']({'raw':_0x4a9846[_0x6235('0x19')]?_0x4a9846[_0x6235('0x19')][_0x6235('0x1a')]===undefined?!![]:![]:!![],'where':_0x4a9846[_0x6235('0x19')]?_0x4a9846[_0x6235('0x19')][_0x6235('0x1b')]||null:null,'attributes':_0x4a9846['options']?_0x4a9846['options'][_0x6235('0x1c')]||null:null,'limit':_0x4a9846['options']?_0x4a9846[_0x6235('0x19')][_0x6235('0x1d')]||null:null,'include':_0x4a9846[_0x6235('0x19')]?_0x4a9846[_0x6235('0x19')][_0x6235('0x1e')]?_['map'](_0x4a9846[_0x6235('0x19')][_0x6235('0x1e')],function(_0x168b01){return{'model':db[_0x168b01[_0x6235('0x1f')]],'as':_0x168b01['as'],'attributes':_0x168b01[_0x6235('0x1c')],'include':_0x168b01['include']?_['map'](_0x168b01['include'],function(_0x4f28f2){return{'model':db[_0x4f28f2[_0x6235('0x1f')]],'as':_0x4f28f2['as'],'attributes':_0x4f28f2[_0x6235('0x1c')],'include':_0x4f28f2[_0x6235('0x1e')]?_[_0x6235('0x20')](_0x4f28f2[_0x6235('0x1e')],function(_0x2acc8c){return{'model':db[_0x2acc8c['model']],'as':_0x2acc8c['as'],'attributes':_0x2acc8c['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x94db3c){logger['info'](_0x6235('0x18'),_0x4a9846);logger[_0x6235('0xf')]('GetMailQueue',_0x4a9846,JSON[_0x6235('0x11')](_0x94db3c));_0x19075e(_0x94db3c);})[_0x6235('0x17')](function(_0x5bb691){logger[_0x6235('0x12')](_0x6235('0x18'),_0x5bb691[_0x6235('0x14')],_0x4a9846);_0x4f0aa2(_0x534dab[_0x6235('0x12')](0x1f4,_0x5bb691[_0x6235('0x14')]));});});};exports[_0x6235('0x21')]=function(_0x281e01){var _0x43a430=this;return new Promise(function(_0x2bdeda,_0x2e233d){return db['MailQueue'][_0x6235('0x22')]({'raw':_0x281e01['options']?_0x281e01['options'][_0x6235('0x1a')]===undefined?!![]:![]:!![],'where':_0x281e01['options']?_0x281e01['options'][_0x6235('0x1b')]||null:null,'attributes':_0x281e01['options']?_0x281e01['options'][_0x6235('0x1c')]||null:null,'include':_0x281e01[_0x6235('0x19')]?_0x281e01[_0x6235('0x19')]['include']?_[_0x6235('0x20')](_0x281e01[_0x6235('0x19')][_0x6235('0x1e')],function(_0x4db26d){return{'model':db[_0x4db26d[_0x6235('0x1f')]],'as':_0x4db26d['as'],'attributes':_0x4db26d['attributes'],'include':_0x4db26d[_0x6235('0x1e')]?_[_0x6235('0x20')](_0x4db26d[_0x6235('0x1e')],function(_0xcb0901){return{'model':db[_0xcb0901[_0x6235('0x1f')]],'as':_0xcb0901['as'],'attributes':_0xcb0901['attributes'],'include':_0xcb0901[_0x6235('0x1e')]?_['map'](_0xcb0901[_0x6235('0x1e')],function(_0x706301){return{'model':db[_0x706301[_0x6235('0x1f')]],'as':_0x706301['as'],'attributes':_0x706301[_0x6235('0x1c')]};}):[]};}):[]};}):[]:[]})[_0x6235('0xc')](function(_0x4f0461){logger['info'](_0x6235('0x21'),_0x281e01);logger[_0x6235('0xf')](_0x6235('0x21'),_0x281e01,JSON[_0x6235('0x11')](_0x4f0461));_0x2bdeda(_0x4f0461);})[_0x6235('0x17')](function(_0x4057aa){logger[_0x6235('0x12')](_0x6235('0x21'),_0x4057aa[_0x6235('0x14')],_0x281e01);_0x2e233d(_0x43a430[_0x6235('0x12')](0x1f4,_0x4057aa['message']));});});};