Built motion from commit (unavailable).|2.5.21
[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 _0x91a7=['ioredis','../../config/utils','../../config/environment','jayson/promise','http','defaults','redis','socket.io-emitter','./mailInteraction.socket','register','request','then','info','MailInteraction,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','catch','UpdateMailInteraction','MailInteraction','update','body','options','raw','where','attributes','limit','debug','AddTagsToMailInteraction','find','omit','ids','spread','AddTags','util','moment','bluebird'];(function(_0x1facfa,_0x1acf7d){var _0x9ec701=function(_0x115e37){while(--_0x115e37){_0x1facfa['push'](_0x1facfa['shift']());}};_0x9ec701(++_0x1acf7d);}(_0x91a7,0xe7));var _0x791a=function(_0x45887e,_0x50168e){_0x45887e=_0x45887e-0x0;var _0x4520b9=_0x91a7[_0x45887e];return _0x4520b9;};'use strict';var _=require('lodash');var util=require(_0x791a('0x0'));var moment=require(_0x791a('0x1'));var BPromise=require(_0x791a('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x791a('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0x791a('0x4'));var logger=require('../../config/logger')('rpc');var config=require(_0x791a('0x5'));var jayson=require(_0x791a('0x6'));var client=jayson['client'][_0x791a('0x7')]({'port':0x232a});config['redis']=_[_0x791a('0x8')](config[_0x791a('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0x791a('0xa'))(new Redis(config[_0x791a('0x9')]));require(_0x791a('0xb'))[_0x791a('0xc')](socket);function respondWithRpcPromise(_0x266e4b,_0x5249d5,_0x21f0e0){return new BPromise(function(_0x38f7c2,_0x57e99c){return client[_0x791a('0xd')](_0x266e4b,_0x21f0e0)[_0x791a('0xe')](function(_0x167bc4){logger[_0x791a('0xf')](_0x791a('0x10'),_0x5249d5,_0x791a('0x11'));logger['debug']('MailInteraction,\x20%s,\x20%s,\x20%s',_0x5249d5,_0x791a('0x11'),JSON[_0x791a('0x12')](_0x167bc4));if(_0x167bc4['error']){if(_0x167bc4[_0x791a('0x13')][_0x791a('0x14')]===0x1f4){logger['error'](_0x791a('0x10'),_0x5249d5,_0x167bc4[_0x791a('0x13')][_0x791a('0x15')]);return _0x57e99c(_0x167bc4[_0x791a('0x13')]['message']);}logger[_0x791a('0x13')]('MailInteraction,\x20%s,\x20%s',_0x5249d5,_0x167bc4[_0x791a('0x13')][_0x791a('0x15')]);return _0x38f7c2(_0x167bc4['error'][_0x791a('0x15')]);}else{logger['info'](_0x791a('0x10'),_0x5249d5,'request\x20sent');_0x38f7c2(_0x167bc4['result']['message']);}})[_0x791a('0x16')](function(_0x52fa43){logger['error'](_0x791a('0x10'),_0x5249d5,_0x52fa43);_0x57e99c(_0x52fa43);});});}exports[_0x791a('0x17')]=function(_0x3a31a3){var _0x364ca1=this;return new Promise(function(_0x5f3cec,_0x189c0d){return db[_0x791a('0x18')][_0x791a('0x19')](_0x3a31a3[_0x791a('0x1a')],{'raw':_0x3a31a3['options']?_0x3a31a3[_0x791a('0x1b')][_0x791a('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3a31a3[_0x791a('0x1b')]?_0x3a31a3[_0x791a('0x1b')][_0x791a('0x1d')]||null:null,'attributes':_0x3a31a3[_0x791a('0x1b')]?_0x3a31a3[_0x791a('0x1b')][_0x791a('0x1e')]||null:null,'limit':_0x3a31a3[_0x791a('0x1b')]?_0x3a31a3[_0x791a('0x1b')][_0x791a('0x1f')]||null:null})['then'](function(_0x1102c9){logger[_0x791a('0xf')](_0x791a('0x17'),_0x3a31a3);logger[_0x791a('0x20')]('UpdateMailInteraction',_0x3a31a3,JSON[_0x791a('0x12')](_0x1102c9));_0x5f3cec(_0x1102c9);})[_0x791a('0x16')](function(_0x51dcca){logger[_0x791a('0x13')](_0x791a('0x17'),_0x51dcca[_0x791a('0x15')],_0x3a31a3);_0x189c0d(_0x364ca1['error'](0x1f4,_0x51dcca[_0x791a('0x15')]));});});};exports[_0x791a('0x21')]=function(_0x2b0784){return new Promise(function(_0x395376,_0x4f423){return db[_0x791a('0x18')][_0x791a('0x22')]({'where':_0x2b0784[_0x791a('0x1b')]?_0x2b0784['options'][_0x791a('0x1d')]||null:null})[_0x791a('0xe')](function(_0x1b10a7){if(_0x1b10a7){return _0x1b10a7['addTags'](_0x2b0784[_0x791a('0x1a')]['ids'],_[_0x791a('0x23')](_0x2b0784[_0x791a('0x1a')],[_0x791a('0x24'),'id'])||{});}})[_0x791a('0x25')](function(_0x6f7624){logger[_0x791a('0xf')](_0x791a('0x26'),_0x2b0784);logger['debug'](_0x791a('0x26'),_0x2b0784,JSON[_0x791a('0x12')](_0x6f7624));_0x395376(_0x6f7624);})[_0x791a('0x16')](function(_0x27f758){logger[_0x791a('0x13')]('AddTags',_0x27f758[_0x791a('0x15')],_0x2b0784);_0x4f423(_this[_0x791a('0x13')](0x1f4,_0x27f758[_0x791a('0x15')]));});});};