Built motion from commit (unavailable).|2.6.0
[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 _0x7ae3=['raw','where','attributes','limit','map','include','model','NotifyFaxAccount','body','fax','describe','ValidationError','difference','createdAt','updatedAt','keys','CompanyId','ListId','isNil','from','Sequelize','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','find','account','CmList','List','CmContact','Contacts','DESC','Applications','get','list','applications','priority','asc','length','defaults','contact','FaxInteraction','create','spread','autoclose','close','*,*,*,*','created','interaction','ContactId','AttachmentId','UserId','User','name','unshift','agent','waitForTheAssignedAgent','Start','startRouting','lodash','moment','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./faxAccount.socket','register','request','then','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetFaxAccount','FaxAccount','options'];(function(_0x276468,_0x29685a){var _0x36dc3a=function(_0x291f0a){while(--_0x291f0a){_0x276468['push'](_0x276468['shift']());}};_0x36dc3a(++_0x29685a);}(_0x7ae3,0x14a));var _0x37ae=function(_0x17606f,_0x1e2e94){_0x17606f=_0x17606f-0x0;var _0x3658e7=_0x7ae3[_0x17606f];return _0x3658e7;};'use strict';var _=require(_0x37ae('0x0'));var util=require('util');var moment=require(_0x37ae('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x37ae('0x2'));var db=require(_0x37ae('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0x37ae('0x4'))(_0x37ae('0x5'));var config=require(_0x37ae('0x6'));var jayson=require(_0x37ae('0x7'));var client=jayson[_0x37ae('0x8')][_0x37ae('0x9')]({'port':0x232c});config[_0x37ae('0xa')]=_['defaults'](config['redis'],{'host':_0x37ae('0xb'),'port':0x18eb});var socket=require(_0x37ae('0xc'))(new Redis(config[_0x37ae('0xa')]));require(_0x37ae('0xd'))[_0x37ae('0xe')](socket);function respondWithRpcPromise(_0x2f6509,_0x191a0a,_0x59df0a){return new BPromise(function(_0x18ce80,_0x11ea5c){return client[_0x37ae('0xf')](_0x2f6509,_0x59df0a)[_0x37ae('0x10')](function(_0x1a6336){logger['info'](_0x37ae('0x11'),_0x191a0a,_0x37ae('0x12'));logger[_0x37ae('0x13')](_0x37ae('0x14'),_0x191a0a,_0x37ae('0x12'),JSON[_0x37ae('0x15')](_0x1a6336));if(_0x1a6336[_0x37ae('0x16')]){if(_0x1a6336[_0x37ae('0x16')][_0x37ae('0x17')]===0x1f4){logger['error'](_0x37ae('0x11'),_0x191a0a,_0x1a6336[_0x37ae('0x16')]['message']);return _0x11ea5c(_0x1a6336[_0x37ae('0x16')][_0x37ae('0x18')]);}logger[_0x37ae('0x16')](_0x37ae('0x11'),_0x191a0a,_0x1a6336[_0x37ae('0x16')]['message']);return _0x18ce80(_0x1a6336['error'][_0x37ae('0x18')]);}else{logger['info'](_0x37ae('0x11'),_0x191a0a,_0x37ae('0x12'));_0x18ce80(_0x1a6336[_0x37ae('0x19')][_0x37ae('0x18')]);}})[_0x37ae('0x1a')](function(_0x59ef37){logger[_0x37ae('0x16')](_0x37ae('0x11'),_0x191a0a,_0x59ef37);_0x11ea5c(_0x59ef37);});});}exports[_0x37ae('0x1b')]=function(_0x23011d){var _0x154bfb=this;return new Promise(function(_0x63db7d,_0x108d7e){return db[_0x37ae('0x1c')]['findAll']({'raw':_0x23011d[_0x37ae('0x1d')]?_0x23011d['options'][_0x37ae('0x1e')]===undefined?!![]:![]:!![],'where':_0x23011d[_0x37ae('0x1d')]?_0x23011d[_0x37ae('0x1d')][_0x37ae('0x1f')]||null:null,'attributes':_0x23011d[_0x37ae('0x1d')]?_0x23011d[_0x37ae('0x1d')][_0x37ae('0x20')]||null:null,'limit':_0x23011d[_0x37ae('0x1d')]?_0x23011d['options'][_0x37ae('0x21')]||null:null,'include':_0x23011d['options']?_0x23011d['options']['include']?_[_0x37ae('0x22')](_0x23011d[_0x37ae('0x1d')][_0x37ae('0x23')],function(_0x59fbcb){return{'model':db[_0x59fbcb[_0x37ae('0x24')]],'as':_0x59fbcb['as'],'attributes':_0x59fbcb[_0x37ae('0x20')],'include':_0x59fbcb[_0x37ae('0x23')]?_[_0x37ae('0x22')](_0x59fbcb[_0x37ae('0x23')],function(_0x28f5fc){return{'model':db[_0x28f5fc[_0x37ae('0x24')]],'as':_0x28f5fc['as'],'attributes':_0x28f5fc['attributes'],'include':_0x28f5fc['include']?_[_0x37ae('0x22')](_0x28f5fc[_0x37ae('0x23')],function(_0x259ce0){return{'model':db[_0x259ce0[_0x37ae('0x24')]],'as':_0x259ce0['as'],'attributes':_0x259ce0[_0x37ae('0x20')]};}):[]};}):[]};}):[]:[]})[_0x37ae('0x10')](function(_0x4f5e69){logger['info']('GetFaxAccount',_0x23011d);logger[_0x37ae('0x13')](_0x37ae('0x1b'),_0x23011d,JSON[_0x37ae('0x15')](_0x4f5e69));_0x63db7d(_0x4f5e69);})[_0x37ae('0x1a')](function(_0x4dc170){logger[_0x37ae('0x16')](_0x37ae('0x1b'),_0x4dc170[_0x37ae('0x18')],_0x23011d);_0x108d7e(_0x154bfb[_0x37ae('0x16')](0x1f4,_0x4dc170[_0x37ae('0x18')]));});});};exports[_0x37ae('0x25')]=function(_0x44bd13,_0x949579,_0x539c8f){var _0xee6cfd=this;return new Promise(function(_0x3a08c9,_0x29c9dc){var _0x40186f={'body':_0x44bd13[_0x37ae('0x26')],'channel':_0x37ae('0x27')};var _0x49c817=[];var _0x213da4=[];var _0x3fdf66={};return db['CmContact'][_0x37ae('0x28')]()[_0x37ae('0x10')](function(_0x946d43){if(!_0x946d43){throw new db['Sequelize'][(_0x37ae('0x29'))]('no\x20available\x20attributes');}_0x49c817=_[_0x37ae('0x2a')](_['keys'](_0x946d43),[_0x37ae('0x2b'),_0x37ae('0x2c')]);_0x213da4=_[_0x37ae('0x2a')](_[_0x37ae('0x2d')](_0x946d43),[_0x37ae('0x2b'),_0x37ae('0x2c'),_0x37ae('0x2e'),_0x37ae('0x2f')]);if(_0x44bd13[_0x37ae('0x26')]['id']){delete _0x44bd13['body']['id'];}if(_[_0x37ae('0x30')](_0x44bd13[_0x37ae('0x26')][_0x37ae('0x31')])){throw new db[(_0x37ae('0x32'))][(_0x37ae('0x29'))](_0x37ae('0x33'));}if(_['isNil'](_0x44bd13[_0x37ae('0x26')][_0x37ae('0x26')])||_0x44bd13[_0x37ae('0x26')][_0x37ae('0x26')]===''){throw new db[(_0x37ae('0x32'))][(_0x37ae('0x29'))](_0x37ae('0x34'));}if(_[_0x37ae('0x30')](_0x44bd13[_0x37ae('0x26')][_0x37ae('0x35')])){throw new db[(_0x37ae('0x32'))][(_0x37ae('0x29'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x213da4);}if(!_[_0x37ae('0x36')](_0x213da4,_0x44bd13[_0x37ae('0x26')][_0x37ae('0x35')])){throw new db[(_0x37ae('0x32'))][(_0x37ae('0x29'))](_0x37ae('0x37')+_0x213da4);}_0x3fdf66[_0x44bd13[_0x37ae('0x26')]['mapKey']]=_0x44bd13['body'][_0x37ae('0x31')];})[_0x37ae('0x10')](function(){return db[_0x37ae('0x1c')][_0x37ae('0x38')]({'where':{'id':_0x44bd13[_0x37ae('0x39')]['id']},'include':[{'model':db[_0x37ae('0x3a')],'as':_0x37ae('0x3b'),'include':[{'model':db[_0x37ae('0x3c')],'as':_0x37ae('0x3d'),'where':_0x3fdf66,'limit':0x1,'order':[[_0x37ae('0x2c'),_0x37ae('0x3e')]]}]},{'model':db['FaxApplication'],'as':_0x37ae('0x3f')}]});})['then'](function(_0x3814df){if(_0x3814df&&_0x3814df[_0x37ae('0x3b')]){var _0xb6f632=_0x3814df[_0x37ae('0x40')]({'plain':!![]});_0x40186f[_0x37ae('0x39')]=_0xb6f632;_0x40186f['applications']=_0xb6f632[_0x37ae('0x3f')];_0x40186f[_0x37ae('0x41')]=_0xb6f632['List'];_0x40186f[_0x37ae('0x42')]=_['orderBy'](_0x40186f[_0x37ae('0x42')],[_0x37ae('0x43')],[_0x37ae('0x44')]);if(_0x40186f[_0x37ae('0x39')][_0x37ae('0x3f')]){delete _0x40186f['account'][_0x37ae('0x3f')];}if(_0x40186f['account'][_0x37ae('0x3b')]&&_0x40186f['account'][_0x37ae('0x3b')]['Contacts'][_0x37ae('0x45')]){return _0x40186f[_0x37ae('0x39')]['List'][_0x37ae('0x3d')][0x0];}var _0x4d1d5e=_[_0x37ae('0x46')](_0x44bd13[_0x37ae('0x26')],{'firstName':_0x44bd13['body'][_0x37ae('0x31')],'ListId':_0xb6f632['ListId']});_0x4d1d5e[_0x44bd13['body'][_0x37ae('0x35')]]=_0x44bd13[_0x37ae('0x26')][_0x37ae('0x31')];return db[_0x37ae('0x3c')]['create'](_0x4d1d5e,{'fields':_0x49c817,'raw':!![]});}})[_0x37ae('0x10')](function(_0x24321b){_0x40186f[_0x37ae('0x47')]=_0x24321b;if(_0x24321b){var _0x47205e={'ContactId':_0x24321b['id'],'FaxAccountId':_0x44bd13[_0x37ae('0x39')]['id'],'fax':_0x24321b['fax']};return db[_0x37ae('0x48')][_0x37ae('0x38')]({'where':{'ContactId':_0x24321b['id'],'closed':![],'FaxAccountId':_0x44bd13[_0x37ae('0x39')]['id']}})[_0x37ae('0x10')](function(_0x5decef){if(_0x5decef){return[_0x5decef,![]];}return db[_0x37ae('0x48')][_0x37ae('0x49')](_0x47205e)[_0x37ae('0x10')](function(_0x4aa5d1){return[_0x4aa5d1,!![]];});});}else{throw new Error('Contact\x20not\x20found');}})[_0x37ae('0x4a')](function(_0x16da49,_0x59fd85){var _0x229635=_0x16da49[_0x37ae('0x40')]({'plain':!![]});if(_0x59fd85){if(_0x40186f[_0x37ae('0x39')][_0x37ae('0x4b')]){_0x40186f[_0x37ae('0x42')]['push']({'id':0x0,'priority':_0x40186f['applications'][_0x37ae('0x45')]+0x1,'app':_0x37ae('0x4c'),'appdata':'unmanaged','interval':_0x37ae('0x4d')});}_0x229635[_0x37ae('0x4e')]=!![];}else{_0x229635['created']=![];}_0x40186f[_0x37ae('0x4f')]=_0x229635;return db['FaxMessage'][_0x37ae('0x49')]({'body':_0x44bd13[_0x37ae('0x26')][_0x37ae('0x26')],'FaxAccountId':_0x44bd13[_0x37ae('0x39')]['id'],'FaxInteractionId':_0x16da49['id'],'direction':'in','ContactId':_0x16da49[_0x37ae('0x50')],'AttachmentId':_0x44bd13[_0x37ae('0x26')][_0x37ae('0x51')]});})['then'](function(_0x578d93){_0x40186f[_0x37ae('0x18')]=_0x578d93;if(_0x40186f['interaction'][_0x37ae('0x52')]){return db[_0x37ae('0x53')]['find']({'attributes':['id',_0x37ae('0x54')],'where':{'id':_0x40186f[_0x37ae('0x4f')][_0x37ae('0x52')]}})[_0x37ae('0x10')](function(_0x3e5767){if(_0x3e5767){_0x40186f[_0x37ae('0x42')][_0x37ae('0x55')]({'id':0x0,'priority':0x0,'app':_0x37ae('0x56'),'appdata':_0x3e5767[_0x37ae('0x54')]+','+(_0x40186f['account'][_0x37ae('0x57')]||0xa),'interval':'*,*,*,*'});}return respondWithRpcPromise('Start','startRouting',_0x40186f);});}return respondWithRpcPromise(_0x37ae('0x58'),_0x37ae('0x59'),_0x40186f);})['then'](function(_0x34686f){_0x3a08c9(_0x34686f);})[_0x37ae('0x1a')](function(_0x5b7743){_0x29c9dc(_0xee6cfd[_0x37ae('0x16')](0x1f4,_0x5b7743[_0x37ae('0x18')]));});});};