96a23519fa9a7db9bc9597da7eea9fbeadc4304f
[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 _0xbaee=['omit','spread','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','jayson/promise','http','redis','defaults','localhost','./mailInteraction.socket','register','request','MailInteraction,\x20%s,\x20%s','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','UpdateMailInteraction','MailInteraction','update','body','options','attributes','limit','then','AddTagsToMailInteraction','find','where','addTags','ids'];(function(_0x1ddf1b,_0x2774a8){var _0x104c1f=function(_0xa7530){while(--_0xa7530){_0x1ddf1b['push'](_0x1ddf1b['shift']());}};_0x104c1f(++_0x2774a8);}(_0xbaee,0x186));var _0xebae=function(_0x3929a8,_0x3c35b3){_0x3929a8=_0x3929a8-0x0;var _0xcd7475=_0xbaee[_0x3929a8];return _0xcd7475;};'use strict';var _=require(_0xebae('0x0'));var util=require(_0xebae('0x1'));var moment=require(_0xebae('0x2'));var BPromise=require(_0xebae('0x3'));var rs=require(_0xebae('0x4'));var fs=require('fs');var Redis=require(_0xebae('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0xebae('0x6'));var logger=require(_0xebae('0x7'))('rpc');var config=require('../../config/environment');var jayson=require(_0xebae('0x8'));var client=jayson['client'][_0xebae('0x9')]({'port':0x232a});config[_0xebae('0xa')]=_[_0xebae('0xb')](config['redis'],{'host':_0xebae('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xebae('0xd'))[_0xebae('0xe')](socket);function respondWithRpcPromise(_0x55bd84,_0x265ee4,_0x24a76a){return new BPromise(function(_0xc65748,_0x538bf0){return client[_0xebae('0xf')](_0x55bd84,_0x24a76a)['then'](function(_0x1d783b){logger['info'](_0xebae('0x10'),_0x265ee4,_0xebae('0x11'));logger[_0xebae('0x12')](_0xebae('0x13'),_0x265ee4,_0xebae('0x11'),JSON[_0xebae('0x14')](_0x1d783b));if(_0x1d783b[_0xebae('0x15')]){if(_0x1d783b[_0xebae('0x15')][_0xebae('0x16')]===0x1f4){logger['error'](_0xebae('0x10'),_0x265ee4,_0x1d783b['error'][_0xebae('0x17')]);return _0x538bf0(_0x1d783b['error']['message']);}logger[_0xebae('0x15')](_0xebae('0x10'),_0x265ee4,_0x1d783b['error']['message']);return _0xc65748(_0x1d783b[_0xebae('0x15')][_0xebae('0x17')]);}else{logger[_0xebae('0x18')](_0xebae('0x10'),_0x265ee4,_0xebae('0x11'));_0xc65748(_0x1d783b[_0xebae('0x19')][_0xebae('0x17')]);}})[_0xebae('0x1a')](function(_0x73cbb2){logger[_0xebae('0x15')](_0xebae('0x10'),_0x265ee4,_0x73cbb2);_0x538bf0(_0x73cbb2);});});}exports[_0xebae('0x1b')]=function(_0x27af4b){var _0x11afdb=this;return new Promise(function(_0x18db4c,_0x5a710c){return db[_0xebae('0x1c')][_0xebae('0x1d')](_0x27af4b[_0xebae('0x1e')],{'raw':_0x27af4b[_0xebae('0x1f')]?_0x27af4b['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x27af4b[_0xebae('0x1f')]?_0x27af4b[_0xebae('0x1f')]['where']||null:null,'attributes':_0x27af4b['options']?_0x27af4b[_0xebae('0x1f')][_0xebae('0x20')]||null:null,'limit':_0x27af4b['options']?_0x27af4b[_0xebae('0x1f')][_0xebae('0x21')]||null:null})[_0xebae('0x22')](function(_0x249def){logger[_0xebae('0x18')](_0xebae('0x1b'),_0x27af4b);logger[_0xebae('0x12')]('UpdateMailInteraction',_0x27af4b,JSON[_0xebae('0x14')](_0x249def));_0x18db4c(_0x249def);})[_0xebae('0x1a')](function(_0x3572fa){logger[_0xebae('0x15')](_0xebae('0x1b'),_0x3572fa[_0xebae('0x17')],_0x27af4b);_0x5a710c(_0x11afdb[_0xebae('0x15')](0x1f4,_0x3572fa[_0xebae('0x17')]));});});};exports[_0xebae('0x23')]=function(_0x57887c){return new Promise(function(_0x9d4fcc,_0x55b386){return db['MailInteraction'][_0xebae('0x24')]({'where':_0x57887c['options']?_0x57887c['options'][_0xebae('0x25')]||null:null})['then'](function(_0x469e18){if(_0x469e18){return _0x469e18[_0xebae('0x26')](_0x57887c['body'][_0xebae('0x27')],_[_0xebae('0x28')](_0x57887c[_0xebae('0x1e')],[_0xebae('0x27'),'id'])||{});}})[_0xebae('0x29')](function(_0x2fbf8b){logger[_0xebae('0x18')](_0xebae('0x2a'),_0x57887c);logger[_0xebae('0x12')](_0xebae('0x2a'),_0x57887c,JSON[_0xebae('0x14')](_0x2fbf8b));_0x9d4fcc(_0x2fbf8b);})[_0xebae('0x1a')](function(_0x4a75c8){logger[_0xebae('0x15')](_0xebae('0x2a'),_0x4a75c8['message'],_0x57887c);_0x55b386(_this[_0xebae('0x15')](0x1f4,_0x4a75c8[_0xebae('0x17')]));});});};