f2b67bacb7427b8cce1d664fb928a89019215bfa
[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 _0xf431=['jayson/promise','client','http','redis','localhost','socket.io-emitter','./mailInteraction.socket','register','request','then','info','MailInteraction,\x20%s,\x20%s','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','UpdateMailInteraction','body','options','where','attributes','limit','AddTagsToMailInteraction','find','addTags','ids','omit','spread','AddTags','lodash','util','moment','bluebird','randomstring','../../mysqldb','rpc','../../config/environment'];(function(_0x35d45d,_0x4b71fe){var _0x2543bc=function(_0x1e75b5){while(--_0x1e75b5){_0x35d45d['push'](_0x35d45d['shift']());}};_0x2543bc(++_0x4b71fe);}(_0xf431,0xc5));var _0x1f43=function(_0x4496d4,_0x35a23c){_0x4496d4=_0x4496d4-0x0;var _0x549149=_0xf431[_0x4496d4];return _0x549149;};'use strict';var _=require(_0x1f43('0x0'));var util=require(_0x1f43('0x1'));var moment=require(_0x1f43('0x2'));var BPromise=require(_0x1f43('0x3'));var rs=require(_0x1f43('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x1f43('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x1f43('0x6'));var config=require(_0x1f43('0x7'));var jayson=require(_0x1f43('0x8'));var client=jayson[_0x1f43('0x9')][_0x1f43('0xa')]({'port':0x232a});config['redis']=_['defaults'](config[_0x1f43('0xb')],{'host':_0x1f43('0xc'),'port':0x18eb});var socket=require(_0x1f43('0xd'))(new Redis(config['redis']));require(_0x1f43('0xe'))[_0x1f43('0xf')](socket);function respondWithRpcPromise(_0x4563e0,_0x255f7c,_0x3dd6a5){return new BPromise(function(_0x1ca41c,_0x18f247){return client[_0x1f43('0x10')](_0x4563e0,_0x3dd6a5)[_0x1f43('0x11')](function(_0x4bf5c3){logger[_0x1f43('0x12')](_0x1f43('0x13'),_0x255f7c,_0x1f43('0x14'));logger[_0x1f43('0x15')](_0x1f43('0x16'),_0x255f7c,_0x1f43('0x14'),JSON[_0x1f43('0x17')](_0x4bf5c3));if(_0x4bf5c3[_0x1f43('0x18')]){if(_0x4bf5c3[_0x1f43('0x18')][_0x1f43('0x19')]===0x1f4){logger['error'](_0x1f43('0x13'),_0x255f7c,_0x4bf5c3[_0x1f43('0x18')][_0x1f43('0x1a')]);return _0x18f247(_0x4bf5c3[_0x1f43('0x18')][_0x1f43('0x1a')]);}logger['error']('MailInteraction,\x20%s,\x20%s',_0x255f7c,_0x4bf5c3[_0x1f43('0x18')]['message']);return _0x1ca41c(_0x4bf5c3['error']['message']);}else{logger[_0x1f43('0x12')]('MailInteraction,\x20%s,\x20%s',_0x255f7c,_0x1f43('0x14'));_0x1ca41c(_0x4bf5c3['result'][_0x1f43('0x1a')]);}})[_0x1f43('0x1b')](function(_0x5de53f){logger[_0x1f43('0x18')](_0x1f43('0x13'),_0x255f7c,_0x5de53f);_0x18f247(_0x5de53f);});});}exports[_0x1f43('0x1c')]=function(_0x2314e7){var _0x49e379=this;return new Promise(function(_0x10640f,_0x493908){return db['MailInteraction']['update'](_0x2314e7[_0x1f43('0x1d')],{'raw':_0x2314e7[_0x1f43('0x1e')]?_0x2314e7[_0x1f43('0x1e')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x2314e7['options']?_0x2314e7[_0x1f43('0x1e')][_0x1f43('0x1f')]||null:null,'attributes':_0x2314e7['options']?_0x2314e7[_0x1f43('0x1e')][_0x1f43('0x20')]||null:null,'limit':_0x2314e7[_0x1f43('0x1e')]?_0x2314e7['options'][_0x1f43('0x21')]||null:null})['then'](function(_0x4735ae){logger[_0x1f43('0x12')](_0x1f43('0x1c'),_0x2314e7);logger[_0x1f43('0x15')](_0x1f43('0x1c'),_0x2314e7,JSON[_0x1f43('0x17')](_0x4735ae));_0x10640f(_0x4735ae);})[_0x1f43('0x1b')](function(_0x5e3bfc){logger['error'](_0x1f43('0x1c'),_0x5e3bfc[_0x1f43('0x1a')],_0x2314e7);_0x493908(_0x49e379[_0x1f43('0x18')](0x1f4,_0x5e3bfc['message']));});});};exports[_0x1f43('0x22')]=function(_0x28cc88){return new Promise(function(_0x387993,_0x5f54a4){return db['MailInteraction'][_0x1f43('0x23')]({'where':_0x28cc88[_0x1f43('0x1e')]?_0x28cc88['options'][_0x1f43('0x1f')]||null:null})[_0x1f43('0x11')](function(_0x6b42a){if(_0x6b42a){return _0x6b42a[_0x1f43('0x24')](_0x28cc88[_0x1f43('0x1d')][_0x1f43('0x25')],_[_0x1f43('0x26')](_0x28cc88['body'],[_0x1f43('0x25'),'id'])||{});}})[_0x1f43('0x27')](function(_0x24ed31){logger['info'](_0x1f43('0x28'),_0x28cc88);logger[_0x1f43('0x15')]('AddTags',_0x28cc88,JSON[_0x1f43('0x17')](_0x24ed31));_0x387993(_0x24ed31);})[_0x1f43('0x1b')](function(_0x2200da){logger[_0x1f43('0x18')](_0x1f43('0x28'),_0x2200da[_0x1f43('0x1a')],_0x28cc88);_0x5f54a4(_this[_0x1f43('0x18')](0x1f4,_0x2200da[_0x1f43('0x1a')]));});});};