7e9a2ec891cb304e8b4f99b458e08d86e8c21031
[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 _0x0979=['info','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','MailInteraction,\x20%s,\x20%s','message','result','update','body','options','attributes','limit','UpdateMailInteraction','catch','find','where','spread','AddTags','lodash','util','bluebird','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','localhost','socket.io-emitter','register','then'];(function(_0x54af19,_0x2ca855){var _0x2f55b4=function(_0x2f19b7){while(--_0x2f19b7){_0x54af19['push'](_0x54af19['shift']());}};_0x2f55b4(++_0x2ca855);}(_0x0979,0x1a1));var _0x9097=function(_0x4bf96c,_0x4d24fd){_0x4bf96c=_0x4bf96c-0x0;var _0x281d09=_0x0979[_0x4bf96c];return _0x281d09;};'use strict';var _=require(_0x9097('0x0'));var util=require(_0x9097('0x1'));var moment=require('moment');var BPromise=require(_0x9097('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x9097('0x3'));var db=require(_0x9097('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x9097('0x5'))(_0x9097('0x6'));var config=require(_0x9097('0x7'));var jayson=require(_0x9097('0x8'));var client=jayson[_0x9097('0x9')]['http']({'port':0x232a});config[_0x9097('0xa')]=_['defaults'](config[_0x9097('0xa')],{'host':_0x9097('0xb'),'port':0x18eb});var socket=require(_0x9097('0xc'))(new Redis(config[_0x9097('0xa')]));require('./mailInteraction.socket')[_0x9097('0xd')](socket);function respondWithRpcPromise(_0xbae04e,_0x232070,_0x2f4bce){return new BPromise(function(_0x397b88,_0x4fd803){return client['request'](_0xbae04e,_0x2f4bce)[_0x9097('0xe')](function(_0x430b8d){logger[_0x9097('0xf')]('MailInteraction,\x20%s,\x20%s',_0x232070,_0x9097('0x10'));logger[_0x9097('0x11')](_0x9097('0x12'),_0x232070,_0x9097('0x10'),JSON[_0x9097('0x13')](_0x430b8d));if(_0x430b8d['error']){if(_0x430b8d[_0x9097('0x14')][_0x9097('0x15')]===0x1f4){logger[_0x9097('0x14')](_0x9097('0x16'),_0x232070,_0x430b8d[_0x9097('0x14')][_0x9097('0x17')]);return _0x4fd803(_0x430b8d[_0x9097('0x14')][_0x9097('0x17')]);}logger[_0x9097('0x14')](_0x9097('0x16'),_0x232070,_0x430b8d[_0x9097('0x14')][_0x9097('0x17')]);return _0x397b88(_0x430b8d[_0x9097('0x14')][_0x9097('0x17')]);}else{logger['info']('MailInteraction,\x20%s,\x20%s',_0x232070,_0x9097('0x10'));_0x397b88(_0x430b8d[_0x9097('0x18')][_0x9097('0x17')]);}})['catch'](function(_0x30348d){logger[_0x9097('0x14')](_0x9097('0x16'),_0x232070,_0x30348d);_0x4fd803(_0x30348d);});});}exports['UpdateMailInteraction']=function(_0x4b6b81){var _0x4589b6=this;return new Promise(function(_0x23b525,_0xfde192){return db['MailInteraction'][_0x9097('0x19')](_0x4b6b81[_0x9097('0x1a')],{'raw':_0x4b6b81['options']?_0x4b6b81[_0x9097('0x1b')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x4b6b81[_0x9097('0x1b')]?_0x4b6b81['options']['where']||null:null,'attributes':_0x4b6b81['options']?_0x4b6b81[_0x9097('0x1b')][_0x9097('0x1c')]||null:null,'limit':_0x4b6b81[_0x9097('0x1b')]?_0x4b6b81[_0x9097('0x1b')][_0x9097('0x1d')]||null:null})['then'](function(_0x1cc608){logger[_0x9097('0xf')](_0x9097('0x1e'),_0x4b6b81);logger[_0x9097('0x11')](_0x9097('0x1e'),_0x4b6b81,JSON[_0x9097('0x13')](_0x1cc608));_0x23b525(_0x1cc608);})[_0x9097('0x1f')](function(_0x3552a7){logger[_0x9097('0x14')]('UpdateMailInteraction',_0x3552a7['message'],_0x4b6b81);_0xfde192(_0x4589b6[_0x9097('0x14')](0x1f4,_0x3552a7[_0x9097('0x17')]));});});};exports['AddTagsToMailInteraction']=function(_0xfd10e1){return new Promise(function(_0x16940b,_0x1d46de){return db['MailInteraction'][_0x9097('0x20')]({'where':_0xfd10e1[_0x9097('0x1b')]?_0xfd10e1[_0x9097('0x1b')][_0x9097('0x21')]||null:null})['then'](function(_0x1e025d){if(_0x1e025d){return _0x1e025d['addTags'](_0xfd10e1['body']['ids'],_['omit'](_0xfd10e1['body'],['ids','id'])||{});}})[_0x9097('0x22')](function(_0x4d2e1d){logger[_0x9097('0xf')](_0x9097('0x23'),_0xfd10e1);logger['debug'](_0x9097('0x23'),_0xfd10e1,JSON[_0x9097('0x13')](_0x4d2e1d));_0x16940b(_0x4d2e1d);})[_0x9097('0x1f')](function(_0x3e0d9f){logger[_0x9097('0x14')](_0x9097('0x23'),_0x3e0d9f[_0x9097('0x17')],_0xfd10e1);_0x1d46de(_this['error'](0x1f4,_0x3e0d9f[_0x9097('0x17')]));});});};