Built motion from commit 2e4747fd.|2.6.7
[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 _0xb58d=['where','limit','find','addTags','omit','AddTags','lodash','util','moment','ioredis','../../config/utils','rpc','../../config/environment','jayson/promise','client','redis','./mailInteraction.socket','request','then','info','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','MailInteraction,\x20%s,\x20%s','result','catch','UpdateMailInteraction','MailInteraction','body','options','raw'];(function(_0x819464,_0x46fc91){var _0x49dcc0=function(_0x36b2b2){while(--_0x36b2b2){_0x819464['push'](_0x819464['shift']());}};_0x49dcc0(++_0x46fc91);}(_0xb58d,0x141));var _0xdb58=function(_0x1d969b,_0x2fd4cf){_0x1d969b=_0x1d969b-0x0;var _0x51b725=_0xb58d[_0x1d969b];return _0x51b725;};'use strict';var _=require(_0xdb58('0x0'));var util=require(_0xdb58('0x1'));var moment=require(_0xdb58('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xdb58('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0xdb58('0x4'));var logger=require('../../config/logger')(_0xdb58('0x5'));var config=require(_0xdb58('0x6'));var jayson=require(_0xdb58('0x7'));var client=jayson[_0xdb58('0x8')]['http']({'port':0x232a});config[_0xdb58('0x9')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xdb58('0x9')]));require(_0xdb58('0xa'))['register'](socket);function respondWithRpcPromise(_0x40f717,_0x1a82e3,_0x2e2941){return new BPromise(function(_0x2c3ac6,_0x3e27d5){return client[_0xdb58('0xb')](_0x40f717,_0x2e2941)[_0xdb58('0xc')](function(_0x12d192){logger[_0xdb58('0xd')]('MailInteraction,\x20%s,\x20%s',_0x1a82e3,_0xdb58('0xe'));logger[_0xdb58('0xf')](_0xdb58('0x10'),_0x1a82e3,_0xdb58('0xe'),JSON[_0xdb58('0x11')](_0x12d192));if(_0x12d192[_0xdb58('0x12')]){if(_0x12d192[_0xdb58('0x12')][_0xdb58('0x13')]===0x1f4){logger[_0xdb58('0x12')]('MailInteraction,\x20%s,\x20%s',_0x1a82e3,_0x12d192[_0xdb58('0x12')][_0xdb58('0x14')]);return _0x3e27d5(_0x12d192['error']['message']);}logger[_0xdb58('0x12')](_0xdb58('0x15'),_0x1a82e3,_0x12d192[_0xdb58('0x12')][_0xdb58('0x14')]);return _0x2c3ac6(_0x12d192['error'][_0xdb58('0x14')]);}else{logger[_0xdb58('0xd')]('MailInteraction,\x20%s,\x20%s',_0x1a82e3,_0xdb58('0xe'));_0x2c3ac6(_0x12d192[_0xdb58('0x16')][_0xdb58('0x14')]);}})[_0xdb58('0x17')](function(_0x28012b){logger['error']('MailInteraction,\x20%s,\x20%s',_0x1a82e3,_0x28012b);_0x3e27d5(_0x28012b);});});}exports[_0xdb58('0x18')]=function(_0x277f91){var _0x4aae64=this;return new Promise(function(_0x39f57f,_0x455860){return db[_0xdb58('0x19')]['update'](_0x277f91[_0xdb58('0x1a')],{'raw':_0x277f91[_0xdb58('0x1b')]?_0x277f91['options'][_0xdb58('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x277f91[_0xdb58('0x1b')]?_0x277f91[_0xdb58('0x1b')][_0xdb58('0x1d')]||null:null,'attributes':_0x277f91[_0xdb58('0x1b')]?_0x277f91[_0xdb58('0x1b')]['attributes']||null:null,'limit':_0x277f91['options']?_0x277f91['options'][_0xdb58('0x1e')]||null:null})[_0xdb58('0xc')](function(_0xe5be08){logger['info']('UpdateMailInteraction',_0x277f91);logger[_0xdb58('0xf')]('UpdateMailInteraction',_0x277f91,JSON[_0xdb58('0x11')](_0xe5be08));_0x39f57f(_0xe5be08);})['catch'](function(_0xcb68d7){logger['error'](_0xdb58('0x18'),_0xcb68d7['message'],_0x277f91);_0x455860(_0x4aae64[_0xdb58('0x12')](0x1f4,_0xcb68d7['message']));});});};exports['AddTagsToMailInteraction']=function(_0x465d46){return new Promise(function(_0x3b349a,_0x28d283){return db[_0xdb58('0x19')][_0xdb58('0x1f')]({'where':_0x465d46['options']?_0x465d46[_0xdb58('0x1b')][_0xdb58('0x1d')]||null:null})[_0xdb58('0xc')](function(_0x1cf7c9){if(_0x1cf7c9){return _0x1cf7c9[_0xdb58('0x20')](_0x465d46[_0xdb58('0x1a')]['ids'],_[_0xdb58('0x21')](_0x465d46['body'],['ids','id'])||{});}})['spread'](function(_0x2eff63){logger['info'](_0xdb58('0x22'),_0x465d46);logger['debug']('AddTags',_0x465d46,JSON[_0xdb58('0x11')](_0x2eff63));_0x3b349a(_0x2eff63);})[_0xdb58('0x17')](function(_0x35256e){logger[_0xdb58('0x12')](_0xdb58('0x22'),_0x35256e[_0xdb58('0x14')],_0x465d46);_0x28d283(_this['error'](0x1f4,_0x35256e[_0xdb58('0x14')]));});});};