34a4cd37d1b67183948a2eb04d28246621f12236
[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 _0x5946=['options','raw','where','attributes','limit','info','AddTagsToMailInteraction','find','addTags','omit','ids','spread','AddTags','catch','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','http','defaults','localhost','./mailInteraction.socket','register','request','then','debug','MailInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','MailInteraction,\x20%s,\x20%s','message','result','UpdateMailInteraction','MailInteraction','update','body'];(function(_0x5e8b01,_0xf3e48d){var _0x15c821=function(_0x5dcf7d){while(--_0x5dcf7d){_0x5e8b01['push'](_0x5e8b01['shift']());}};_0x15c821(++_0xf3e48d);}(_0x5946,0x8f));var _0x6594=function(_0x2ecc65,_0xd75c48){_0x2ecc65=_0x2ecc65-0x0;var _0x103cc3=_0x5946[_0x2ecc65];return _0x103cc3;};'use strict';var _=require('lodash');var util=require(_0x6594('0x0'));var moment=require('moment');var BPromise=require(_0x6594('0x1'));var rs=require(_0x6594('0x2'));var fs=require('fs');var Redis=require(_0x6594('0x3'));var db=require(_0x6594('0x4'))['db'];var utils=require(_0x6594('0x5'));var logger=require('../../config/logger')('rpc');var config=require(_0x6594('0x6'));var jayson=require(_0x6594('0x7'));var client=jayson[_0x6594('0x8')][_0x6594('0x9')]({'port':0x232a});config['redis']=_[_0x6594('0xa')](config['redis'],{'host':_0x6594('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x6594('0xc'))[_0x6594('0xd')](socket);function respondWithRpcPromise(_0x535b5e,_0x9872b3,_0x5ea911){return new BPromise(function(_0xb6ca72,_0x64d553){return client[_0x6594('0xe')](_0x535b5e,_0x5ea911)[_0x6594('0xf')](function(_0x4828af){logger['info']('MailInteraction,\x20%s,\x20%s',_0x9872b3,'request\x20sent');logger[_0x6594('0x10')](_0x6594('0x11'),_0x9872b3,_0x6594('0x12'),JSON[_0x6594('0x13')](_0x4828af));if(_0x4828af[_0x6594('0x14')]){if(_0x4828af[_0x6594('0x14')][_0x6594('0x15')]===0x1f4){logger[_0x6594('0x14')](_0x6594('0x16'),_0x9872b3,_0x4828af[_0x6594('0x14')][_0x6594('0x17')]);return _0x64d553(_0x4828af[_0x6594('0x14')][_0x6594('0x17')]);}logger[_0x6594('0x14')](_0x6594('0x16'),_0x9872b3,_0x4828af[_0x6594('0x14')][_0x6594('0x17')]);return _0xb6ca72(_0x4828af[_0x6594('0x14')][_0x6594('0x17')]);}else{logger['info'](_0x6594('0x16'),_0x9872b3,_0x6594('0x12'));_0xb6ca72(_0x4828af[_0x6594('0x18')][_0x6594('0x17')]);}})['catch'](function(_0x43e5d2){logger[_0x6594('0x14')](_0x6594('0x16'),_0x9872b3,_0x43e5d2);_0x64d553(_0x43e5d2);});});}exports[_0x6594('0x19')]=function(_0x3053ee){var _0x331066=this;return new Promise(function(_0x33ba0f,_0xa57345){return db[_0x6594('0x1a')][_0x6594('0x1b')](_0x3053ee[_0x6594('0x1c')],{'raw':_0x3053ee[_0x6594('0x1d')]?_0x3053ee[_0x6594('0x1d')][_0x6594('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3053ee['options']?_0x3053ee[_0x6594('0x1d')][_0x6594('0x1f')]||null:null,'attributes':_0x3053ee[_0x6594('0x1d')]?_0x3053ee[_0x6594('0x1d')][_0x6594('0x20')]||null:null,'limit':_0x3053ee[_0x6594('0x1d')]?_0x3053ee['options'][_0x6594('0x21')]||null:null})['then'](function(_0x1b7b13){logger[_0x6594('0x22')](_0x6594('0x19'),_0x3053ee);logger[_0x6594('0x10')](_0x6594('0x19'),_0x3053ee,JSON[_0x6594('0x13')](_0x1b7b13));_0x33ba0f(_0x1b7b13);})['catch'](function(_0x48d25b){logger[_0x6594('0x14')]('UpdateMailInteraction',_0x48d25b['message'],_0x3053ee);_0xa57345(_0x331066[_0x6594('0x14')](0x1f4,_0x48d25b['message']));});});};exports[_0x6594('0x23')]=function(_0x2781d5){return new Promise(function(_0x376317,_0x5af9cb){return db[_0x6594('0x1a')][_0x6594('0x24')]({'where':_0x2781d5[_0x6594('0x1d')]?_0x2781d5[_0x6594('0x1d')][_0x6594('0x1f')]||null:null})[_0x6594('0xf')](function(_0x40e891){if(_0x40e891){return _0x40e891[_0x6594('0x25')](_0x2781d5[_0x6594('0x1c')]['ids'],_[_0x6594('0x26')](_0x2781d5['body'],[_0x6594('0x27'),'id'])||{});}})[_0x6594('0x28')](function(_0x3016e0){logger[_0x6594('0x22')](_0x6594('0x29'),_0x2781d5);logger[_0x6594('0x10')](_0x6594('0x29'),_0x2781d5,JSON['stringify'](_0x3016e0));_0x376317(_0x3016e0);})[_0x6594('0x2a')](function(_0x4e30d7){logger[_0x6594('0x14')]('AddTags',_0x4e30d7['message'],_0x2781d5);_0x5af9cb(_this[_0x6594('0x14')](0x1f4,_0x4e30d7['message']));});});};