a96a46473e4e2656d17c4713b2da817802df7f93
[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 _0x3b64=['../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','redis','socket.io-emitter','./mailInteraction.socket','request','MailInteraction,\x20%s,\x20%s','MailInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','UpdateMailInteraction','MailInteraction','options','raw','attributes','limit','then','debug','AddTagsToMailInteraction','find','where','addTags','body','ids','omit','spread','info','AddTags','lodash','util','moment','bluebird','randomstring','ioredis'];(function(_0x34334d,_0x1c485f){var _0x39d85d=function(_0x3e0577){while(--_0x3e0577){_0x34334d['push'](_0x34334d['shift']());}};_0x39d85d(++_0x1c485f);}(_0x3b64,0x1bd));var _0x43b6=function(_0x2cdce9,_0x231a9b){_0x2cdce9=_0x2cdce9-0x0;var _0x2e1aee=_0x3b64[_0x2cdce9];return _0x2e1aee;};'use strict';var _=require(_0x43b6('0x0'));var util=require(_0x43b6('0x1'));var moment=require(_0x43b6('0x2'));var BPromise=require(_0x43b6('0x3'));var rs=require(_0x43b6('0x4'));var fs=require('fs');var Redis=require(_0x43b6('0x5'));var db=require(_0x43b6('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0x43b6('0x7'))('rpc');var config=require(_0x43b6('0x8'));var jayson=require(_0x43b6('0x9'));var client=jayson[_0x43b6('0xa')]['http']({'port':0x232a});config[_0x43b6('0xb')]=_['defaults'](config[_0x43b6('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0x43b6('0xc'))(new Redis(config[_0x43b6('0xb')]));require(_0x43b6('0xd'))['register'](socket);function respondWithRpcPromise(_0x3bc214,_0x2b944a,_0x234d8f){return new BPromise(function(_0x31bd19,_0x5778e8){return client[_0x43b6('0xe')](_0x3bc214,_0x234d8f)['then'](function(_0x5e47f6){logger['info'](_0x43b6('0xf'),_0x2b944a,'request\x20sent');logger['debug'](_0x43b6('0x10'),_0x2b944a,_0x43b6('0x11'),JSON[_0x43b6('0x12')](_0x5e47f6));if(_0x5e47f6[_0x43b6('0x13')]){if(_0x5e47f6['error'][_0x43b6('0x14')]===0x1f4){logger['error'](_0x43b6('0xf'),_0x2b944a,_0x5e47f6[_0x43b6('0x13')][_0x43b6('0x15')]);return _0x5778e8(_0x5e47f6[_0x43b6('0x13')]['message']);}logger['error'](_0x43b6('0xf'),_0x2b944a,_0x5e47f6[_0x43b6('0x13')][_0x43b6('0x15')]);return _0x31bd19(_0x5e47f6['error'][_0x43b6('0x15')]);}else{logger['info']('MailInteraction,\x20%s,\x20%s',_0x2b944a,_0x43b6('0x11'));_0x31bd19(_0x5e47f6['result'][_0x43b6('0x15')]);}})[_0x43b6('0x16')](function(_0x2164a3){logger[_0x43b6('0x13')](_0x43b6('0xf'),_0x2b944a,_0x2164a3);_0x5778e8(_0x2164a3);});});}exports[_0x43b6('0x17')]=function(_0x1e724a){var _0x56d608=this;return new Promise(function(_0xe31496,_0x4ed338){return db[_0x43b6('0x18')]['update'](_0x1e724a['body'],{'raw':_0x1e724a[_0x43b6('0x19')]?_0x1e724a['options'][_0x43b6('0x1a')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x1e724a[_0x43b6('0x19')]?_0x1e724a['options']['where']||null:null,'attributes':_0x1e724a[_0x43b6('0x19')]?_0x1e724a[_0x43b6('0x19')][_0x43b6('0x1b')]||null:null,'limit':_0x1e724a[_0x43b6('0x19')]?_0x1e724a[_0x43b6('0x19')][_0x43b6('0x1c')]||null:null})[_0x43b6('0x1d')](function(_0x5e6c2d){logger['info'](_0x43b6('0x17'),_0x1e724a);logger[_0x43b6('0x1e')](_0x43b6('0x17'),_0x1e724a,JSON[_0x43b6('0x12')](_0x5e6c2d));_0xe31496(_0x5e6c2d);})[_0x43b6('0x16')](function(_0x121723){logger[_0x43b6('0x13')]('UpdateMailInteraction',_0x121723['message'],_0x1e724a);_0x4ed338(_0x56d608[_0x43b6('0x13')](0x1f4,_0x121723[_0x43b6('0x15')]));});});};exports[_0x43b6('0x1f')]=function(_0x42e9d1){return new Promise(function(_0x589976,_0x4c87b7){return db[_0x43b6('0x18')][_0x43b6('0x20')]({'where':_0x42e9d1[_0x43b6('0x19')]?_0x42e9d1[_0x43b6('0x19')][_0x43b6('0x21')]||null:null})[_0x43b6('0x1d')](function(_0x44427b){if(_0x44427b){return _0x44427b[_0x43b6('0x22')](_0x42e9d1[_0x43b6('0x23')][_0x43b6('0x24')],_[_0x43b6('0x25')](_0x42e9d1[_0x43b6('0x23')],[_0x43b6('0x24'),'id'])||{});}})[_0x43b6('0x26')](function(_0x25c42b){logger[_0x43b6('0x27')](_0x43b6('0x28'),_0x42e9d1);logger[_0x43b6('0x1e')]('AddTags',_0x42e9d1,JSON[_0x43b6('0x12')](_0x25c42b));_0x589976(_0x25c42b);})[_0x43b6('0x16')](function(_0x1d5108){logger[_0x43b6('0x13')](_0x43b6('0x28'),_0x1d5108[_0x43b6('0x15')],_0x42e9d1);_0x4c87b7(_this['error'](0x1f4,_0x1d5108[_0x43b6('0x15')]));});});};