Built motion from commit da617fac.|2.6.6
[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 _0xf404=['UpdateMailInteraction','catch','AddTagsToMailInteraction','find','addTags','omit','ids','AddTags','lodash','bluebird','randomstring','ioredis','../../config/utils','rpc','jayson/promise','http','redis','defaults','localhost','socket.io-emitter','./mailInteraction.socket','register','request','MailInteraction,\x20%s,\x20%s','request\x20sent','debug','MailInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','MailInteraction','update','body','options','where','limit','then'];(function(_0x5fc402,_0xc2613){var _0x59d9f9=function(_0x20f5ef){while(--_0x20f5ef){_0x5fc402['push'](_0x5fc402['shift']());}};_0x59d9f9(++_0xc2613);}(_0xf404,0x120));var _0x4f40=function(_0x3f4d3d,_0x3a33a7){_0x3f4d3d=_0x3f4d3d-0x0;var _0x3a510d=_0xf404[_0x3f4d3d];return _0x3a510d;};'use strict';var _=require(_0x4f40('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x4f40('0x1'));var rs=require(_0x4f40('0x2'));var fs=require('fs');var Redis=require(_0x4f40('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0x4f40('0x4'));var logger=require('../../config/logger')(_0x4f40('0x5'));var config=require('../../config/environment');var jayson=require(_0x4f40('0x6'));var client=jayson['client'][_0x4f40('0x7')]({'port':0x232a});config[_0x4f40('0x8')]=_[_0x4f40('0x9')](config[_0x4f40('0x8')],{'host':_0x4f40('0xa'),'port':0x18eb});var socket=require(_0x4f40('0xb'))(new Redis(config[_0x4f40('0x8')]));require(_0x4f40('0xc'))[_0x4f40('0xd')](socket);function respondWithRpcPromise(_0x18caa9,_0x2ff16d,_0x28f06a){return new BPromise(function(_0x51a98f,_0x400399){return client[_0x4f40('0xe')](_0x18caa9,_0x28f06a)['then'](function(_0x5b2d9b){logger['info'](_0x4f40('0xf'),_0x2ff16d,_0x4f40('0x10'));logger[_0x4f40('0x11')](_0x4f40('0x12'),_0x2ff16d,_0x4f40('0x10'),JSON[_0x4f40('0x13')](_0x5b2d9b));if(_0x5b2d9b[_0x4f40('0x14')]){if(_0x5b2d9b[_0x4f40('0x14')][_0x4f40('0x15')]===0x1f4){logger[_0x4f40('0x14')](_0x4f40('0xf'),_0x2ff16d,_0x5b2d9b[_0x4f40('0x14')][_0x4f40('0x16')]);return _0x400399(_0x5b2d9b[_0x4f40('0x14')]['message']);}logger[_0x4f40('0x14')](_0x4f40('0xf'),_0x2ff16d,_0x5b2d9b['error'][_0x4f40('0x16')]);return _0x51a98f(_0x5b2d9b[_0x4f40('0x14')]['message']);}else{logger[_0x4f40('0x17')](_0x4f40('0xf'),_0x2ff16d,_0x4f40('0x10'));_0x51a98f(_0x5b2d9b[_0x4f40('0x18')][_0x4f40('0x16')]);}})['catch'](function(_0x762165){logger[_0x4f40('0x14')](_0x4f40('0xf'),_0x2ff16d,_0x762165);_0x400399(_0x762165);});});}exports['UpdateMailInteraction']=function(_0x178ee2){var _0x565f4c=this;return new Promise(function(_0x5391ff,_0x4809c8){return db[_0x4f40('0x19')][_0x4f40('0x1a')](_0x178ee2[_0x4f40('0x1b')],{'raw':_0x178ee2[_0x4f40('0x1c')]?_0x178ee2['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x178ee2[_0x4f40('0x1c')]?_0x178ee2['options'][_0x4f40('0x1d')]||null:null,'attributes':_0x178ee2[_0x4f40('0x1c')]?_0x178ee2['options']['attributes']||null:null,'limit':_0x178ee2[_0x4f40('0x1c')]?_0x178ee2['options'][_0x4f40('0x1e')]||null:null})[_0x4f40('0x1f')](function(_0x15b092){logger[_0x4f40('0x17')](_0x4f40('0x20'),_0x178ee2);logger[_0x4f40('0x11')]('UpdateMailInteraction',_0x178ee2,JSON[_0x4f40('0x13')](_0x15b092));_0x5391ff(_0x15b092);})[_0x4f40('0x21')](function(_0x1ca942){logger[_0x4f40('0x14')](_0x4f40('0x20'),_0x1ca942[_0x4f40('0x16')],_0x178ee2);_0x4809c8(_0x565f4c['error'](0x1f4,_0x1ca942[_0x4f40('0x16')]));});});};exports[_0x4f40('0x22')]=function(_0x193f02){return new Promise(function(_0x21ebe3,_0x1a06c4){return db['MailInteraction'][_0x4f40('0x23')]({'where':_0x193f02[_0x4f40('0x1c')]?_0x193f02[_0x4f40('0x1c')][_0x4f40('0x1d')]||null:null})['then'](function(_0x1245e5){if(_0x1245e5){return _0x1245e5[_0x4f40('0x24')](_0x193f02[_0x4f40('0x1b')]['ids'],_[_0x4f40('0x25')](_0x193f02[_0x4f40('0x1b')],[_0x4f40('0x26'),'id'])||{});}})['spread'](function(_0xc8b8d0){logger[_0x4f40('0x17')](_0x4f40('0x27'),_0x193f02);logger['debug']('AddTags',_0x193f02,JSON[_0x4f40('0x13')](_0xc8b8d0));_0x21ebe3(_0xc8b8d0);})[_0x4f40('0x21')](function(_0xec1c43){logger[_0x4f40('0x14')](_0x4f40('0x27'),_0xec1c43['message'],_0x193f02);_0x1a06c4(_this[_0x4f40('0x14')](0x1f4,_0xec1c43['message']));});});};