Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / cmContact / cmContact.model.js
index 3f28c6a..6d3c934 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9e11=['../../config/logger','api','moment','bluebird','path','rimraf','../../config/environment','./cmContact.attributes','exports','define','CmContact','cm_contacts','phone','fti_cm_contacts','lastName','mobile','fax','email','FULLTEXT','error','cmContact','afterCreate','inspect','scheduledat','format','YYYY-MM-DD\x20HH:mm:ss','isNil','dialTimezone','VoiceQueue','findOne','then','utcOffset','add','minutes','ret','cmContact,\x20afterCreate\x20','CmHopper','create','ListId','priority','callbackUniqueid','\x20contact\x20not\x20insert\x20in\x20hopper,\x20check\x20duplicate\x20always,\x20exist\x20in\x20hopper\x20VoiceQueue\x20','CmHopperFinal','\x20contact\x20not\x20insert\x20in\x20hopper,\x20check\x20duplicate\x20always,\x20exist\x20in\x20hopperFinal\x20VoiceQueue\x20','catch','Campaign','\x20contact\x20not\x20insert\x20in\x20hopper,\x20check\x20duplicate\x20onlyIfOpen,\x20exist\x20in\x20hopper\x20Campaign\x20','cmContact,\x20afterCreate,\x20','findAll','dialCheckDuplicateType','length','get','onlyIfOpen','BlackLists','message','CmList','Lists','always','CmHopperBlack','cmContact,\x20%s,\x20%s','List\x20not\x20found','models','isEmpty','VoiceQueueId','CampaignId','push','all','info','[CmContact][afterDestroy][Error]','lodash'];(function(_0x2e2681,_0x4089c1){var _0x368a64=function(_0x267262){while(--_0x267262){_0x2e2681['push'](_0x2e2681['shift']());}};_0x368a64(++_0x4089c1);}(_0x9e11,0x15d));var _0x19e1=function(_0x17303c,_0x274419){_0x17303c=_0x17303c-0x0;var _0x296266=_0x9e11[_0x17303c];return _0x296266;};'use strict';var _=require(_0x19e1('0x0'));var util=require('util');var logger=require(_0x19e1('0x1'))(_0x19e1('0x2'));var moment=require(_0x19e1('0x3'));var BPromise=require(_0x19e1('0x4'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x19e1('0x5'));var rimraf=require(_0x19e1('0x6'));var config=require(_0x19e1('0x7'));var shared=require('../../config/environment/shared');var attributes=require(_0x19e1('0x8'));module[_0x19e1('0x9')]=function(_0x3d9996,_0x4aae03){return _0x3d9996[_0x19e1('0xa')](_0x19e1('0xb'),attributes,{'tableName':_0x19e1('0xc'),'paranoid':!![],'indexes':[{'name':_0x19e1('0xd'),'fields':[_0x19e1('0xd')]},{'name':_0x19e1('0xe'),'fields':['firstName',_0x19e1('0xf'),_0x19e1('0xd'),_0x19e1('0x10'),_0x19e1('0x11'),_0x19e1('0x12')],'type':_0x19e1('0x13')}],'timestamps':!![],'charset':'utf8mb4','collate':'utf8mb4_unicode_ci','hooks':{'afterCreate':function(_0x32c8fb,_0x3414a3,_0x2dd1d1){var _0x160e9f=_0x3d9996['models'];var _0x33bb7f=_0x32c8fb['get']({'plain':!![]});function _0x3749fc(){return function(_0x221de7){logger[_0x19e1('0x14')](_0x19e1('0x15'),_0x19e1('0x16'),util[_0x19e1('0x17')](_0x221de7,{'showHidden':![],'depth':null}));};}function _0x353da5(_0x2caaea,_0x2eb132){var _0x10b210=_0x2eb132[_0x19e1('0x18')]?_0x2eb132[_0x19e1('0x18')]:moment()[_0x19e1('0x19')](_0x19e1('0x1a'));return new BPromise(function(_0x53c2c9,_0x9f3a74){if(_[_0x19e1('0x1b')](_0x2eb132[_0x19e1('0x1c')])){_0x53c2c9({'ret':_0x10b210});}else{_0x160e9f[_0x19e1('0x1d')][_0x19e1('0x1e')]({'where':{'id':_0x2caaea['id']}})[_0x19e1('0x1f')](function(_0x4a83ca){if(!_[_0x19e1('0x1b')](_0x4a83ca)){var _0x2b17eb=_0x4a83ca[_0x19e1('0x1c')];if(!_['isNil'](_0x2b17eb)){var _0x18a5e1=shared['timezones'];var _0x23e754=_0x18a5e1[_0x2b17eb];var _0xa811e7=_0x18a5e1[_0x2eb132[_0x19e1('0x1c')]];if(!_[_0x19e1('0x1b')](_0x23e754)&&!_[_0x19e1('0x1b')](_0xa811e7)){var _0x2c8bf4=_0x23e754['utcOffset']-_0xa811e7[_0x19e1('0x20')];_0x10b210=_0x2eb132[_0x19e1('0x18')]?_0x2eb132[_0x19e1('0x18')]:moment();var _0x44b950=moment(_0x10b210)[_0x19e1('0x21')](_0x2c8bf4,_0x19e1('0x22'));_0x53c2c9({'ret':_0x44b950[_0x19e1('0x19')](_0x19e1('0x1a'))});}else _0x53c2c9({'ret':_0x10b210});}else _0x53c2c9({'ret':_0x10b210});}else{_0x53c2c9({'ret':_0x10b210});}});}});return 0xa;}var _0x3c00e9=function(_0x19d92f){return new BPromise(function(_0x318320,_0x1a3da4){_0x353da5(_0x19d92f,_0x33bb7f)[_0x19e1('0x1f')](function(_0x8fe95d){_0x33bb7f['scheduledat']=_0x8fe95d[_0x19e1('0x23')];_0x160e9f['CmHopper']['findOne']({'where':{'phone':_0x33bb7f[_0x19e1('0xd')],'VoiceQueueId':_0x19d92f['id']}})['then'](function(_0x3e23e2){if(!_[_0x19e1('0x1b')](_0x3e23e2)){throw new Error(_0x19e1('0x24')+_0x33bb7f['phone']+'\x20contact\x20not\x20insert\x20in\x20hopper,\x20check\x20duplicate\x20onlyIfOpen,\x20exist\x20in\x20hopper\x20VoiceQueue\x20'+_0x19d92f['id']);}return _0x160e9f[_0x19e1('0x25')][_0x19e1('0x26')]({'phone':_0x33bb7f['phone'],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f[_0x19e1('0x27')],'priority':_0x33bb7f[_0x19e1('0x28')]?_0x33bb7f[_0x19e1('0x28')]:0x2,'scheduledat':_0x33bb7f[_0x19e1('0x18')]?_0x33bb7f[_0x19e1('0x18')]:moment()[_0x19e1('0x19')](_0x19e1('0x1a')),'callback':_0x33bb7f['callbackUniqueid']?!![]:![],'callbackuniqueid':_0x33bb7f[_0x19e1('0x29')]?_0x33bb7f[_0x19e1('0x29')]:undefined,'callbackat':_0x33bb7f[_0x19e1('0x29')]?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined,'VoiceQueueId':_0x19d92f['id']});})['catch'](function(_0x2e6156){_0x1a3da4(_0x2e6156);});});});};var _0x311352=function(_0x2bb02e){return new BPromise(function(_0x5df06a,_0x557c4e){_0x353da5(_0x2bb02e,_0x33bb7f)['then'](function(_0x553e98){_0x33bb7f[_0x19e1('0x18')]=_0x553e98[_0x19e1('0x23')];_0x160e9f[_0x19e1('0x25')][_0x19e1('0x1e')]({'where':{'phone':_0x33bb7f[_0x19e1('0xd')],'VoiceQueueId':_0x2bb02e['id']}})[_0x19e1('0x1f')](function(_0x1b6194){if(!_[_0x19e1('0x1b')](_0x1b6194)){throw new Error(_0x19e1('0x24')+_0x33bb7f[_0x19e1('0xd')]+_0x19e1('0x2a')+_0x2bb02e['id']);}return _0x160e9f[_0x19e1('0x2b')]['findOne']({'where':{'calleridnum':_0x33bb7f[_0x19e1('0xd')],'VoiceQueueId':_0x2bb02e['id']}});})['then'](function(_0x15bf5e){if(!_[_0x19e1('0x1b')](_0x15bf5e)){throw new Error('cmContact,\x20afterCreate,\x20'+_0x33bb7f[_0x19e1('0xd')]+_0x19e1('0x2c')+_0x2bb02e['id']);}return _0x160e9f[_0x19e1('0x25')][_0x19e1('0x26')]({'phone':_0x33bb7f[_0x19e1('0xd')],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f['ListId'],'priority':_0x33bb7f[_0x19e1('0x28')]?_0x33bb7f[_0x19e1('0x28')]:0x2,'scheduledat':_0x33bb7f[_0x19e1('0x18')]?_0x33bb7f[_0x19e1('0x18')]:moment()['format'](_0x19e1('0x1a')),'callback':_0x33bb7f[_0x19e1('0x29')]?!![]:![],'callbackuniqueid':_0x33bb7f[_0x19e1('0x29')]?_0x33bb7f[_0x19e1('0x29')]:undefined,'callbackat':_0x33bb7f[_0x19e1('0x29')]?moment()[_0x19e1('0x19')](_0x19e1('0x1a')):undefined,'VoiceQueueId':_0x2bb02e['id']});})[_0x19e1('0x2d')](function(_0x8010db){_0x557c4e(_0x8010db);});});});};function _0x151810(){return function(_0x3bbbe9){logger[_0x19e1('0x14')](_0x19e1('0x15'),_0x19e1('0x16'),util[_0x19e1('0x17')](_0x3bbbe9,{'showHidden':![],'depth':null}));};}function _0x119d6a(_0x1483b0,_0x4d08a2){var _0x2d70e2=_0x4d08a2[_0x19e1('0x18')]?_0x4d08a2[_0x19e1('0x18')]:moment()[_0x19e1('0x19')](_0x19e1('0x1a'));return new BPromise(function(_0x7f6347,_0xdacb0){if(_[_0x19e1('0x1b')](_0x4d08a2[_0x19e1('0x1c')])){_0x7f6347({'ret':_0x2d70e2});}else{_0x160e9f[_0x19e1('0x2e')]['findOne']({'where':{'id':_0x1483b0['id']}})[_0x19e1('0x1f')](function(_0x42f396){if(!_[_0x19e1('0x1b')](_0x42f396)){var _0x3360b4=_0x42f396[_0x19e1('0x1c')];if(!_['isNil'](_0x3360b4)){var _0x22dcc7=shared['timezones'];var _0x4566b8=_0x22dcc7[_0x3360b4];var _0x40339d=_0x22dcc7[_0x4d08a2[_0x19e1('0x1c')]];if(!_['isNil'](_0x4566b8)&&!_[_0x19e1('0x1b')](_0x40339d)){var _0x47b7aa=_0x4566b8[_0x19e1('0x20')]-_0x40339d[_0x19e1('0x20')];_0x2d70e2=_0x4d08a2[_0x19e1('0x18')]?_0x4d08a2[_0x19e1('0x18')]:moment();var _0x5c32a2=moment(_0x2d70e2)[_0x19e1('0x21')](_0x47b7aa,_0x19e1('0x22'));_0x7f6347({'ret':_0x5c32a2[_0x19e1('0x19')](_0x19e1('0x1a'))});}else _0x7f6347({'ret':_0x2d70e2});}else _0x7f6347({'ret':_0x2d70e2});}else{_0x7f6347({'ret':_0x2d70e2});}});}});return 0xa;}var _0x1ae098=function(_0x391e1a){return new BPromise(function(_0x3c38c7,_0x352fbd){_0x119d6a(_0x391e1a,_0x33bb7f)[_0x19e1('0x1f')](function(_0x53b060){_0x33bb7f[_0x19e1('0x18')]=_0x53b060[_0x19e1('0x23')];_0x160e9f['CmHopper'][_0x19e1('0x1e')]({'where':{'phone':_0x33bb7f[_0x19e1('0xd')],'CampaignId':_0x391e1a['id']}})[_0x19e1('0x1f')](function(_0x43a75e){if(!_[_0x19e1('0x1b')](_0x43a75e)){throw new Error(_0x19e1('0x24')+_0x33bb7f[_0x19e1('0xd')]+_0x19e1('0x2f')+_0x391e1a['id']);}return _0x160e9f['CmHopper'][_0x19e1('0x26')]({'phone':_0x33bb7f[_0x19e1('0xd')],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f[_0x19e1('0x27')],'priority':_0x33bb7f[_0x19e1('0x28')]?_0x33bb7f[_0x19e1('0x28')]:0x2,'scheduledat':_0x33bb7f[_0x19e1('0x18')]?_0x33bb7f[_0x19e1('0x18')]:moment()['format'](_0x19e1('0x1a')),'callback':_0x33bb7f[_0x19e1('0x29')]?!![]:![],'callbackuniqueid':_0x33bb7f[_0x19e1('0x29')]?_0x33bb7f[_0x19e1('0x29')]:undefined,'callbackat':_0x33bb7f[_0x19e1('0x29')]?moment()[_0x19e1('0x19')](_0x19e1('0x1a')):undefined,'CampaignId':_0x391e1a['id']});})[_0x19e1('0x2d')](function(_0x1267ff){_0x352fbd(_0x1267ff);});});});};var _0x318298=function(_0x528c4a){return new BPromise(function(_0x294474,_0x2389bd){_0x119d6a(_0x528c4a,_0x33bb7f)[_0x19e1('0x1f')](function(_0x111f35){_0x33bb7f['scheduledat']=_0x111f35[_0x19e1('0x23')];_0x160e9f['CmHopper'][_0x19e1('0x1e')]({'where':{'phone':_0x33bb7f[_0x19e1('0xd')],'CampaignId':_0x528c4a['id']}})[_0x19e1('0x1f')](function(_0xe35550){if(!_['isNil'](_0xe35550)){throw new Error(_0x19e1('0x24')+_0x33bb7f[_0x19e1('0xd')]+'\x20contact\x20not\x20insert\x20in\x20hopper,\x20check\x20duplicate\x20always,\x20exist\x20in\x20hopper\x20Campaign\x20'+_0x528c4a['id']);}return _0x160e9f[_0x19e1('0x2b')][_0x19e1('0x1e')]({'where':{'calleridnum':_0x33bb7f[_0x19e1('0xd')],'CampaignId':_0x528c4a['id']}});})['then'](function(_0x3b1ef1){if(!_[_0x19e1('0x1b')](_0x3b1ef1)){throw new Error(_0x19e1('0x30')+_0x33bb7f['phone']+'\x20contact\x20not\x20insert\x20in\x20hopper,\x20check\x20duplicate\x20always,\x20exist\x20in\x20hopperFinal\x20Campaign\x20'+_0x528c4a['id']);}return _0x160e9f[_0x19e1('0x25')][_0x19e1('0x26')]({'phone':_0x33bb7f[_0x19e1('0xd')],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f[_0x19e1('0x27')],'priority':_0x33bb7f[_0x19e1('0x28')]?_0x33bb7f['priority']:0x2,'scheduledat':_0x33bb7f['scheduledat']?_0x33bb7f[_0x19e1('0x18')]:moment()[_0x19e1('0x19')]('YYYY-MM-DD\x20HH:mm:ss'),'callback':_0x33bb7f[_0x19e1('0x29')]?!![]:![],'callbackuniqueid':_0x33bb7f['callbackUniqueid']?_0x33bb7f[_0x19e1('0x29')]:undefined,'callbackat':_0x33bb7f['callbackUniqueid']?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined,'CampaignId':_0x528c4a['id']});})[_0x19e1('0x2d')](function(_0x2ecd9e){_0x2389bd(_0x2ecd9e);});});});};if(_0x33bb7f[_0x19e1('0x27')]){_0x160e9f[_0x19e1('0x1d')][_0x19e1('0x31')]({'where':{'type':'outbound'},'attributes':['id',_0x19e1('0x32'),_0x19e1('0x1c')],'include':[{'model':_0x160e9f['CmList'],'as':'Lists','where':{'id':_0x33bb7f[_0x19e1('0x27')]}}]})['then'](function(_0x3d8dd3){if(_0x3d8dd3){var _0x58fe6c=[];for(var _0x50ea5c=0x0,_0x50793b;_0x50ea5c<_0x3d8dd3[_0x19e1('0x33')];_0x50ea5c+=0x1){_0x50793b=_0x3d8dd3[_0x50ea5c][_0x19e1('0x34')]({'plain':!![]});switch(_0x50793b['dialCheckDuplicateType']){case'always':_0x311352(_0x50793b)[_0x19e1('0x2d')](_0x3749fc());break;case _0x19e1('0x35'):_0x3c00e9(_0x50793b)[_0x19e1('0x2d')](_0x3749fc());break;default:_0x119d6a(_0x50793b,_0x33bb7f)[_0x19e1('0x1f')](function(_0x6eea2d){_0x33bb7f[_0x19e1('0x18')]=_0x6eea2d[_0x19e1('0x23')];_0x160e9f['CmHopper'][_0x19e1('0x26')]({'phone':_0x33bb7f['phone'],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f[_0x19e1('0x27')],'scheduledat':_0x33bb7f[_0x19e1('0x18')]?_0x33bb7f[_0x19e1('0x18')]:moment()[_0x19e1('0x19')](_0x19e1('0x1a')),'priority':_0x33bb7f[_0x19e1('0x28')]?_0x33bb7f[_0x19e1('0x28')]:0x2,'callback':_0x33bb7f[_0x19e1('0x29')]?!![]:![],'callbackuniqueid':_0x33bb7f[_0x19e1('0x29')]?_0x33bb7f[_0x19e1('0x29')]:undefined,'callbackat':_0x33bb7f[_0x19e1('0x29')]?moment()[_0x19e1('0x19')]('YYYY-MM-DD\x20HH:mm:ss'):undefined,'VoiceQueueId':_0x50793b['id']})[_0x19e1('0x2d')](_0x3749fc());});}}}})[_0x19e1('0x1f')](function(){return _0x160e9f['VoiceQueue'][_0x19e1('0x31')]({'where':{'type':'outbound'},'attributes':['id'],'include':[{'model':_0x160e9f['CmList'],'as':_0x19e1('0x36'),'where':{'id':_0x33bb7f[_0x19e1('0x27')]}}]})['then'](function(_0x42844f){if(_0x42844f){var _0x18598d=[];for(var _0x3295d5=0x0,_0x401021;_0x3295d5<_0x42844f[_0x19e1('0x33')];_0x3295d5+=0x1){_0x401021=_0x42844f[_0x3295d5][_0x19e1('0x34')]({'plain':!![]});_0x160e9f['CmHopperBlack'][_0x19e1('0x26')]({'phone':_0x33bb7f[_0x19e1('0xd')],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f[_0x19e1('0x27')],'VoiceQueueId':_0x401021['id']})[_0x19e1('0x2d')](function(_0x495c6f){logger[_0x19e1('0x14')]('cmContact,\x20%s,\x20%s',_0x19e1('0x16'),_0x495c6f[_0x19e1('0x37')]);});}}});})['then'](function(){return _0x160e9f[_0x19e1('0x2e')][_0x19e1('0x31')]({'attributes':['id','dialCheckDuplicateType',_0x19e1('0x1c')],'include':[{'model':_0x160e9f[_0x19e1('0x38')],'as':_0x19e1('0x39'),'where':{'id':_0x33bb7f[_0x19e1('0x27')]}}]})['then'](function(_0x3e9e6c){if(_0x3e9e6c){var _0x53706a=[];for(var _0x51d199=0x0,_0x547958;_0x51d199<_0x3e9e6c[_0x19e1('0x33')];_0x51d199+=0x1){_0x547958=_0x3e9e6c[_0x51d199]['get']({'plain':!![]});switch(_0x547958[_0x19e1('0x32')]){case _0x19e1('0x3a'):_0x318298(_0x547958)[_0x19e1('0x2d')](_0x151810());break;case _0x19e1('0x35'):_0x1ae098(_0x547958)[_0x19e1('0x2d')](_0x151810());break;default:_0x160e9f[_0x19e1('0x25')][_0x19e1('0x26')]({'phone':_0x33bb7f[_0x19e1('0xd')],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f['ListId'],'scheduledat':_0x33bb7f[_0x19e1('0x18')]?_0x33bb7f[_0x19e1('0x18')]:moment()[_0x19e1('0x19')](_0x19e1('0x1a')),'priority':_0x33bb7f['priority']?_0x33bb7f[_0x19e1('0x28')]:0x2,'callback':_0x33bb7f[_0x19e1('0x29')]?!![]:![],'callbackuniqueid':_0x33bb7f['callbackUniqueid']?_0x33bb7f[_0x19e1('0x29')]:undefined,'callbackat':_0x33bb7f[_0x19e1('0x29')]?moment()[_0x19e1('0x19')](_0x19e1('0x1a')):undefined,'CampaignId':_0x547958['id']})[_0x19e1('0x2d')](_0x151810());}}}});})[_0x19e1('0x1f')](function(){return _0x160e9f[_0x19e1('0x2e')][_0x19e1('0x31')]({'attributes':['id'],'include':[{'model':_0x160e9f['CmList'],'as':_0x19e1('0x36'),'where':{'id':_0x33bb7f[_0x19e1('0x27')]}}]})[_0x19e1('0x1f')](function(_0x5a6eb9){if(_0x5a6eb9){var _0x2fe3c5=[];for(var _0x4dcabe=0x0,_0x23f05;_0x4dcabe<_0x5a6eb9[_0x19e1('0x33')];_0x4dcabe+=0x1){_0x23f05=_0x5a6eb9[_0x4dcabe][_0x19e1('0x34')]({'plain':!![]});_0x160e9f[_0x19e1('0x3b')][_0x19e1('0x26')]({'phone':_0x33bb7f[_0x19e1('0xd')],'ContactId':_0x33bb7f['id'],'ListId':_0x33bb7f[_0x19e1('0x27')],'CampaignId':_0x23f05['id']})['catch'](function(_0x100404){logger['error']('cmContact,\x20%s,\x20%s',_0x19e1('0x16'),_0x100404[_0x19e1('0x37')]);});}}});})[_0x19e1('0x1f')](function(){_0x2dd1d1();})[_0x19e1('0x2d')](function(_0x1e5418){logger[_0x19e1('0x14')](_0x19e1('0x3c'),'afterCreate',_0x1e5418[_0x19e1('0x37')]);_0x2dd1d1(_0x1e5418);});}else{_0x2dd1d1(new Error(_0x19e1('0x3d')));}},'afterDestroy':function(_0x553f2b,_0x15430c,_0x210852){var _0x5c2504=_0x3d9996[_0x19e1('0x3e')];var _0x255bae=_0x553f2b[_0x19e1('0x34')]({'plain':!![]});return _0x5c2504[_0x19e1('0x25')][_0x19e1('0x31')]({'raw':!![],'where':{'ListId':_0x255bae[_0x19e1('0x27')],'ContactId':_0x255bae['id']}})[_0x19e1('0x1f')](function(_0x2f9b35){if(!_[_0x19e1('0x3f')](_0x2f9b35)){var _0x2cca95=[];for(var _0x5265c8=0x0;_0x5265c8<_0x2f9b35[_0x19e1('0x33')];_0x5265c8+=0x1){var _0x1b9c3d=_0x5c2504[_0x19e1('0x25')]['destroy']({'where':{'ListId':_0x2f9b35[_0x5265c8]['ListId'],'ContactId':_0x2f9b35[_0x5265c8]['ContactId'],'VoiceQueueId':_0x2f9b35[_0x5265c8][_0x19e1('0x40')],'CampaignId':_0x2f9b35[_0x5265c8][_0x19e1('0x41')]}});_0x2cca95[_0x19e1('0x42')](_0x1b9c3d);}return BPromise[_0x19e1('0x43')](_0x2cca95);}})['then'](function(_0x199c7d){logger[_0x19e1('0x44')]('[CmContact][afterDestroy][Succesfull]',util['inspect'](_0x199c7d,{'showHidden':![],'depth':null}));_0x210852();})[_0x19e1('0x2d')](function(_0x45936e){logger['error'](_0x19e1('0x45'),util['inspect'](_0x45936e,{'showHidden':![],'depth':null}));_0x210852(_0x45936e);});}}});};
\ No newline at end of file
+var _0xc17f=['util','moment','../../config/environment/shared','Campaign','VoiceQueue','scheduledat','format','isNil','dialTimezone','resolve','findOne','then','timezones','utcOffset','minutes','YYYY-MM-DD\x20HH:mm:ss','phone','ListId','priority','callbackUniqueid','assign','CmHopper','[Always]\x20Hopper\x20already\x20exists\x20for\x20contact\x20with\x20phone\x20','\x20in\x20Campaign\x20with\x20id\x20','[Always]\x20Hopper\x20Final\x20already\x20exists\x20for\x20contact\x20with\x20phone\x20','CampaignId','VoiceQueueId','create','[OnlyIfOpen]\x20Hopper\x20already\x20exists\x20for\x20contact\x20with\x20phone\x20','dialCheckDuplicateType','onlyIfOpen','outbound','CmList','map','Lists','all','findAll','CmHopperBlack','BlackLists','exports','cm_contacts','fti_cm_contacts','mobile','fax','utf8mb4','utf8mb4_unicode_ci','error','[cmContact][afterCreate]\x20List\x20not\x20found\x20for\x20contact\x20with\x20id\x20','catch','[cmContact][afterCreate]','message','get','isEmpty','length','destroy','info','[CmContact][afterDestroy][Succesfull]','inspect','[CmContact][afterDestroy][Error]'];(function(_0x53ccf2,_0x13cb67){var _0x5a2964=function(_0x3b0514){while(--_0x3b0514){_0x53ccf2['push'](_0x53ccf2['shift']());}};_0x5a2964(++_0x13cb67);}(_0xc17f,0x1d8));var _0xfc17=function(_0x258534,_0x586b54){_0x258534=_0x258534-0x0;var _0x37b893=_0xc17f[_0x258534];return _0x37b893;};'use strict';var _=require('lodash');var util=require(_0xfc17('0x0'));var logger=require('../../config/logger')('api');var moment=require(_0xfc17('0x1'));var shared=require(_0xfc17('0x2'));var attributes=require('./cmContact.attributes');function getTimezoneCallbackAt(_0x218bb7,_0x2ca557,_0x31a4dd,_0x1e6ff7){var _0x5c309d=_0x1e6ff7?_0xfc17('0x3'):_0xfc17('0x4');var _0x51b0c1=_0x31a4dd[_0xfc17('0x5')]?_0x31a4dd[_0xfc17('0x5')]:moment()[_0xfc17('0x6')]('YYYY-MM-DD\x20HH:mm:ss');if(_[_0xfc17('0x7')](_0x31a4dd[_0xfc17('0x8')])){return Promise[_0xfc17('0x9')](_0x51b0c1);}return _0x218bb7[_0x5c309d][_0xfc17('0xa')]({'where':{'id':_0x2ca557}})[_0xfc17('0xb')](function(_0x190a8c){if(_[_0xfc17('0x7')](_0x190a8c)||_[_0xfc17('0x7')](_0x190a8c[_0xfc17('0x8')])){return Promise[_0xfc17('0x9')](_0x51b0c1);}var _0x430e5a=shared[_0xfc17('0xc')];var _0x541b8a=_0x430e5a[_0x190a8c[_0xfc17('0x8')]];var _0x438b0a=_0x430e5a[_0x31a4dd[_0xfc17('0x8')]];if(_[_0xfc17('0x7')](_0x541b8a)&&_[_0xfc17('0x7')](_0x438b0a)){return Promise['resolve'](_0x51b0c1);}var _0x264d8f=_0x541b8a[_0xfc17('0xd')]-_0x438b0a[_0xfc17('0xd')];var _0x226ac6=_0x31a4dd[_0xfc17('0x5')]?_0x31a4dd[_0xfc17('0x5')]:moment();_0x51b0c1=moment(_0x226ac6)['add'](_0x264d8f,_0xfc17('0xe'))[_0xfc17('0x6')](_0xfc17('0xf'));return Promise[_0xfc17('0x9')](_0x51b0c1);});}function getNewHopperPayload(_0x5d4b5d){return{'phone':_0x5d4b5d[_0xfc17('0x10')],'ContactId':_0x5d4b5d['id'],'ListId':_0x5d4b5d[_0xfc17('0x11')],'scheduledat':_0x5d4b5d[_0xfc17('0x5')]?_0x5d4b5d[_0xfc17('0x5')]:moment()[_0xfc17('0x6')](_0xfc17('0xf')),'priority':_0x5d4b5d[_0xfc17('0x12')]?_0x5d4b5d[_0xfc17('0x12')]:0x2,'callback':_0x5d4b5d['callbackUniqueid']?!![]:![],'callbackuniqueid':_0x5d4b5d[_0xfc17('0x13')]?_0x5d4b5d[_0xfc17('0x13')]:undefined,'callbackat':_0x5d4b5d['callbackUniqueid']?moment()['format'](_0xfc17('0xf')):undefined};}function handleAlwaysCheckDuplicate(_0x140adc,_0x54253f,_0x2b304,_0x741623){var _0xa43f01={'phone':_0x2b304[_0xfc17('0x10')]};var _0x278d52={'calleridnum':_0x2b304[_0xfc17('0x10')]};if(_0x741623){Object[_0xfc17('0x14')](_0xa43f01,{'CampaignId':_0x54253f['id']});Object[_0xfc17('0x14')](_0x278d52,{'CampaignId':_0x54253f['id']});}else{Object['assign'](_0xa43f01,{'VoiceQueueId':_0x54253f['id']});Object[_0xfc17('0x14')](_0x278d52,{'VoiceQueueId':_0x54253f['id']});}return _0x140adc[_0xfc17('0x15')][_0xfc17('0xa')]({'where':_0xa43f01})[_0xfc17('0xb')](function(_0x340361){if(_0x340361){throw new Error(_0xfc17('0x16')+_0x2b304[_0xfc17('0x10')]+_0xfc17('0x17')+_0x54253f['id']);}return _0x140adc['CmHopperFinal'][_0xfc17('0xa')]({'where':_0x278d52});})[_0xfc17('0xb')](function(_0x658ed2){if(_0x658ed2){throw new Error(_0xfc17('0x18')+_0x2b304[_0xfc17('0x10')]+_0xfc17('0x17')+_0x54253f['id']);}var _0x2568da=getNewHopperPayload(_0x2b304);if(_0x741623){_0x2568da[_0xfc17('0x19')]=_0x54253f['id'];}else{_0x2568da[_0xfc17('0x1a')]=_0x54253f['id'];}return _0x140adc[_0xfc17('0x15')][_0xfc17('0x1b')](_0x2568da);});}function handleOnlyIfOpenCheckDuplicate(_0x33016e,_0x301f00,_0x216a01,_0x311fad){var _0xf87eb5={'phone':_0x216a01[_0xfc17('0x10')]};if(_0x311fad){Object['assign'](_0xf87eb5,{'CampaignId':_0x301f00['id']});}else{Object[_0xfc17('0x14')](_0xf87eb5,{'VoiceQueueId':_0x301f00['id']});}return _0x33016e['CmHopper'][_0xfc17('0xa')]({'where':_0xf87eb5})[_0xfc17('0xb')](function(_0x545ff7){if(_0x545ff7){throw new Error(_0xfc17('0x1c')+_0x216a01[_0xfc17('0x10')]+_0xfc17('0x17')+_0x301f00['id']);}var _0x41b6e7=getNewHopperPayload(_0x216a01);if(_0x311fad){_0x41b6e7[_0xfc17('0x19')]=_0x301f00['id'];}else{_0x41b6e7[_0xfc17('0x1a')]=_0x301f00['id'];}return _0x33016e[_0xfc17('0x15')][_0xfc17('0x1b')](_0x41b6e7);});}function handleNeverCheckDuplicate(_0xdfdce5,_0x4197b7,_0x558358){var _0x443cfb=getNewHopperPayload(_0x558358);_0x443cfb[_0xfc17('0x1a')]=_0x4197b7['id'];return _0xdfdce5[_0xfc17('0x15')][_0xfc17('0x1b')](_0x443cfb);}function handleCheckDuplicate(_0x2effb9,_0x58864e,_0x131def,_0x27ce61){return getTimezoneCallbackAt(_0x2effb9,_0x58864e,_0x131def,_0x27ce61)[_0xfc17('0xb')](function(_0x22c038){_0x131def[_0xfc17('0x5')]=_0x22c038;switch(_0x58864e[_0xfc17('0x1d')]){case'always':return handleAlwaysCheckDuplicate(_0x2effb9,_0x58864e,_0x131def,_0x27ce61);case _0xfc17('0x1e'):return handleOnlyIfOpenCheckDuplicate(_0x2effb9,_0x58864e,_0x131def,_0x27ce61);default:return handleNeverCheckDuplicate(_0x2effb9,_0x58864e,_0x131def);}});}function createHopperForVoiceQueues(_0x363a0b,_0x457d71){return _0x363a0b[_0xfc17('0x4')]['findAll']({'where':{'type':_0xfc17('0x1f')},'attributes':['id',_0xfc17('0x1d'),_0xfc17('0x8')],'include':[{'model':_0x363a0b[_0xfc17('0x20')],'as':'Lists','where':{'id':_0x457d71[_0xfc17('0x11')]}}],'raw':!![]})['then'](function(_0x316ca6){var _0x1af927=_0x316ca6[_0xfc17('0x21')](function(_0x48221e){return handleCheckDuplicate(_0x363a0b,_0x48221e,_0x457d71,![]);});return Promise['all'](_0x1af927);});}function createHopperForCampaigns(_0x22b070,_0x1614fe){return _0x22b070[_0xfc17('0x3')]['findAll']({'attributes':['id',_0xfc17('0x1d'),'dialTimezone'],'include':[{'model':_0x22b070['CmList'],'as':_0xfc17('0x22'),'where':{'id':_0x1614fe['ListId']}}],'raw':!![]})[_0xfc17('0xb')](function(_0x5511d2){var _0x29426e=_0x5511d2['map'](function(_0x2b846d){return handleCheckDuplicate(_0x22b070,_0x2b846d,_0x1614fe,!![]);});return Promise[_0xfc17('0x23')](_0x29426e);});}function createHopperBlackForVoiceQueues(_0x26eb02,_0x35d484){return _0x26eb02[_0xfc17('0x4')][_0xfc17('0x24')]({'where':{'type':_0xfc17('0x1f')},'attributes':['id'],'include':[{'model':_0x26eb02[_0xfc17('0x20')],'as':'BlackLists','where':{'id':_0x35d484[_0xfc17('0x11')]}}],'raw':!![]})['then'](function(_0x2912a9){var _0x125027=_0x2912a9[_0xfc17('0x21')](function(_0xeb5d07){return _0x26eb02[_0xfc17('0x25')][_0xfc17('0x1b')]({'phone':_0x35d484[_0xfc17('0x10')],'ContactId':_0x35d484['id'],'ListId':_0x35d484[_0xfc17('0x11')],'VoiceQueueId':_0xeb5d07['id']});});return Promise[_0xfc17('0x23')](_0x125027);});}function createHopperBlackForCampaigns(_0x2ab9a0,_0x2b9810){return _0x2ab9a0[_0xfc17('0x3')][_0xfc17('0x24')]({'attributes':['id'],'include':[{'model':_0x2ab9a0[_0xfc17('0x20')],'as':_0xfc17('0x26'),'where':{'id':_0x2b9810[_0xfc17('0x11')]}}],'raw':!![]})[_0xfc17('0xb')](function(_0xeeefc9){var _0x4acd39=_0xeeefc9[_0xfc17('0x21')](function(_0x59f3ec){return _0x2ab9a0[_0xfc17('0x25')][_0xfc17('0x1b')]({'phone':_0x2b9810['phone'],'ContactId':_0x2b9810['id'],'ListId':_0x2b9810[_0xfc17('0x11')],'CampaignId':_0x59f3ec['id']});});return Promise['all'](_0x4acd39);});}module[_0xfc17('0x27')]=function(_0x1567cf){return _0x1567cf['define']('CmContact',attributes,{'tableName':_0xfc17('0x28'),'paranoid':!![],'indexes':[{'name':'phone','fields':[_0xfc17('0x10')]},{'name':_0xfc17('0x29'),'fields':['firstName','lastName',_0xfc17('0x10'),_0xfc17('0x2a'),_0xfc17('0x2b'),'email'],'type':'FULLTEXT'}],'timestamps':!![],'charset':_0xfc17('0x2c'),'collate':_0xfc17('0x2d'),'hooks':{'afterCreate':function(_0x40b8e7,_0x287477,_0xdd4cfe){var _0x1be5ed=_0x1567cf['models'];var _0x55cc0e=_0x40b8e7['get']({'plain':!![]});if(!_0x55cc0e[_0xfc17('0x11')]){logger[_0xfc17('0x2e')](_0xfc17('0x2f')+_0x55cc0e['id']);return _0xdd4cfe();}if(!_0x55cc0e[_0xfc17('0x10')]){return _0xdd4cfe();}return createHopperForVoiceQueues(_0x1be5ed,_0x55cc0e)['then'](function(){return createHopperBlackForVoiceQueues(_0x1be5ed,_0x55cc0e);})[_0xfc17('0xb')](function(){return createHopperForCampaigns(_0x1be5ed,_0x55cc0e);})[_0xfc17('0xb')](function(){return createHopperBlackForCampaigns(_0x1be5ed,_0x55cc0e);})[_0xfc17('0xb')](function(){return _0xdd4cfe();})[_0xfc17('0x30')](function(_0x46e2f5){logger[_0xfc17('0x2e')](_0xfc17('0x31'),_0x46e2f5[_0xfc17('0x32')]);_0xdd4cfe();});},'afterDestroy':function(_0x2aab2c,_0xe8a39e,_0x3f0bea){var _0x494c65=_0x1567cf['models'];var _0x50cff6=_0x2aab2c[_0xfc17('0x33')]({'plain':!![]});return _0x494c65[_0xfc17('0x15')][_0xfc17('0x24')]({'raw':!![],'where':{'ListId':_0x50cff6[_0xfc17('0x11')],'ContactId':_0x50cff6['id']}})[_0xfc17('0xb')](function(_0x2660aa){if(!_[_0xfc17('0x34')](_0x2660aa)){var _0xbeacae=[];for(var _0xe38936=0x0;_0xe38936<_0x2660aa[_0xfc17('0x35')];_0xe38936+=0x1){var _0xf22f06=_0x494c65[_0xfc17('0x15')][_0xfc17('0x36')]({'where':{'ListId':_0x2660aa[_0xe38936]['ListId'],'ContactId':_0x2660aa[_0xe38936]['ContactId'],'VoiceQueueId':_0x2660aa[_0xe38936][_0xfc17('0x1a')],'CampaignId':_0x2660aa[_0xe38936][_0xfc17('0x19')]}});_0xbeacae['push'](_0xf22f06);}return Promise[_0xfc17('0x23')](_0xbeacae);}})[_0xfc17('0xb')](function(_0x3149e2){logger[_0xfc17('0x37')](_0xfc17('0x38'),util[_0xfc17('0x39')](_0x3149e2,{'showHidden':![],'depth':null}));_0x3f0bea();})['catch'](function(_0x27e283){logger[_0xfc17('0x2e')](_0xfc17('0x3a'),util[_0xfc17('0x39')](_0x27e283,{'showHidden':![],'depth':null}));_0x3f0bea(_0x27e283);});}}});};
\ No newline at end of file