7306fd9cb751cecb4dc7f28645a8baa332097bf6
[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 _0x82b0=['jayson/promise','client','http','defaults','redis','localhost','socket.io-emitter','./mailInteraction.socket','register','request','then','MailInteraction,\x20%s,\x20%s','MailInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','info','catch','UpdateMailInteraction','MailInteraction','update','options','raw','where','attributes','limit','debug','stringify','AddTagsToMailInteraction','find','addTags','body','ids','omit','spread','AddTags','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment'];(function(_0x2499b4,_0x50738d){var _0x159617=function(_0x196de3){while(--_0x196de3){_0x2499b4['push'](_0x2499b4['shift']());}};_0x159617(++_0x50738d);}(_0x82b0,0x81));var _0x082b=function(_0x1e03e4,_0x362f76){_0x1e03e4=_0x1e03e4-0x0;var _0x4a887e=_0x82b0[_0x1e03e4];return _0x4a887e;};'use strict';var _=require(_0x082b('0x0'));var util=require(_0x082b('0x1'));var moment=require(_0x082b('0x2'));var BPromise=require('bluebird');var rs=require(_0x082b('0x3'));var fs=require('fs');var Redis=require(_0x082b('0x4'));var db=require(_0x082b('0x5'))['db'];var utils=require(_0x082b('0x6'));var logger=require('../../config/logger')(_0x082b('0x7'));var config=require(_0x082b('0x8'));var jayson=require(_0x082b('0x9'));var client=jayson[_0x082b('0xa')][_0x082b('0xb')]({'port':0x232a});config['redis']=_[_0x082b('0xc')](config[_0x082b('0xd')],{'host':_0x082b('0xe'),'port':0x18eb});var socket=require(_0x082b('0xf'))(new Redis(config[_0x082b('0xd')]));require(_0x082b('0x10'))[_0x082b('0x11')](socket);function respondWithRpcPromise(_0x303c1e,_0x1483c3,_0x1066e8){return new BPromise(function(_0x18a27f,_0x181a6e){return client[_0x082b('0x12')](_0x303c1e,_0x1066e8)[_0x082b('0x13')](function(_0x4e9133){logger['info'](_0x082b('0x14'),_0x1483c3,'request\x20sent');logger['debug'](_0x082b('0x15'),_0x1483c3,_0x082b('0x16'),JSON['stringify'](_0x4e9133));if(_0x4e9133[_0x082b('0x17')]){if(_0x4e9133[_0x082b('0x17')][_0x082b('0x18')]===0x1f4){logger[_0x082b('0x17')](_0x082b('0x14'),_0x1483c3,_0x4e9133['error'][_0x082b('0x19')]);return _0x181a6e(_0x4e9133[_0x082b('0x17')]['message']);}logger[_0x082b('0x17')]('MailInteraction,\x20%s,\x20%s',_0x1483c3,_0x4e9133[_0x082b('0x17')][_0x082b('0x19')]);return _0x18a27f(_0x4e9133['error'][_0x082b('0x19')]);}else{logger[_0x082b('0x1a')](_0x082b('0x14'),_0x1483c3,_0x082b('0x16'));_0x18a27f(_0x4e9133['result'][_0x082b('0x19')]);}})[_0x082b('0x1b')](function(_0x7d188d){logger[_0x082b('0x17')](_0x082b('0x14'),_0x1483c3,_0x7d188d);_0x181a6e(_0x7d188d);});});}exports[_0x082b('0x1c')]=function(_0x101654){var _0x18074e=this;return new Promise(function(_0x5dee52,_0x9faf2){return db[_0x082b('0x1d')][_0x082b('0x1e')](_0x101654['body'],{'raw':_0x101654[_0x082b('0x1f')]?_0x101654[_0x082b('0x1f')][_0x082b('0x20')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x101654['options']?_0x101654['options'][_0x082b('0x21')]||null:null,'attributes':_0x101654['options']?_0x101654['options'][_0x082b('0x22')]||null:null,'limit':_0x101654[_0x082b('0x1f')]?_0x101654[_0x082b('0x1f')][_0x082b('0x23')]||null:null})[_0x082b('0x13')](function(_0x4ed723){logger[_0x082b('0x1a')](_0x082b('0x1c'),_0x101654);logger[_0x082b('0x24')](_0x082b('0x1c'),_0x101654,JSON[_0x082b('0x25')](_0x4ed723));_0x5dee52(_0x4ed723);})[_0x082b('0x1b')](function(_0x1b6dfc){logger['error'](_0x082b('0x1c'),_0x1b6dfc['message'],_0x101654);_0x9faf2(_0x18074e[_0x082b('0x17')](0x1f4,_0x1b6dfc['message']));});});};exports[_0x082b('0x26')]=function(_0x15c093){return new Promise(function(_0x545fd6,_0x2279d7){return db['MailInteraction'][_0x082b('0x27')]({'where':_0x15c093['options']?_0x15c093[_0x082b('0x1f')][_0x082b('0x21')]||null:null})[_0x082b('0x13')](function(_0x23b651){if(_0x23b651){return _0x23b651[_0x082b('0x28')](_0x15c093[_0x082b('0x29')][_0x082b('0x2a')],_[_0x082b('0x2b')](_0x15c093[_0x082b('0x29')],[_0x082b('0x2a'),'id'])||{});}})[_0x082b('0x2c')](function(_0x11be3b){logger['info'](_0x082b('0x2d'),_0x15c093);logger[_0x082b('0x24')](_0x082b('0x2d'),_0x15c093,JSON[_0x082b('0x25')](_0x11be3b));_0x545fd6(_0x11be3b);})[_0x082b('0x1b')](function(_0x50d5fd){logger['error'](_0x082b('0x2d'),_0x50d5fd[_0x082b('0x19')],_0x15c093);_0x2279d7(_this['error'](0x1f4,_0x50d5fd[_0x082b('0x19')]));});});};