Built motion from commit 639a1a7f.|2.6.19
[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 _0x088b=['orderBy','asc','length','defaults','create','contact','Contact\x20not\x20found','spread','autoclose','push','close','*,*,*,*','created','interaction','ContactId','AttachmentId','UserId','User','name','unshift','agent','queueId','FaxQueue','startRouting','lodash','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','redis','socket.io-emitter','./faxAccount.socket','request','then','info','FaxAccount,\x20%s,\x20%s','request\x20sent','debug','FaxAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','options','attributes','limit','include','map','model','GetFaxAccount','catch','NotifyFaxAccount','fax','Sequelize','ValidationError','difference','keys','createdAt','CompanyId','ListId','body','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','FaxAccount','find','account','CmList','List','CmContact','Contacts','updatedAt','FaxApplication','Applications','get','applications','list'];(function(_0x3e1415,_0x2ad5ee){var _0x2e1ec7=function(_0x4beb31){while(--_0x4beb31){_0x3e1415['push'](_0x3e1415['shift']());}};_0x2e1ec7(++_0x2ad5ee);}(_0x088b,0xc8));var _0xb088=function(_0x4279e1,_0x39cda4){_0x4279e1=_0x4279e1-0x0;var _0x1e33ea=_0x088b[_0x4279e1];return _0x1e33ea;};'use strict';var _=require(_0xb088('0x0'));var util=require('util');var moment=require(_0xb088('0x1'));var BPromise=require(_0xb088('0x2'));var rs=require(_0xb088('0x3'));var fs=require('fs');var Redis=require(_0xb088('0x4'));var db=require(_0xb088('0x5'))['db'];var utils=require(_0xb088('0x6'));var logger=require(_0xb088('0x7'))(_0xb088('0x8'));var config=require(_0xb088('0x9'));var jayson=require(_0xb088('0xa'));var client=jayson['client'][_0xb088('0xb')]({'port':0x232c});config[_0xb088('0xc')]=_['defaults'](config[_0xb088('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0xb088('0xd'))(new Redis(config[_0xb088('0xc')]));require(_0xb088('0xe'))['register'](socket);function respondWithRpcPromise(_0x1e5d57,_0x482c14,_0x2fefc7){return new BPromise(function(_0x4fa1e4,_0x555a97){return client[_0xb088('0xf')](_0x1e5d57,_0x2fefc7)[_0xb088('0x10')](function(_0x51ea01){logger[_0xb088('0x11')](_0xb088('0x12'),_0x482c14,_0xb088('0x13'));logger[_0xb088('0x14')](_0xb088('0x15'),_0x482c14,_0xb088('0x13'),JSON[_0xb088('0x16')](_0x51ea01));if(_0x51ea01[_0xb088('0x17')]){if(_0x51ea01[_0xb088('0x17')]['code']===0x1f4){logger[_0xb088('0x17')](_0xb088('0x12'),_0x482c14,_0x51ea01[_0xb088('0x17')][_0xb088('0x18')]);return _0x555a97(_0x51ea01[_0xb088('0x17')][_0xb088('0x18')]);}logger[_0xb088('0x17')]('FaxAccount,\x20%s,\x20%s',_0x482c14,_0x51ea01['error'][_0xb088('0x18')]);return _0x4fa1e4(_0x51ea01['error'][_0xb088('0x18')]);}else{logger[_0xb088('0x11')](_0xb088('0x12'),_0x482c14,'request\x20sent');_0x4fa1e4(_0x51ea01[_0xb088('0x19')][_0xb088('0x18')]);}})['catch'](function(_0xcebe48){logger[_0xb088('0x17')](_0xb088('0x12'),_0x482c14,_0xcebe48);_0x555a97(_0xcebe48);});});}exports['GetFaxAccount']=function(_0x82157b){var _0x13a619=this;return new Promise(function(_0x27c881,_0x37b6be){return db['FaxAccount']['findAll']({'raw':_0x82157b[_0xb088('0x1a')]?_0x82157b[_0xb088('0x1a')]['raw']===undefined?!![]:![]:!![],'where':_0x82157b[_0xb088('0x1a')]?_0x82157b['options']['where']||null:null,'attributes':_0x82157b[_0xb088('0x1a')]?_0x82157b[_0xb088('0x1a')][_0xb088('0x1b')]||null:null,'limit':_0x82157b[_0xb088('0x1a')]?_0x82157b[_0xb088('0x1a')][_0xb088('0x1c')]||null:null,'include':_0x82157b['options']?_0x82157b[_0xb088('0x1a')][_0xb088('0x1d')]?_[_0xb088('0x1e')](_0x82157b[_0xb088('0x1a')][_0xb088('0x1d')],function(_0x4c0028){return{'model':db[_0x4c0028['model']],'as':_0x4c0028['as'],'attributes':_0x4c0028[_0xb088('0x1b')],'include':_0x4c0028[_0xb088('0x1d')]?_[_0xb088('0x1e')](_0x4c0028['include'],function(_0x49618e){return{'model':db[_0x49618e[_0xb088('0x1f')]],'as':_0x49618e['as'],'attributes':_0x49618e[_0xb088('0x1b')],'include':_0x49618e[_0xb088('0x1d')]?_[_0xb088('0x1e')](_0x49618e[_0xb088('0x1d')],function(_0x4cd8ef){return{'model':db[_0x4cd8ef['model']],'as':_0x4cd8ef['as'],'attributes':_0x4cd8ef['attributes']};}):[]};}):[]};}):[]:[]})[_0xb088('0x10')](function(_0x1680d4){logger[_0xb088('0x11')](_0xb088('0x20'),_0x82157b);logger[_0xb088('0x14')]('GetFaxAccount',_0x82157b,JSON[_0xb088('0x16')](_0x1680d4));_0x27c881(_0x1680d4);})[_0xb088('0x21')](function(_0x170040){logger[_0xb088('0x17')](_0xb088('0x20'),_0x170040[_0xb088('0x18')],_0x82157b);_0x37b6be(_0x13a619['error'](0x1f4,_0x170040[_0xb088('0x18')]));});});};exports[_0xb088('0x22')]=function(_0x4c6171,_0x9ea8ef,_0x2a597b){var _0x4447f2=this;return new Promise(function(_0x2e344d,_0x3e76c7){var _0x2c8fc6={'body':_0x4c6171['body'],'channel':_0xb088('0x23')};var _0x221211=[];var _0x50cbe0=[];var _0x117125={};return db['CmContact']['describe']()['then'](function(_0x53940f){if(!_0x53940f){throw new db[(_0xb088('0x24'))][(_0xb088('0x25'))]('no\x20available\x20attributes');}_0x221211=_[_0xb088('0x26')](_[_0xb088('0x27')](_0x53940f),[_0xb088('0x28'),'updatedAt']);_0x50cbe0=_[_0xb088('0x26')](_['keys'](_0x53940f),[_0xb088('0x28'),'updatedAt',_0xb088('0x29'),_0xb088('0x2a')]);if(_0x4c6171['body']['id']){delete _0x4c6171[_0xb088('0x2b')]['id'];}if(_[_0xb088('0x2c')](_0x4c6171[_0xb088('0x2b')][_0xb088('0x2d')])){throw new db[(_0xb088('0x24'))][(_0xb088('0x25'))](_0xb088('0x2e'));}if(_[_0xb088('0x2c')](_0x4c6171[_0xb088('0x2b')][_0xb088('0x2b')])||_0x4c6171[_0xb088('0x2b')][_0xb088('0x2b')]===''){throw new db[(_0xb088('0x24'))][(_0xb088('0x25'))](_0xb088('0x2f'));}if(_[_0xb088('0x2c')](_0x4c6171[_0xb088('0x2b')][_0xb088('0x30')])){throw new db['Sequelize'][(_0xb088('0x25'))](_0xb088('0x31')+_0x50cbe0);}if(!_['includes'](_0x50cbe0,_0x4c6171[_0xb088('0x2b')][_0xb088('0x30')])){throw new db[(_0xb088('0x24'))][(_0xb088('0x25'))](_0xb088('0x32')+_0x50cbe0);}_0x117125[_0x4c6171[_0xb088('0x2b')]['mapKey']]=_0x4c6171[_0xb088('0x2b')][_0xb088('0x2d')];})['then'](function(){return db[_0xb088('0x33')][_0xb088('0x34')]({'where':{'id':_0x4c6171[_0xb088('0x35')]['id']},'include':[{'model':db[_0xb088('0x36')],'as':_0xb088('0x37'),'include':[{'model':db[_0xb088('0x38')],'as':_0xb088('0x39'),'where':_0x117125,'limit':0x1,'order':[[_0xb088('0x3a'),'DESC']]}]},{'model':db[_0xb088('0x3b')],'as':_0xb088('0x3c')}]});})[_0xb088('0x10')](function(_0xc5909f){if(_0xc5909f&&_0xc5909f['List']){var _0x5644f6=_0xc5909f[_0xb088('0x3d')]({'plain':!![]});_0x2c8fc6['account']=_0x5644f6;_0x2c8fc6[_0xb088('0x3e')]=_0x5644f6[_0xb088('0x3c')];_0x2c8fc6[_0xb088('0x3f')]=_0x5644f6[_0xb088('0x37')];_0x2c8fc6['applications']=_[_0xb088('0x40')](_0x2c8fc6[_0xb088('0x3e')],['priority'],[_0xb088('0x41')]);if(_0x2c8fc6[_0xb088('0x35')][_0xb088('0x3c')]){delete _0x2c8fc6[_0xb088('0x35')][_0xb088('0x3c')];}if(_0x2c8fc6[_0xb088('0x35')]['List']&&_0x2c8fc6['account'][_0xb088('0x37')]['Contacts'][_0xb088('0x42')]){return _0x2c8fc6['account']['List'][_0xb088('0x39')][0x0];}var _0x454148=_[_0xb088('0x43')](_0x4c6171[_0xb088('0x2b')],{'firstName':_0x4c6171[_0xb088('0x2b')][_0xb088('0x2d')],'ListId':_0x5644f6[_0xb088('0x2a')]});_0x454148[_0x4c6171[_0xb088('0x2b')][_0xb088('0x30')]]=_0x4c6171['body'][_0xb088('0x2d')];return db['CmContact'][_0xb088('0x44')](_0x454148,{'fields':_0x221211,'raw':!![]});}})[_0xb088('0x10')](function(_0x95bb31){_0x2c8fc6[_0xb088('0x45')]=_0x95bb31;if(_0x95bb31){var _0x1f98e5={'ContactId':_0x95bb31['id'],'FaxAccountId':_0x4c6171[_0xb088('0x35')]['id'],'fax':_0x95bb31['fax']};return db['FaxInteraction'][_0xb088('0x34')]({'where':{'ContactId':_0x95bb31['id'],'closed':![],'FaxAccountId':_0x4c6171['account']['id']}})[_0xb088('0x10')](function(_0x104e08){if(_0x104e08){return[_0x104e08,![]];}return db['FaxInteraction'][_0xb088('0x44')](_0x1f98e5)[_0xb088('0x10')](function(_0x41594c){return[_0x41594c,!![]];});});}else{throw new Error(_0xb088('0x46'));}})[_0xb088('0x47')](function(_0x39d0dc,_0x4f8b71){var _0x38fa5c=_0x39d0dc[_0xb088('0x3d')]({'plain':!![]});if(_0x4f8b71){if(_0x2c8fc6[_0xb088('0x35')][_0xb088('0x48')]){_0x2c8fc6[_0xb088('0x3e')][_0xb088('0x49')]({'id':0x0,'priority':_0x2c8fc6[_0xb088('0x3e')][_0xb088('0x42')]+0x1,'app':_0xb088('0x4a'),'appdata':'unmanaged','interval':_0xb088('0x4b')});}_0x38fa5c[_0xb088('0x4c')]=!![];}else{_0x38fa5c['created']=![];}_0x2c8fc6[_0xb088('0x4d')]=_0x38fa5c;return db['FaxMessage'][_0xb088('0x44')]({'body':_0x4c6171[_0xb088('0x2b')]['body'],'FaxAccountId':_0x4c6171[_0xb088('0x35')]['id'],'FaxInteractionId':_0x39d0dc['id'],'direction':'in','ContactId':_0x39d0dc[_0xb088('0x4e')],'AttachmentId':_0x4c6171[_0xb088('0x2b')][_0xb088('0x4f')]});})['then'](function(_0x119c82){_0x2c8fc6[_0xb088('0x18')]=_0x119c82;if(!_0x2c8fc6[_0xb088('0x4d')][_0xb088('0x50')])return;return db[_0xb088('0x51')][_0xb088('0x34')]({'attributes':['id',_0xb088('0x52')],'where':{'id':_0x2c8fc6[_0xb088('0x4d')][_0xb088('0x50')]}});})[_0xb088('0x10')](function(_0x5594a7){if(_0x5594a7){_0x2c8fc6[_0xb088('0x3e')][_0xb088('0x53')]({'id':0x0,'priority':0x0,'app':_0xb088('0x54'),'appdata':_0x5594a7[_0xb088('0x52')]+','+(_0x2c8fc6['account']['waitForTheAssignedAgent']||0xa),'interval':_0xb088('0x4b')});}if(!_0x2c8fc6[_0xb088('0x4d')][_0xb088('0x55')])return;return db[_0xb088('0x56')][_0xb088('0x34')]({'attributes':['id','name'],'where':{'id':_0x2c8fc6[_0xb088('0x4d')][_0xb088('0x55')]}});})['then'](function(_0x2f7458){if(_0x2f7458){_0x2c8fc6[_0xb088('0x3e')][_0xb088('0x53')]({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x2f7458[_0xb088('0x52')]+','+(_0x2c8fc6['account']['waitForTheAssignedQueue']||0x12c),'interval':_0xb088('0x4b')});}return respondWithRpcPromise('Start',_0xb088('0x57'),_0x2c8fc6);})[_0xb088('0x10')](function(_0x184b08){_0x2e344d(_0x184b08);})[_0xb088('0x21')](function(_0x4351b2){_0x3e76c7(_0x4447f2[_0xb088('0x17')](0x1f4,_0x4351b2[_0xb088('0x18')]));});});};