53b82238dd5ec7cb99f8c3756edcb4a519c3042f
[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 _0x3b40=['options','raw','where','debug','catch','find','ids','spread','AddTags','stringify','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','http','defaults','localhost','redis','./mailInteraction.socket','request','then','info','MailInteraction,\x20%s,\x20%s','request\x20sent','MailInteraction,\x20%s,\x20%s,\x20%s','error','message','result','UpdateMailInteraction','MailInteraction','update','body'];(function(_0x4fdb42,_0x4cd32b){var _0x33389c=function(_0x4e0266){while(--_0x4e0266){_0x4fdb42['push'](_0x4fdb42['shift']());}};_0x33389c(++_0x4cd32b);}(_0x3b40,0x13a));var _0x03b4=function(_0x306d0f,_0x151722){_0x306d0f=_0x306d0f-0x0;var _0x41a6ff=_0x3b40[_0x306d0f];return _0x41a6ff;};'use strict';var _=require('lodash');var util=require(_0x03b4('0x0'));var moment=require(_0x03b4('0x1'));var BPromise=require(_0x03b4('0x2'));var rs=require(_0x03b4('0x3'));var fs=require('fs');var Redis=require(_0x03b4('0x4'));var db=require(_0x03b4('0x5'))['db'];var utils=require(_0x03b4('0x6'));var logger=require(_0x03b4('0x7'))(_0x03b4('0x8'));var config=require('../../config/environment');var jayson=require(_0x03b4('0x9'));var client=jayson['client'][_0x03b4('0xa')]({'port':0x232a});config['redis']=_[_0x03b4('0xb')](config['redis'],{'host':_0x03b4('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x03b4('0xd')]));require(_0x03b4('0xe'))['register'](socket);function respondWithRpcPromise(_0x2cb754,_0x59d040,_0x40778d){return new BPromise(function(_0x4506bd,_0x7f992c){return client[_0x03b4('0xf')](_0x2cb754,_0x40778d)[_0x03b4('0x10')](function(_0x379b02){logger[_0x03b4('0x11')](_0x03b4('0x12'),_0x59d040,_0x03b4('0x13'));logger['debug'](_0x03b4('0x14'),_0x59d040,_0x03b4('0x13'),JSON['stringify'](_0x379b02));if(_0x379b02[_0x03b4('0x15')]){if(_0x379b02[_0x03b4('0x15')]['code']===0x1f4){logger['error'](_0x03b4('0x12'),_0x59d040,_0x379b02[_0x03b4('0x15')][_0x03b4('0x16')]);return _0x7f992c(_0x379b02[_0x03b4('0x15')][_0x03b4('0x16')]);}logger[_0x03b4('0x15')]('MailInteraction,\x20%s,\x20%s',_0x59d040,_0x379b02[_0x03b4('0x15')]['message']);return _0x4506bd(_0x379b02['error'][_0x03b4('0x16')]);}else{logger[_0x03b4('0x11')](_0x03b4('0x12'),_0x59d040,'request\x20sent');_0x4506bd(_0x379b02[_0x03b4('0x17')][_0x03b4('0x16')]);}})['catch'](function(_0xc10a0f){logger[_0x03b4('0x15')](_0x03b4('0x12'),_0x59d040,_0xc10a0f);_0x7f992c(_0xc10a0f);});});}exports[_0x03b4('0x18')]=function(_0x435ec4){var _0x9aa2a8=this;return new Promise(function(_0x3bc69f,_0x3e6c00){return db[_0x03b4('0x19')][_0x03b4('0x1a')](_0x435ec4[_0x03b4('0x1b')],{'raw':_0x435ec4[_0x03b4('0x1c')]?_0x435ec4[_0x03b4('0x1c')][_0x03b4('0x1d')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x435ec4[_0x03b4('0x1c')]?_0x435ec4[_0x03b4('0x1c')][_0x03b4('0x1e')]||null:null,'attributes':_0x435ec4[_0x03b4('0x1c')]?_0x435ec4[_0x03b4('0x1c')]['attributes']||null:null,'limit':_0x435ec4[_0x03b4('0x1c')]?_0x435ec4[_0x03b4('0x1c')]['limit']||null:null})[_0x03b4('0x10')](function(_0x11acc0){logger[_0x03b4('0x11')](_0x03b4('0x18'),_0x435ec4);logger[_0x03b4('0x1f')](_0x03b4('0x18'),_0x435ec4,JSON['stringify'](_0x11acc0));_0x3bc69f(_0x11acc0);})[_0x03b4('0x20')](function(_0x54fbcb){logger['error']('UpdateMailInteraction',_0x54fbcb[_0x03b4('0x16')],_0x435ec4);_0x3e6c00(_0x9aa2a8[_0x03b4('0x15')](0x1f4,_0x54fbcb[_0x03b4('0x16')]));});});};exports['AddTagsToMailInteraction']=function(_0x488e98){return new Promise(function(_0x1c9c38,_0x4e869f){return db[_0x03b4('0x19')][_0x03b4('0x21')]({'where':_0x488e98[_0x03b4('0x1c')]?_0x488e98['options']['where']||null:null})[_0x03b4('0x10')](function(_0x3554e9){if(_0x3554e9){return _0x3554e9['addTags'](_0x488e98[_0x03b4('0x1b')][_0x03b4('0x22')],_['omit'](_0x488e98[_0x03b4('0x1b')],['ids','id'])||{});}})[_0x03b4('0x23')](function(_0x1654af){logger[_0x03b4('0x11')]('AddTags',_0x488e98);logger[_0x03b4('0x1f')](_0x03b4('0x24'),_0x488e98,JSON[_0x03b4('0x25')](_0x1654af));_0x1c9c38(_0x1654af);})[_0x03b4('0x20')](function(_0x9dea3c){logger['error']('AddTags',_0x9dea3c[_0x03b4('0x16')],_0x488e98);_0x4e869f(_this[_0x03b4('0x15')](0x1f4,_0x9dea3c['message']));});});};