ac124926d11b93bc105a850d092cd60b49651b40
[motion2.git] / server / api / faxInteraction / faxInteraction.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 _0xa0bb=['body','ids','omit','AddTags','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','localhost','./faxInteraction.socket','register','request','info','request\x20sent','debug','FaxInteraction,\x20%s,\x20%s,\x20%s','stringify','error','FaxInteraction,\x20%s,\x20%s','message','result','catch','UpdateFaxInteraction','FaxInteraction','options','raw','where','attributes','limit','then'];(function(_0x3932eb,_0x43b210){var _0x5316e5=function(_0x1744e8){while(--_0x1744e8){_0x3932eb['push'](_0x3932eb['shift']());}};_0x5316e5(++_0x43b210);}(_0xa0bb,0x19b));var _0xba0b=function(_0xd730d2,_0x1695eb){_0xd730d2=_0xd730d2-0x0;var _0x2c2bc1=_0xa0bb[_0xd730d2];return _0x2c2bc1;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xba0b('0x0'));var BPromise=require(_0xba0b('0x1'));var rs=require(_0xba0b('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xba0b('0x3'))['db'];var utils=require(_0xba0b('0x4'));var logger=require(_0xba0b('0x5'))('rpc');var config=require(_0xba0b('0x6'));var jayson=require(_0xba0b('0x7'));var client=jayson[_0xba0b('0x8')][_0xba0b('0x9')]({'port':0x232a});config['redis']=_['defaults'](config[_0xba0b('0xa')],{'host':_0xba0b('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xba0b('0xa')]));require(_0xba0b('0xc'))[_0xba0b('0xd')](socket);function respondWithRpcPromise(_0x1476f3,_0x68dc41,_0x18cfe9){return new BPromise(function(_0x533661,_0x12d777){return client[_0xba0b('0xe')](_0x1476f3,_0x18cfe9)['then'](function(_0x442be9){logger[_0xba0b('0xf')]('FaxInteraction,\x20%s,\x20%s',_0x68dc41,_0xba0b('0x10'));logger[_0xba0b('0x11')](_0xba0b('0x12'),_0x68dc41,_0xba0b('0x10'),JSON[_0xba0b('0x13')](_0x442be9));if(_0x442be9[_0xba0b('0x14')]){if(_0x442be9['error']['code']===0x1f4){logger[_0xba0b('0x14')](_0xba0b('0x15'),_0x68dc41,_0x442be9[_0xba0b('0x14')][_0xba0b('0x16')]);return _0x12d777(_0x442be9[_0xba0b('0x14')]['message']);}logger['error'](_0xba0b('0x15'),_0x68dc41,_0x442be9[_0xba0b('0x14')][_0xba0b('0x16')]);return _0x533661(_0x442be9[_0xba0b('0x14')]['message']);}else{logger[_0xba0b('0xf')](_0xba0b('0x15'),_0x68dc41,_0xba0b('0x10'));_0x533661(_0x442be9[_0xba0b('0x17')][_0xba0b('0x16')]);}})[_0xba0b('0x18')](function(_0xa92867){logger[_0xba0b('0x14')]('FaxInteraction,\x20%s,\x20%s',_0x68dc41,_0xa92867);_0x12d777(_0xa92867);});});}exports[_0xba0b('0x19')]=function(_0x3a5922){var _0x27c42f=this;return new Promise(function(_0x209f76,_0x353dce){return db[_0xba0b('0x1a')]['update'](_0x3a5922['body'],{'raw':_0x3a5922['options']?_0x3a5922[_0xba0b('0x1b')][_0xba0b('0x1c')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x3a5922[_0xba0b('0x1b')]?_0x3a5922[_0xba0b('0x1b')][_0xba0b('0x1d')]||null:null,'attributes':_0x3a5922[_0xba0b('0x1b')]?_0x3a5922[_0xba0b('0x1b')][_0xba0b('0x1e')]||null:null,'limit':_0x3a5922[_0xba0b('0x1b')]?_0x3a5922['options'][_0xba0b('0x1f')]||null:null})[_0xba0b('0x20')](function(_0x6fe9e0){logger[_0xba0b('0xf')](_0xba0b('0x19'),_0x3a5922);logger[_0xba0b('0x11')](_0xba0b('0x19'),_0x3a5922,JSON['stringify'](_0x6fe9e0));_0x209f76(_0x6fe9e0);})[_0xba0b('0x18')](function(_0x2ff66c){logger[_0xba0b('0x14')]('UpdateFaxInteraction',_0x2ff66c['message'],_0x3a5922);_0x353dce(_0x27c42f[_0xba0b('0x14')](0x1f4,_0x2ff66c['message']));});});};exports['AddTagsToFaxInteraction']=function(_0xb854b1){return new Promise(function(_0x4197be,_0x25e28d){return db[_0xba0b('0x1a')]['find']({'where':_0xb854b1['options']?_0xb854b1[_0xba0b('0x1b')][_0xba0b('0x1d')]||null:null})[_0xba0b('0x20')](function(_0x186d95){if(_0x186d95){return _0x186d95['addTags'](_0xb854b1[_0xba0b('0x21')][_0xba0b('0x22')],_[_0xba0b('0x23')](_0xb854b1[_0xba0b('0x21')],[_0xba0b('0x22'),'id'])||{});}})['spread'](function(_0xea4893){logger['info'](_0xba0b('0x24'),_0xb854b1);logger[_0xba0b('0x11')]('AddTags',_0xb854b1,JSON[_0xba0b('0x13')](_0xea4893));_0x4197be(_0xea4893);})[_0xba0b('0x18')](function(_0x7a1faf){logger[_0xba0b('0x14')](_0xba0b('0x24'),_0x7a1faf[_0xba0b('0x16')],_0xb854b1);_0x25e28d(_this[_0xba0b('0x14')](0x1f4,_0x7a1faf['message']));});});};