Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / api / mailInteraction / mailInteraction.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 _0x36b6=['socket.io-emitter','./mailInteraction.socket','register','then','MailInteraction,\x20%s,\x20%s','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','message','info','result','catch','UpdateMailInteraction','body','options','raw','attributes','limit','MailInteraction','find','where','addTags','ids','omit','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults'];(function(_0x10bbb8,_0x19e2eb){var _0x2026a0=function(_0x36420e){while(--_0x36420e){_0x10bbb8['push'](_0x10bbb8['shift']());}};_0x2026a0(++_0x19e2eb);}(_0x36b6,0x13a));var _0x636b=function(_0x43bee1,_0x10ad81){_0x43bee1=_0x43bee1-0x0;var _0x2fedfd=_0x36b6[_0x43bee1];return _0x2fedfd;};'use strict';var _=require(_0x636b('0x0'));var util=require(_0x636b('0x1'));var moment=require(_0x636b('0x2'));var BPromise=require(_0x636b('0x3'));var rs=require(_0x636b('0x4'));var fs=require('fs');var Redis=require(_0x636b('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x636b('0x6'));var logger=require(_0x636b('0x7'))('rpc');var config=require(_0x636b('0x8'));var jayson=require(_0x636b('0x9'));var client=jayson[_0x636b('0xa')][_0x636b('0xb')]({'port':0x232a});config[_0x636b('0xc')]=_[_0x636b('0xd')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x636b('0xe'))(new Redis(config['redis']));require(_0x636b('0xf'))[_0x636b('0x10')](socket);function respondWithRpcPromise(_0x194d35,_0x17f029,_0x335202){return new BPromise(function(_0x1a9458,_0x9b7d57){return client['request'](_0x194d35,_0x335202)[_0x636b('0x11')](function(_0x44b913){logger['info'](_0x636b('0x12'),_0x17f029,_0x636b('0x13'));logger[_0x636b('0x14')](_0x636b('0x15'),_0x17f029,_0x636b('0x13'),JSON[_0x636b('0x16')](_0x44b913));if(_0x44b913['error']){if(_0x44b913[_0x636b('0x17')]['code']===0x1f4){logger[_0x636b('0x17')]('MailInteraction,\x20%s,\x20%s',_0x17f029,_0x44b913[_0x636b('0x17')][_0x636b('0x18')]);return _0x9b7d57(_0x44b913['error'][_0x636b('0x18')]);}logger[_0x636b('0x17')](_0x636b('0x12'),_0x17f029,_0x44b913[_0x636b('0x17')][_0x636b('0x18')]);return _0x1a9458(_0x44b913[_0x636b('0x17')][_0x636b('0x18')]);}else{logger[_0x636b('0x19')](_0x636b('0x12'),_0x17f029,'request\x20sent');_0x1a9458(_0x44b913[_0x636b('0x1a')][_0x636b('0x18')]);}})[_0x636b('0x1b')](function(_0x39ad09){logger[_0x636b('0x17')]('MailInteraction,\x20%s,\x20%s',_0x17f029,_0x39ad09);_0x9b7d57(_0x39ad09);});});}exports[_0x636b('0x1c')]=function(_0x13bdfe){var _0x32edd7=this;return new Promise(function(_0x3cdfa9,_0x1d3b59){return db['MailInteraction']['update'](_0x13bdfe[_0x636b('0x1d')],{'raw':_0x13bdfe[_0x636b('0x1e')]?_0x13bdfe['options'][_0x636b('0x1f')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x13bdfe[_0x636b('0x1e')]?_0x13bdfe['options']['where']||null:null,'attributes':_0x13bdfe[_0x636b('0x1e')]?_0x13bdfe[_0x636b('0x1e')][_0x636b('0x20')]||null:null,'limit':_0x13bdfe[_0x636b('0x1e')]?_0x13bdfe[_0x636b('0x1e')][_0x636b('0x21')]||null:null})['then'](function(_0xca2ad9){logger[_0x636b('0x19')](_0x636b('0x1c'),_0x13bdfe);logger[_0x636b('0x14')](_0x636b('0x1c'),_0x13bdfe,JSON[_0x636b('0x16')](_0xca2ad9));_0x3cdfa9(_0xca2ad9);})['catch'](function(_0xb2a375){logger[_0x636b('0x17')](_0x636b('0x1c'),_0xb2a375['message'],_0x13bdfe);_0x1d3b59(_0x32edd7[_0x636b('0x17')](0x1f4,_0xb2a375[_0x636b('0x18')]));});});};exports['AddTagsToMailInteraction']=function(_0x26e659){return new Promise(function(_0x1f6224,_0x10da22){return db[_0x636b('0x22')][_0x636b('0x23')]({'where':_0x26e659[_0x636b('0x1e')]?_0x26e659[_0x636b('0x1e')][_0x636b('0x24')]||null:null})[_0x636b('0x11')](function(_0x5a00d6){if(_0x5a00d6){return _0x5a00d6[_0x636b('0x25')](_0x26e659[_0x636b('0x1d')][_0x636b('0x26')],_[_0x636b('0x27')](_0x26e659[_0x636b('0x1d')],[_0x636b('0x26'),'id'])||{});}})['spread'](function(_0x14480c){logger[_0x636b('0x19')](_0x636b('0x28'),_0x26e659);logger[_0x636b('0x14')](_0x636b('0x28'),_0x26e659,JSON[_0x636b('0x16')](_0x14480c));_0x1f6224(_0x14480c);})[_0x636b('0x1b')](function(_0xfb3200){logger[_0x636b('0x17')](_0x636b('0x28'),_0xfb3200[_0x636b('0x18')],_0x26e659);_0x10da22(_this[_0x636b('0x17')](0x1f4,_0xfb3200[_0x636b('0x18')]));});});};