b869d84ef937a26b6cbef75fc71978bdddde286e
[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 _0x5707=['stringify','AddTagsToMailInteraction','find','addTags','ids','omit','AddTags','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','./mailInteraction.socket','register','then','info','MailInteraction,\x20%s,\x20%s','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','error','message','result','catch','UpdateMailInteraction','MailInteraction','update','body','options','raw','where','attributes'];(function(_0x12a43d,_0x25e8c0){var _0x5b74c1=function(_0x5b417a){while(--_0x5b417a){_0x12a43d['push'](_0x12a43d['shift']());}};_0x5b74c1(++_0x25e8c0);}(_0x5707,0x134));var _0x7570=function(_0x1e73fc,_0x533750){_0x1e73fc=_0x1e73fc-0x0;var _0xeceac4=_0x5707[_0x1e73fc];return _0xeceac4;};'use strict';var _=require(_0x7570('0x0'));var util=require(_0x7570('0x1'));var moment=require(_0x7570('0x2'));var BPromise=require(_0x7570('0x3'));var rs=require(_0x7570('0x4'));var fs=require('fs');var Redis=require(_0x7570('0x5'));var db=require(_0x7570('0x6'))['db'];var utils=require(_0x7570('0x7'));var logger=require(_0x7570('0x8'))(_0x7570('0x9'));var config=require(_0x7570('0xa'));var jayson=require(_0x7570('0xb'));var client=jayson[_0x7570('0xc')][_0x7570('0xd')]({'port':0x232a});config[_0x7570('0xe')]=_[_0x7570('0xf')](config[_0x7570('0xe')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x7570('0xe')]));require(_0x7570('0x10'))[_0x7570('0x11')](socket);function respondWithRpcPromise(_0x1282a3,_0x16937f,_0x5d75bb){return new BPromise(function(_0x1dc826,_0x4a5676){return client['request'](_0x1282a3,_0x5d75bb)[_0x7570('0x12')](function(_0x2366dc){logger[_0x7570('0x13')](_0x7570('0x14'),_0x16937f,_0x7570('0x15'));logger[_0x7570('0x16')](_0x7570('0x17'),_0x16937f,_0x7570('0x15'),JSON['stringify'](_0x2366dc));if(_0x2366dc['error']){if(_0x2366dc[_0x7570('0x18')]['code']===0x1f4){logger[_0x7570('0x18')](_0x7570('0x14'),_0x16937f,_0x2366dc[_0x7570('0x18')]['message']);return _0x4a5676(_0x2366dc[_0x7570('0x18')][_0x7570('0x19')]);}logger[_0x7570('0x18')]('MailInteraction,\x20%s,\x20%s',_0x16937f,_0x2366dc['error']['message']);return _0x1dc826(_0x2366dc[_0x7570('0x18')][_0x7570('0x19')]);}else{logger[_0x7570('0x13')]('MailInteraction,\x20%s,\x20%s',_0x16937f,_0x7570('0x15'));_0x1dc826(_0x2366dc[_0x7570('0x1a')]['message']);}})[_0x7570('0x1b')](function(_0x323a52){logger[_0x7570('0x18')]('MailInteraction,\x20%s,\x20%s',_0x16937f,_0x323a52);_0x4a5676(_0x323a52);});});}exports[_0x7570('0x1c')]=function(_0x25fc1b){var _0x37e955=this;return new Promise(function(_0x204cf4,_0x4b8e82){return db[_0x7570('0x1d')][_0x7570('0x1e')](_0x25fc1b[_0x7570('0x1f')],{'raw':_0x25fc1b[_0x7570('0x20')]?_0x25fc1b[_0x7570('0x20')][_0x7570('0x21')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x25fc1b[_0x7570('0x20')]?_0x25fc1b[_0x7570('0x20')][_0x7570('0x22')]||null:null,'attributes':_0x25fc1b[_0x7570('0x20')]?_0x25fc1b[_0x7570('0x20')][_0x7570('0x23')]||null:null,'limit':_0x25fc1b['options']?_0x25fc1b[_0x7570('0x20')]['limit']||null:null})[_0x7570('0x12')](function(_0x91eb37){logger[_0x7570('0x13')](_0x7570('0x1c'),_0x25fc1b);logger[_0x7570('0x16')](_0x7570('0x1c'),_0x25fc1b,JSON[_0x7570('0x24')](_0x91eb37));_0x204cf4(_0x91eb37);})[_0x7570('0x1b')](function(_0xca040d){logger['error'](_0x7570('0x1c'),_0xca040d['message'],_0x25fc1b);_0x4b8e82(_0x37e955[_0x7570('0x18')](0x1f4,_0xca040d[_0x7570('0x19')]));});});};exports[_0x7570('0x25')]=function(_0x4e49a1){return new Promise(function(_0x40d420,_0x592d2a){return db['MailInteraction'][_0x7570('0x26')]({'where':_0x4e49a1[_0x7570('0x20')]?_0x4e49a1[_0x7570('0x20')][_0x7570('0x22')]||null:null})[_0x7570('0x12')](function(_0x2d55e1){if(_0x2d55e1){return _0x2d55e1[_0x7570('0x27')](_0x4e49a1[_0x7570('0x1f')][_0x7570('0x28')],_[_0x7570('0x29')](_0x4e49a1[_0x7570('0x1f')],[_0x7570('0x28'),'id'])||{});}})['spread'](function(_0x31cbd4){logger['info']('AddTags',_0x4e49a1);logger[_0x7570('0x16')](_0x7570('0x2a'),_0x4e49a1,JSON[_0x7570('0x24')](_0x31cbd4));_0x40d420(_0x31cbd4);})['catch'](function(_0x140d02){logger[_0x7570('0x18')](_0x7570('0x2a'),_0x140d02[_0x7570('0x19')],_0x4e49a1);_0x592d2a(_this['error'](0x1f4,_0x140d02['message']));});});};