1ffcec05a627973da50cf53e598afab26e5625b6
[motion2.git] / server / api / faxAccount / faxAccount.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 _0xdd04=['Sequelize','ValidationError','no\x20available\x20attributes','difference','keys','createdAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','FaxAccount','find','account','List','Contacts','updatedAt','DESC','FaxApplication','Applications','applications','list','priority','asc','length','create','contact','FaxInteraction','Contact\x20not\x20found','get','autoclose','push','unmanaged','*,*,*,*','created','interaction','FaxMessage','ContactId','AttachmentId','UserId','name','agent','queueId','FaxQueue','queue','waitForTheAssignedQueue','Start','startRouting','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','defaults','redis','localhost','socket.io-emitter','./faxAccount.socket','register','request','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','GetFaxAccount','options','raw','where','attributes','limit','map','include','model','stringify','NotifyFaxAccount','body','fax','CmContact','describe'];(function(_0x2faddb,_0xc18b78){var _0x273c05=function(_0x1a3785){while(--_0x1a3785){_0x2faddb['push'](_0x2faddb['shift']());}};_0x273c05(++_0xc18b78);}(_0xdd04,0x157));var _0x4dd0=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xdd04[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x4dd0('0x0'));var util=require(_0x4dd0('0x1'));var moment=require(_0x4dd0('0x2'));var BPromise=require(_0x4dd0('0x3'));var rs=require(_0x4dd0('0x4'));var fs=require('fs');var Redis=require(_0x4dd0('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0x4dd0('0x6'));var logger=require(_0x4dd0('0x7'))('rpc');var config=require(_0x4dd0('0x8'));var jayson=require(_0x4dd0('0x9'));var client=jayson[_0x4dd0('0xa')][_0x4dd0('0xb')]({'port':0x232c});config['redis']=_[_0x4dd0('0xc')](config[_0x4dd0('0xd')],{'host':_0x4dd0('0xe'),'port':0x18eb});var socket=require(_0x4dd0('0xf'))(new Redis(config[_0x4dd0('0xd')]));require(_0x4dd0('0x10'))[_0x4dd0('0x11')](socket);function respondWithRpcPromise(_0x3d4498,_0x26e4dc,_0x59ae93){return new BPromise(function(_0xc9a9fd,_0x4fda9e){return client[_0x4dd0('0x12')](_0x3d4498,_0x59ae93)[_0x4dd0('0x13')](function(_0xdd606c){logger[_0x4dd0('0x14')](_0x4dd0('0x15'),_0x26e4dc,_0x4dd0('0x16'));logger[_0x4dd0('0x17')](_0x4dd0('0x18'),_0x26e4dc,'request\x20sent',JSON['stringify'](_0xdd606c));if(_0xdd606c[_0x4dd0('0x19')]){if(_0xdd606c['error'][_0x4dd0('0x1a')]===0x1f4){logger['error'](_0x4dd0('0x15'),_0x26e4dc,_0xdd606c['error'][_0x4dd0('0x1b')]);return _0x4fda9e(_0xdd606c[_0x4dd0('0x19')][_0x4dd0('0x1b')]);}logger['error'](_0x4dd0('0x15'),_0x26e4dc,_0xdd606c[_0x4dd0('0x19')][_0x4dd0('0x1b')]);return _0xc9a9fd(_0xdd606c[_0x4dd0('0x19')][_0x4dd0('0x1b')]);}else{logger['info']('FaxAccount,\x20%s,\x20%s',_0x26e4dc,'request\x20sent');_0xc9a9fd(_0xdd606c[_0x4dd0('0x1c')][_0x4dd0('0x1b')]);}})[_0x4dd0('0x1d')](function(_0x671bd3){logger[_0x4dd0('0x19')](_0x4dd0('0x15'),_0x26e4dc,_0x671bd3);_0x4fda9e(_0x671bd3);});});}exports[_0x4dd0('0x1e')]=function(_0x388d15){var _0x5c678e=this;return new Promise(function(_0x1596a0,_0x2d44f6){return db['FaxAccount']['findAll']({'raw':_0x388d15[_0x4dd0('0x1f')]?_0x388d15['options'][_0x4dd0('0x20')]===undefined?!![]:![]:!![],'where':_0x388d15[_0x4dd0('0x1f')]?_0x388d15[_0x4dd0('0x1f')][_0x4dd0('0x21')]||null:null,'attributes':_0x388d15[_0x4dd0('0x1f')]?_0x388d15[_0x4dd0('0x1f')][_0x4dd0('0x22')]||null:null,'limit':_0x388d15[_0x4dd0('0x1f')]?_0x388d15[_0x4dd0('0x1f')][_0x4dd0('0x23')]||null:null,'include':_0x388d15[_0x4dd0('0x1f')]?_0x388d15['options']['include']?_[_0x4dd0('0x24')](_0x388d15[_0x4dd0('0x1f')][_0x4dd0('0x25')],function(_0x285e5b){return{'model':db[_0x285e5b[_0x4dd0('0x26')]],'as':_0x285e5b['as'],'attributes':_0x285e5b[_0x4dd0('0x22')],'include':_0x285e5b['include']?_[_0x4dd0('0x24')](_0x285e5b[_0x4dd0('0x25')],function(_0xcf28eb){return{'model':db[_0xcf28eb[_0x4dd0('0x26')]],'as':_0xcf28eb['as'],'attributes':_0xcf28eb[_0x4dd0('0x22')],'include':_0xcf28eb[_0x4dd0('0x25')]?_[_0x4dd0('0x24')](_0xcf28eb[_0x4dd0('0x25')],function(_0x5c6d73){return{'model':db[_0x5c6d73[_0x4dd0('0x26')]],'as':_0x5c6d73['as'],'attributes':_0x5c6d73[_0x4dd0('0x22')]};}):[]};}):[]};}):[]:[]})[_0x4dd0('0x13')](function(_0x3d6f51){logger[_0x4dd0('0x14')]('GetFaxAccount',_0x388d15);logger[_0x4dd0('0x17')](_0x4dd0('0x1e'),_0x388d15,JSON[_0x4dd0('0x27')](_0x3d6f51));_0x1596a0(_0x3d6f51);})['catch'](function(_0x37ab51){logger[_0x4dd0('0x19')]('GetFaxAccount',_0x37ab51['message'],_0x388d15);_0x2d44f6(_0x5c678e['error'](0x1f4,_0x37ab51[_0x4dd0('0x1b')]));});});};exports[_0x4dd0('0x28')]=function(_0x567d32,_0xdc8e4,_0x5c25b1){var _0x142b53=this;return new Promise(function(_0x4b42a1,_0x42397c){var _0x19ea79={'body':_0x567d32[_0x4dd0('0x29')],'channel':_0x4dd0('0x2a')};var _0x50e3ad=[];var _0x2539e1=[];var _0x821fe1={};return db[_0x4dd0('0x2b')][_0x4dd0('0x2c')]()[_0x4dd0('0x13')](function(_0x2af104){if(!_0x2af104){throw new db[(_0x4dd0('0x2d'))][(_0x4dd0('0x2e'))](_0x4dd0('0x2f'));}_0x50e3ad=_[_0x4dd0('0x30')](_[_0x4dd0('0x31')](_0x2af104),[_0x4dd0('0x32'),'updatedAt']);_0x2539e1=_['difference'](_[_0x4dd0('0x31')](_0x2af104),[_0x4dd0('0x32'),'updatedAt',_0x4dd0('0x33'),_0x4dd0('0x34')]);if(_0x567d32[_0x4dd0('0x29')]['id']){delete _0x567d32[_0x4dd0('0x29')]['id'];}if(_[_0x4dd0('0x35')](_0x567d32[_0x4dd0('0x29')][_0x4dd0('0x36')])){throw new db['Sequelize']['ValidationError'](_0x4dd0('0x37'));}if(_['isNil'](_0x567d32['body'][_0x4dd0('0x29')])||_0x567d32['body'][_0x4dd0('0x29')]===''){throw new db[(_0x4dd0('0x2d'))][(_0x4dd0('0x2e'))](_0x4dd0('0x38'));}if(_['isNil'](_0x567d32[_0x4dd0('0x29')][_0x4dd0('0x39')])){throw new db[(_0x4dd0('0x2d'))][(_0x4dd0('0x2e'))](_0x4dd0('0x3a')+_0x2539e1);}if(!_[_0x4dd0('0x3b')](_0x2539e1,_0x567d32[_0x4dd0('0x29')][_0x4dd0('0x39')])){throw new db[(_0x4dd0('0x2d'))][(_0x4dd0('0x2e'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2539e1);}_0x821fe1[_0x567d32[_0x4dd0('0x29')]['mapKey']]=_0x567d32['body'][_0x4dd0('0x36')];})[_0x4dd0('0x13')](function(){return db[_0x4dd0('0x3c')][_0x4dd0('0x3d')]({'where':{'id':_0x567d32[_0x4dd0('0x3e')]['id']},'include':[{'model':db['CmList'],'as':_0x4dd0('0x3f'),'include':[{'model':db[_0x4dd0('0x2b')],'as':_0x4dd0('0x40'),'where':_0x821fe1,'limit':0x1,'order':[[_0x4dd0('0x41'),_0x4dd0('0x42')]]}]},{'model':db[_0x4dd0('0x43')],'as':_0x4dd0('0x44')}]});})[_0x4dd0('0x13')](function(_0x233384){if(_0x233384&&_0x233384[_0x4dd0('0x3f')]){var _0x781e62=_0x233384['get']({'plain':!![]});_0x19ea79['account']=_0x781e62;_0x19ea79[_0x4dd0('0x45')]=_0x781e62[_0x4dd0('0x44')];_0x19ea79[_0x4dd0('0x46')]=_0x781e62[_0x4dd0('0x3f')];_0x19ea79[_0x4dd0('0x45')]=_['orderBy'](_0x19ea79[_0x4dd0('0x45')],[_0x4dd0('0x47')],[_0x4dd0('0x48')]);if(_0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x44')]){delete _0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x44')];}if(_0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x3f')]&&_0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x3f')][_0x4dd0('0x40')][_0x4dd0('0x49')]){return _0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x3f')][_0x4dd0('0x40')][0x0];}var _0x36f987=_[_0x4dd0('0xc')](_0x567d32['body'],{'firstName':_0x567d32[_0x4dd0('0x29')]['from'],'ListId':_0x781e62[_0x4dd0('0x34')]});_0x36f987[_0x567d32['body'][_0x4dd0('0x39')]]=_0x567d32[_0x4dd0('0x29')][_0x4dd0('0x36')];return db['CmContact'][_0x4dd0('0x4a')](_0x36f987,{'fields':_0x50e3ad,'raw':!![]});}})[_0x4dd0('0x13')](function(_0x19d243){_0x19ea79[_0x4dd0('0x4b')]=_0x19d243;if(_0x19d243){var _0x5ad08f={'ContactId':_0x19d243['id'],'FaxAccountId':_0x567d32['account']['id'],'fax':_0x19d243[_0x4dd0('0x2a')]};return db[_0x4dd0('0x4c')][_0x4dd0('0x3d')]({'where':{'ContactId':_0x19d243['id'],'closed':![],'FaxAccountId':_0x567d32[_0x4dd0('0x3e')]['id']}})[_0x4dd0('0x13')](function(_0x18ae38){if(_0x18ae38){return[_0x18ae38,![]];}return db[_0x4dd0('0x4c')][_0x4dd0('0x4a')](_0x5ad08f)[_0x4dd0('0x13')](function(_0x571670){return[_0x571670,!![]];});});}else{throw new Error(_0x4dd0('0x4d'));}})['spread'](function(_0x44da6f,_0x39e02f){var _0x11bc40=_0x44da6f[_0x4dd0('0x4e')]({'plain':!![]});if(_0x39e02f){if(_0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x4f')]){_0x19ea79[_0x4dd0('0x45')][_0x4dd0('0x50')]({'id':0x0,'priority':_0x19ea79[_0x4dd0('0x45')][_0x4dd0('0x49')]+0x1,'app':'close','appdata':_0x4dd0('0x51'),'interval':_0x4dd0('0x52')});}_0x11bc40[_0x4dd0('0x53')]=!![];}else{_0x11bc40['created']=![];}_0x19ea79[_0x4dd0('0x54')]=_0x11bc40;return db[_0x4dd0('0x55')][_0x4dd0('0x4a')]({'body':_0x567d32['body']['body'],'FaxAccountId':_0x567d32[_0x4dd0('0x3e')]['id'],'FaxInteractionId':_0x44da6f['id'],'direction':'in','ContactId':_0x44da6f[_0x4dd0('0x56')],'AttachmentId':_0x567d32[_0x4dd0('0x29')][_0x4dd0('0x57')]});})[_0x4dd0('0x13')](function(_0x45dc88){_0x19ea79[_0x4dd0('0x1b')]=_0x45dc88;if(!_0x19ea79['interaction'][_0x4dd0('0x58')])return;return db['User'][_0x4dd0('0x3d')]({'attributes':['id',_0x4dd0('0x59')],'where':{'id':_0x19ea79[_0x4dd0('0x54')]['UserId']}});})[_0x4dd0('0x13')](function(_0x16b2d3){if(_0x16b2d3){_0x19ea79[_0x4dd0('0x45')]['unshift']({'id':0x0,'priority':0x0,'app':_0x4dd0('0x5a'),'appdata':_0x16b2d3[_0x4dd0('0x59')]+','+(_0x19ea79['account']['waitForTheAssignedAgent']||0xa),'interval':'*,*,*,*'});}if(!_0x19ea79[_0x4dd0('0x54')][_0x4dd0('0x5b')])return;return db[_0x4dd0('0x5c')][_0x4dd0('0x3d')]({'attributes':['id',_0x4dd0('0x59')],'where':{'id':_0x19ea79[_0x4dd0('0x54')]['queueId']}});})[_0x4dd0('0x13')](function(_0x53b400){if(_0x53b400){_0x19ea79[_0x4dd0('0x45')]['unshift']({'id':0x0,'priority':0x1,'app':_0x4dd0('0x5d'),'appdata':_0x53b400[_0x4dd0('0x59')]+','+(_0x19ea79[_0x4dd0('0x3e')][_0x4dd0('0x5e')]||0x12c),'interval':_0x4dd0('0x52')});}return respondWithRpcPromise(_0x4dd0('0x5f'),_0x4dd0('0x60'),_0x19ea79);})[_0x4dd0('0x13')](function(_0x5ba7b6){_0x4b42a1(_0x5ba7b6);})[_0x4dd0('0x1d')](function(_0x3b1dd7){_0x42397c(_0x142b53[_0x4dd0('0x19')](0x1f4,_0x3b1dd7[_0x4dd0('0x1b')]));});});};