ad15d71873bb5310c450bbd7cd512d381c92f5c2
[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 _0x1396=['raw','where','attributes','limit','debug','AddTagsToMailInteraction','addTags','ids','spread','AddTags','lodash','moment','ioredis','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','socket.io-emitter','./mailInteraction.socket','register','request','then','info','MailInteraction,\x20%s,\x20%s','MailInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','UpdateMailInteraction','MailInteraction','update','body','options'];(function(_0x248d46,_0xba08ec){var _0x354942=function(_0x1b52a1){while(--_0x1b52a1){_0x248d46['push'](_0x248d46['shift']());}};_0x354942(++_0xba08ec);}(_0x1396,0x1ea));var _0x6139=function(_0x5027b1,_0x1409a5){_0x5027b1=_0x5027b1-0x0;var _0x4a46cf=_0x1396[_0x5027b1];return _0x4a46cf;};'use strict';var _=require(_0x6139('0x0'));var util=require('util');var moment=require(_0x6139('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x6139('0x2'));var db=require(_0x6139('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0x6139('0x4'))('rpc');var config=require(_0x6139('0x5'));var jayson=require(_0x6139('0x6'));var client=jayson[_0x6139('0x7')][_0x6139('0x8')]({'port':0x232a});config[_0x6139('0x9')]=_[_0x6139('0xa')](config[_0x6139('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0x6139('0xb'))(new Redis(config['redis']));require(_0x6139('0xc'))[_0x6139('0xd')](socket);function respondWithRpcPromise(_0x9a2eb7,_0x58dd96,_0x3878cc){return new BPromise(function(_0x163235,_0x34e658){return client[_0x6139('0xe')](_0x9a2eb7,_0x3878cc)[_0x6139('0xf')](function(_0x359ed2){logger[_0x6139('0x10')](_0x6139('0x11'),_0x58dd96,'request\x20sent');logger['debug'](_0x6139('0x12'),_0x58dd96,_0x6139('0x13'),JSON[_0x6139('0x14')](_0x359ed2));if(_0x359ed2[_0x6139('0x15')]){if(_0x359ed2['error'][_0x6139('0x16')]===0x1f4){logger[_0x6139('0x15')](_0x6139('0x11'),_0x58dd96,_0x359ed2[_0x6139('0x15')][_0x6139('0x17')]);return _0x34e658(_0x359ed2[_0x6139('0x15')][_0x6139('0x17')]);}logger[_0x6139('0x15')](_0x6139('0x11'),_0x58dd96,_0x359ed2[_0x6139('0x15')]['message']);return _0x163235(_0x359ed2[_0x6139('0x15')][_0x6139('0x17')]);}else{logger[_0x6139('0x10')]('MailInteraction,\x20%s,\x20%s',_0x58dd96,_0x6139('0x13'));_0x163235(_0x359ed2['result'][_0x6139('0x17')]);}})[_0x6139('0x18')](function(_0x27317f){logger[_0x6139('0x15')](_0x6139('0x11'),_0x58dd96,_0x27317f);_0x34e658(_0x27317f);});});}exports[_0x6139('0x19')]=function(_0x55eb11){var _0x4f0d14=this;return new Promise(function(_0x140fca,_0x59f23d){return db[_0x6139('0x1a')][_0x6139('0x1b')](_0x55eb11[_0x6139('0x1c')],{'raw':_0x55eb11[_0x6139('0x1d')]?_0x55eb11['options'][_0x6139('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x55eb11[_0x6139('0x1d')]?_0x55eb11['options'][_0x6139('0x1f')]||null:null,'attributes':_0x55eb11[_0x6139('0x1d')]?_0x55eb11[_0x6139('0x1d')][_0x6139('0x20')]||null:null,'limit':_0x55eb11['options']?_0x55eb11[_0x6139('0x1d')][_0x6139('0x21')]||null:null})[_0x6139('0xf')](function(_0x44126c){logger[_0x6139('0x10')](_0x6139('0x19'),_0x55eb11);logger[_0x6139('0x22')]('UpdateMailInteraction',_0x55eb11,JSON['stringify'](_0x44126c));_0x140fca(_0x44126c);})[_0x6139('0x18')](function(_0x5a3242){logger[_0x6139('0x15')]('UpdateMailInteraction',_0x5a3242[_0x6139('0x17')],_0x55eb11);_0x59f23d(_0x4f0d14[_0x6139('0x15')](0x1f4,_0x5a3242[_0x6139('0x17')]));});});};exports[_0x6139('0x23')]=function(_0x2b8325){return new Promise(function(_0x371a1f,_0x1d3af6){return db['MailInteraction']['find']({'where':_0x2b8325[_0x6139('0x1d')]?_0x2b8325['options'][_0x6139('0x1f')]||null:null})[_0x6139('0xf')](function(_0x5e3d3a){if(_0x5e3d3a){return _0x5e3d3a[_0x6139('0x24')](_0x2b8325[_0x6139('0x1c')][_0x6139('0x25')],_['omit'](_0x2b8325[_0x6139('0x1c')],[_0x6139('0x25'),'id'])||{});}})[_0x6139('0x26')](function(_0x86740a){logger[_0x6139('0x10')](_0x6139('0x27'),_0x2b8325);logger[_0x6139('0x22')]('AddTags',_0x2b8325,JSON[_0x6139('0x14')](_0x86740a));_0x371a1f(_0x86740a);})[_0x6139('0x18')](function(_0x3eb8c9){logger['error'](_0x6139('0x27'),_0x3eb8c9['message'],_0x2b8325);_0x1d3af6(_this[_0x6139('0x15')](0x1f4,_0x3eb8c9[_0x6139('0x17')]));});});};