aeb6417b3fb7172e260d6d968bc3c93718627be2
[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 _0xc7ea=['jayson/promise','client','http','redis','defaults','localhost','./mailInteraction.socket','register','request','then','info','request\x20sent','debug','stringify','error','code','MailInteraction,\x20%s,\x20%s','message','UpdateMailInteraction','update','body','options','raw','where','attributes','limit','catch','find','addTags','omit','ids','spread','AddTags','lodash','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment'];(function(_0x144b30,_0x77072d){var _0x1bb7bc=function(_0x1082cc){while(--_0x1082cc){_0x144b30['push'](_0x144b30['shift']());}};_0x1bb7bc(++_0x77072d);}(_0xc7ea,0x171));var _0xac7e=function(_0x50bd74,_0x47e8fa){_0x50bd74=_0x50bd74-0x0;var _0x509e03=_0xc7ea[_0x50bd74];return _0x509e03;};'use strict';var _=require(_0xac7e('0x0'));var util=require(_0xac7e('0x1'));var moment=require('moment');var BPromise=require(_0xac7e('0x2'));var rs=require(_0xac7e('0x3'));var fs=require('fs');var Redis=require(_0xac7e('0x4'));var db=require(_0xac7e('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0xac7e('0x6'))(_0xac7e('0x7'));var config=require(_0xac7e('0x8'));var jayson=require(_0xac7e('0x9'));var client=jayson[_0xac7e('0xa')][_0xac7e('0xb')]({'port':0x232a});config[_0xac7e('0xc')]=_[_0xac7e('0xd')](config[_0xac7e('0xc')],{'host':_0xac7e('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xac7e('0xc')]));require(_0xac7e('0xf'))[_0xac7e('0x10')](socket);function respondWithRpcPromise(_0x173b59,_0x39d2e3,_0x260889){return new BPromise(function(_0x10873d,_0x240869){return client[_0xac7e('0x11')](_0x173b59,_0x260889)[_0xac7e('0x12')](function(_0x404fc0){logger[_0xac7e('0x13')]('MailInteraction,\x20%s,\x20%s',_0x39d2e3,_0xac7e('0x14'));logger[_0xac7e('0x15')]('MailInteraction,\x20%s,\x20%s,\x20%s',_0x39d2e3,_0xac7e('0x14'),JSON[_0xac7e('0x16')](_0x404fc0));if(_0x404fc0[_0xac7e('0x17')]){if(_0x404fc0[_0xac7e('0x17')][_0xac7e('0x18')]===0x1f4){logger['error'](_0xac7e('0x19'),_0x39d2e3,_0x404fc0[_0xac7e('0x17')][_0xac7e('0x1a')]);return _0x240869(_0x404fc0[_0xac7e('0x17')][_0xac7e('0x1a')]);}logger[_0xac7e('0x17')](_0xac7e('0x19'),_0x39d2e3,_0x404fc0[_0xac7e('0x17')]['message']);return _0x10873d(_0x404fc0[_0xac7e('0x17')][_0xac7e('0x1a')]);}else{logger[_0xac7e('0x13')](_0xac7e('0x19'),_0x39d2e3,_0xac7e('0x14'));_0x10873d(_0x404fc0['result'][_0xac7e('0x1a')]);}})['catch'](function(_0xba3d01){logger['error'](_0xac7e('0x19'),_0x39d2e3,_0xba3d01);_0x240869(_0xba3d01);});});}exports[_0xac7e('0x1b')]=function(_0x231ab0){var _0x41ae40=this;return new Promise(function(_0x3be919,_0x2ad784){return db['MailInteraction'][_0xac7e('0x1c')](_0x231ab0[_0xac7e('0x1d')],{'raw':_0x231ab0['options']?_0x231ab0[_0xac7e('0x1e')][_0xac7e('0x1f')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x231ab0[_0xac7e('0x1e')]?_0x231ab0[_0xac7e('0x1e')][_0xac7e('0x20')]||null:null,'attributes':_0x231ab0[_0xac7e('0x1e')]?_0x231ab0[_0xac7e('0x1e')][_0xac7e('0x21')]||null:null,'limit':_0x231ab0[_0xac7e('0x1e')]?_0x231ab0[_0xac7e('0x1e')][_0xac7e('0x22')]||null:null})['then'](function(_0x57c945){logger[_0xac7e('0x13')](_0xac7e('0x1b'),_0x231ab0);logger[_0xac7e('0x15')]('UpdateMailInteraction',_0x231ab0,JSON[_0xac7e('0x16')](_0x57c945));_0x3be919(_0x57c945);})[_0xac7e('0x23')](function(_0x2cafcb){logger[_0xac7e('0x17')]('UpdateMailInteraction',_0x2cafcb['message'],_0x231ab0);_0x2ad784(_0x41ae40[_0xac7e('0x17')](0x1f4,_0x2cafcb['message']));});});};exports['AddTagsToMailInteraction']=function(_0x24fa95){return new Promise(function(_0x43eb5e,_0x3ecfc1){return db['MailInteraction'][_0xac7e('0x24')]({'where':_0x24fa95[_0xac7e('0x1e')]?_0x24fa95[_0xac7e('0x1e')][_0xac7e('0x20')]||null:null})['then'](function(_0x12450b){if(_0x12450b){return _0x12450b[_0xac7e('0x25')](_0x24fa95[_0xac7e('0x1d')]['ids'],_[_0xac7e('0x26')](_0x24fa95[_0xac7e('0x1d')],[_0xac7e('0x27'),'id'])||{});}})[_0xac7e('0x28')](function(_0x4b4dee){logger[_0xac7e('0x13')]('AddTags',_0x24fa95);logger[_0xac7e('0x15')](_0xac7e('0x29'),_0x24fa95,JSON[_0xac7e('0x16')](_0x4b4dee));_0x43eb5e(_0x4b4dee);})['catch'](function(_0x194465){logger[_0xac7e('0x17')]('AddTags',_0x194465['message'],_0x24fa95);_0x3ecfc1(_this[_0xac7e('0x17')](0x1f4,_0x194465[_0xac7e('0x1a')]));});});};