6a4918cebaad927bebfea5e662f136fba90b337e
[motion2.git] / server / api / campaign / campaign.controller.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 _0xf2f3=['autoAssociation','params','omit','createdAt','updatedAt','Unable\x20to\x20retrieve\x20the\x20current\x20user','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','getHoppers','findOne','CmHopper','getHopperHistories','CmHopperHistory','CampaignId','CmHopperFinal','getHopperBlacks','CmHopperBlack','getLists','format','addLists','ids','dialCheckDuplicateType','always','insert','into','cm_hopper','phone','ContactId','select','field','ListId','toString','from','cm_contacts','deletedAt\x20IS\x20NULL','CmListId','phone\x20NOT\x20IN\x20(?)','COALESCE(calleridnum,\x27\x27)','cm_hopper_final','COALESCE(phone,\x27\x27)','CampaignId\x20=\x20?','onlyIfOpen','ListId\x20=\x20?','phone\x20IS\x20NOT\x20NULL','scheduledAt','cm_hopper_additional_phones','fromQuery','cmHopperId','OrderBy','NOW()','cm_contact_has_items','join','h.ListId\x20=\x20?','h.CampaignId=?','h.createdAt\x20=\x20?','push','sequelize','removeLists','CmList','getBlackLists','addBlackLists','spread','removeBlackLists','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','status','end','json','offset','limit','undefined','count','set','apply','reject','save','then','destroy','get','UserProfileResource','sendStatus','stack','name','send','index','map','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','merge','filter','options','Campaign','include','findAll','rows','keys','length','includeAll','find','catch','create','body','role','user','IvrCampaigns','userProfileId'];(function(_0x2ff837,_0x4d4f3b){var _0x100be3=function(_0x4c7d54){while(--_0x4c7d54){_0x2ff837['push'](_0x2ff837['shift']());}};_0x100be3(++_0x4d4f3b);}(_0xf2f3,0x15d));var _0x3f2f=function(_0x4199d9,_0x1e865b){_0x4199d9=_0x4199d9-0x0;var _0x4efa8e=_0xf2f3[_0x4199d9];return _0x4efa8e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3f2f('0x0'));var zipdir=require(_0x3f2f('0x1'));var jsonpatch=require(_0x3f2f('0x2'));var rp=require('request-promise');var moment=require(_0x3f2f('0x3'));var BPromise=require(_0x3f2f('0x4'));var Mustache=require(_0x3f2f('0x5'));var util=require('util');var path=require('path');var sox=require(_0x3f2f('0x6'));var csv=require(_0x3f2f('0x7'));var ejs=require(_0x3f2f('0x8'));var fs=require('fs');var fs_extra=require(_0x3f2f('0x9'));var _=require(_0x3f2f('0xa'));var squel=require(_0x3f2f('0xb'));var crypto=require(_0x3f2f('0xc'));var jsforce=require(_0x3f2f('0xd'));var deskjs=require(_0x3f2f('0xe'));var toCsv=require(_0x3f2f('0x7'));var querystring=require(_0x3f2f('0xf'));var Papa=require(_0x3f2f('0x10'));var Redis=require(_0x3f2f('0x11'));var authService=require(_0x3f2f('0x12'));var qs=require(_0x3f2f('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x3f2f('0x14'));var logger=require(_0x3f2f('0x15'))(_0x3f2f('0x16'));var utils=require('../../config/utils');var config=require(_0x3f2f('0x17'));var licenseUtil=require(_0x3f2f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x52feb7,_0x26cdf7){_0x26cdf7=_0x26cdf7||0xcc;return function(_0x4f4c81){if(_0x4f4c81){return _0x52feb7['sendStatus'](_0x26cdf7);}return _0x52feb7[_0x3f2f('0x19')](_0x26cdf7)[_0x3f2f('0x1a')]();};}function respondWithResult(_0x3fd307,_0x55e319){_0x55e319=_0x55e319||0xc8;return function(_0x47e978){if(_0x47e978){return _0x3fd307[_0x3f2f('0x19')](_0x55e319)[_0x3f2f('0x1b')](_0x47e978);}};}function respondWithFilteredResult(_0x1ef904,_0xa2c47f){return function(_0x367927){if(_0x367927){var _0x3556ae=typeof _0xa2c47f[_0x3f2f('0x1c')]==='undefined'&&typeof _0xa2c47f[_0x3f2f('0x1d')]===_0x3f2f('0x1e');var _0x32ac1c=_0x367927[_0x3f2f('0x1f')];var _0x34813b=_0x3556ae?0x0:_0xa2c47f[_0x3f2f('0x1c')];var _0xb1602f=_0x3556ae?_0x367927['count']:_0xa2c47f[_0x3f2f('0x1c')]+_0xa2c47f[_0x3f2f('0x1d')];var _0x286d84;if(_0xb1602f>=_0x32ac1c){_0xb1602f=_0x32ac1c;_0x286d84=0xc8;}else{_0x286d84=0xce;}_0x1ef904['status'](_0x286d84);return _0x1ef904[_0x3f2f('0x20')]('Content-Range',_0x34813b+'-'+_0xb1602f+'/'+_0x32ac1c)[_0x3f2f('0x1b')](_0x367927);}return null;};}function patchUpdates(_0x28a669){return function(_0x3e39b9){try{jsonpatch[_0x3f2f('0x21')](_0x3e39b9,_0x28a669,!![]);}catch(_0x1c6840){return BPromise[_0x3f2f('0x22')](_0x1c6840);}return _0x3e39b9[_0x3f2f('0x23')]();};}function saveUpdates(_0x4b6773,_0xa6488d){return function(_0x38abf5){if(_0x38abf5){return _0x38abf5['update'](_0x4b6773)[_0x3f2f('0x24')](function(_0x181226){return _0x181226;});}return null;};}function removeEntity(_0x40920e,_0x260dda){return function(_0x4661cc){if(_0x4661cc){return _0x4661cc[_0x3f2f('0x25')]()[_0x3f2f('0x24')](function(){var _0x4aea5f=_0x4661cc[_0x3f2f('0x26')]({'plain':!![]});var _0x443024='IvrCampaigns';return db[_0x3f2f('0x27')][_0x3f2f('0x25')]({'where':{'type':_0x443024,'resourceId':_0x4aea5f['id']}})[_0x3f2f('0x24')](function(){return _0x4661cc;});})['then'](function(){_0x40920e[_0x3f2f('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5f1870,_0x29dc27){return function(_0x3bcc4f){if(!_0x3bcc4f){_0x5f1870[_0x3f2f('0x28')](0x194);}return _0x3bcc4f;};}function handleError(_0x195c0d,_0x304cce){_0x304cce=_0x304cce||0x1f4;return function(_0x57d989){logger['error'](_0x57d989[_0x3f2f('0x29')]);if(_0x57d989[_0x3f2f('0x2a')]){delete _0x57d989[_0x3f2f('0x2a')];}_0x195c0d[_0x3f2f('0x19')](_0x304cce)[_0x3f2f('0x2b')](_0x57d989);};}exports[_0x3f2f('0x2c')]=function(_0x2916fa,_0x2fde83){var _0x544b4b={},_0x5c0adb={},_0x2696d6={'count':0x0,'rows':[]};var _0x4420c0=_[_0x3f2f('0x2d')](db['Campaign'][_0x3f2f('0x2e')],function(_0x3b01ab){return{'name':_0x3b01ab[_0x3f2f('0x2f')],'type':_0x3b01ab[_0x3f2f('0x30')][_0x3f2f('0x31')]};});_0x5c0adb['model']=_[_0x3f2f('0x2d')](_0x4420c0,_0x3f2f('0x2a'));_0x5c0adb['query']=_['keys'](_0x2916fa[_0x3f2f('0x32')]);_0x5c0adb[_0x3f2f('0x33')]=_[_0x3f2f('0x34')](_0x5c0adb[_0x3f2f('0x35')],_0x5c0adb[_0x3f2f('0x32')]);_0x544b4b[_0x3f2f('0x36')]=_['intersection'](_0x5c0adb[_0x3f2f('0x35')],qs[_0x3f2f('0x37')](_0x2916fa[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x544b4b['attributes']=_0x544b4b[_0x3f2f('0x36')]['length']?_0x544b4b['attributes']:_0x5c0adb[_0x3f2f('0x35')];if(!_0x2916fa[_0x3f2f('0x32')][_0x3f2f('0x38')](_0x3f2f('0x39'))){_0x544b4b['limit']=qs[_0x3f2f('0x1d')](_0x2916fa[_0x3f2f('0x32')][_0x3f2f('0x1d')]);_0x544b4b[_0x3f2f('0x1c')]=qs[_0x3f2f('0x1c')](_0x2916fa[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}_0x544b4b[_0x3f2f('0x3a')]=qs[_0x3f2f('0x3b')](_0x2916fa[_0x3f2f('0x32')][_0x3f2f('0x3b')]);_0x544b4b[_0x3f2f('0x3c')]=qs[_0x3f2f('0x33')](_[_0x3f2f('0x3d')](_0x2916fa[_0x3f2f('0x32')],_0x5c0adb[_0x3f2f('0x33')]),_0x4420c0);if(_0x2916fa[_0x3f2f('0x32')]['filter']){_0x544b4b[_0x3f2f('0x3c')]=_[_0x3f2f('0x3e')](_0x544b4b[_0x3f2f('0x3c')],{'$or':_[_0x3f2f('0x2d')](_0x4420c0,function(_0x3d6344){if(_0x3d6344['type']!=='VIRTUAL'){var _0x24ff74={};_0x24ff74[_0x3d6344['name']]={'$like':'%'+_0x2916fa[_0x3f2f('0x32')][_0x3f2f('0x3f')]+'%'};return _0x24ff74;}})});}_0x544b4b=_[_0x3f2f('0x3e')]({},_0x544b4b,_0x2916fa[_0x3f2f('0x40')]);var _0x1ee64d={'where':_0x544b4b[_0x3f2f('0x3c')]};return db[_0x3f2f('0x41')][_0x3f2f('0x1f')](_0x1ee64d)[_0x3f2f('0x24')](function(_0x47cd63){_0x2696d6[_0x3f2f('0x1f')]=_0x47cd63;if(_0x2916fa[_0x3f2f('0x32')]['includeAll']){_0x544b4b[_0x3f2f('0x42')]=[{'all':!![]}];}return db[_0x3f2f('0x41')][_0x3f2f('0x43')](_0x544b4b);})['then'](function(_0x37e273){_0x2696d6[_0x3f2f('0x44')]=_0x37e273;return _0x2696d6;})[_0x3f2f('0x24')](respondWithFilteredResult(_0x2fde83,_0x544b4b))['catch'](handleError(_0x2fde83,null));};exports['show']=function(_0x322550,_0x2dae3e){var _0x19c86d={'raw':![],'where':{'id':_0x322550['params']['id']}},_0x30bda3={};_0x30bda3['model']=_[_0x3f2f('0x45')](db[_0x3f2f('0x41')][_0x3f2f('0x2e')]);_0x30bda3[_0x3f2f('0x32')]=_['keys'](_0x322550[_0x3f2f('0x32')]);_0x30bda3[_0x3f2f('0x33')]=_[_0x3f2f('0x34')](_0x30bda3[_0x3f2f('0x35')],_0x30bda3[_0x3f2f('0x32')]);_0x19c86d[_0x3f2f('0x36')]=_[_0x3f2f('0x34')](_0x30bda3['model'],qs['fields'](_0x322550[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x19c86d[_0x3f2f('0x36')]=_0x19c86d['attributes'][_0x3f2f('0x46')]?_0x19c86d[_0x3f2f('0x36')]:_0x30bda3[_0x3f2f('0x35')];if(_0x322550[_0x3f2f('0x32')][_0x3f2f('0x47')]){_0x19c86d[_0x3f2f('0x42')]=[{'all':!![]}];}_0x19c86d=_[_0x3f2f('0x3e')]({},_0x19c86d,_0x322550[_0x3f2f('0x40')]);return db[_0x3f2f('0x41')][_0x3f2f('0x48')](_0x19c86d)['then'](handleEntityNotFound(_0x2dae3e,null))[_0x3f2f('0x24')](respondWithResult(_0x2dae3e,null))[_0x3f2f('0x49')](handleError(_0x2dae3e,null));};exports[_0x3f2f('0x4a')]=function(_0x370588,_0x1ece12){return db['Campaign'][_0x3f2f('0x4a')](_0x370588[_0x3f2f('0x4b')],{})[_0x3f2f('0x24')](function(_0x5fa01){var _0x221dce=_0x370588['user'][_0x3f2f('0x26')]({'plain':!![]});if(!_0x221dce)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x221dce[_0x3f2f('0x4c')]===_0x3f2f('0x4d')){var _0x48ead3=_0x5fa01[_0x3f2f('0x26')]({'plain':!![]});var _0x21fa2c=_0x3f2f('0x4e');return db['UserProfileSection'][_0x3f2f('0x48')]({'where':{'name':_0x21fa2c,'userProfileId':_0x221dce[_0x3f2f('0x4f')]},'raw':!![]})[_0x3f2f('0x24')](function(_0x2724b7){if(_0x2724b7&&_0x2724b7[_0x3f2f('0x50')]===0x0){return db[_0x3f2f('0x27')][_0x3f2f('0x4a')]({'name':_0x48ead3['name'],'resourceId':_0x48ead3['id'],'type':_0x2724b7[_0x3f2f('0x2a')],'sectionId':_0x2724b7['id']},{})[_0x3f2f('0x24')](function(){return _0x5fa01;});}else{return _0x5fa01;}})[_0x3f2f('0x49')](function(_0x300808){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x300808);throw _0x300808;});}return _0x5fa01;})[_0x3f2f('0x24')](respondWithResult(_0x1ece12,0xc9))[_0x3f2f('0x49')](handleError(_0x1ece12,null));};exports['clone']=function(_0xeea0ac,_0x5ffdc8){var _0x1d0218={'where':{'id':_0xeea0ac[_0x3f2f('0x51')]['id']}},_0x2b543d={};_0x2b543d['model']=_[_0x3f2f('0x45')](db[_0x3f2f('0x41')][_0x3f2f('0x2e')]);_0x1d0218[_0x3f2f('0x36')]=_[_0x3f2f('0x34')](_0x2b543d[_0x3f2f('0x35')],qs[_0x3f2f('0x37')](_0xeea0ac[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x1d0218['attributes']=_0x1d0218[_0x3f2f('0x36')][_0x3f2f('0x46')]?_0x1d0218[_0x3f2f('0x36')]:_0x2b543d[_0x3f2f('0x35')];if(_0xeea0ac[_0x3f2f('0x32')][_0x3f2f('0x47')]){_0x1d0218[_0x3f2f('0x42')]=[{'all':!![]}];}_0x1d0218=_[_0x3f2f('0x3e')]({},_0x1d0218,_0xeea0ac['options']);return db[_0x3f2f('0x41')][_0x3f2f('0x48')](_0x1d0218)[_0x3f2f('0x24')](handleEntityNotFound(_0x5ffdc8,null))[_0x3f2f('0x24')](function(_0x5b36dd){if(_0x5b36dd){var _0x3f04b7=_0x5b36dd[_0x3f2f('0x26')]({'plain':!![]});_0x3f04b7=qs[_0x3f2f('0x52')](_0x3f04b7,['id',_0x3f2f('0x53'),'updatedAt']);_0xeea0ac[_0x3f2f('0x4b')]=_['omit'](_0xeea0ac[_0x3f2f('0x4b')],['id',_0x3f2f('0x53'),_0x3f2f('0x54')]);return db[_0x3f2f('0x41')]['create'](_[_0x3f2f('0x3e')](_0x3f04b7,_0xeea0ac['body']),{'include':_0xeea0ac[_0x3f2f('0x32')]['includeAll']?[{'all':!![]}]:undefined})[_0x3f2f('0x24')](function(_0x475b9a){var _0x28d051=_0xeea0ac[_0x3f2f('0x4d')][_0x3f2f('0x26')]({'plain':!![]});if(!_0x28d051)throw new Error(_0x3f2f('0x55'));if(_0x28d051[_0x3f2f('0x4c')]==='user'){var _0x3fc11d=_0x475b9a['get']({'plain':!![]});var _0xb7b013=_0x3f2f('0x4e');return db['UserProfileSection'][_0x3f2f('0x48')]({'where':{'name':_0xb7b013,'userProfileId':_0x28d051[_0x3f2f('0x4f')]},'raw':!![]})['then'](function(_0x266eac){if(_0x266eac&&_0x266eac[_0x3f2f('0x50')]===0x0){return db[_0x3f2f('0x27')][_0x3f2f('0x4a')]({'name':_0x3fc11d[_0x3f2f('0x2a')],'resourceId':_0x3fc11d['id'],'type':_0x266eac[_0x3f2f('0x2a')],'sectionId':_0x266eac['id']},{})[_0x3f2f('0x24')](function(){return _0x475b9a;});}else{return _0x475b9a;}})[_0x3f2f('0x49')](function(_0x58ae11){logger['error'](_0x3f2f('0x56'),_0x58ae11);throw _0x58ae11;});}return _0x475b9a;});}})['then'](respondWithResult(_0x5ffdc8,0xc9))[_0x3f2f('0x49')](handleError(_0x5ffdc8,null));};exports[_0x3f2f('0x57')]=function(_0x2bc62f,_0x28306c){if(_0x2bc62f[_0x3f2f('0x4b')]['id']){delete _0x2bc62f[_0x3f2f('0x4b')]['id'];}return db[_0x3f2f('0x41')][_0x3f2f('0x48')]({'where':{'id':_0x2bc62f[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x28306c,null))[_0x3f2f('0x24')](saveUpdates(_0x2bc62f['body'],null))[_0x3f2f('0x24')](respondWithResult(_0x28306c,null))['catch'](handleError(_0x28306c,null));};exports[_0x3f2f('0x25')]=function(_0x3f0332,_0x171487){return db[_0x3f2f('0x41')][_0x3f2f('0x48')]({'where':{'id':_0x3f0332[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x171487,null))[_0x3f2f('0x24')](removeEntity(_0x171487,null))['catch'](handleError(_0x171487,null));};exports[_0x3f2f('0x58')]=function(_0x28e382,_0x4f443c,_0x10cbfd){var _0x110832={'raw':!![],'where':{}};var _0x5a9e7b={};var _0x2fd1d6={'count':0x0,'rows':[]};return db['Campaign'][_0x3f2f('0x59')]({'where':{'id':_0x28e382[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x4f443c,null))['then'](function(_0xaa94ac){if(_0xaa94ac){_0x5a9e7b[_0x3f2f('0x35')]=_[_0x3f2f('0x45')](db['CmHopper']['rawAttributes']);_0x5a9e7b[_0x3f2f('0x32')]=_[_0x3f2f('0x45')](_0x28e382[_0x3f2f('0x32')]);_0x5a9e7b['filters']=_[_0x3f2f('0x34')](_0x5a9e7b[_0x3f2f('0x35')],_0x5a9e7b['query']);_0x110832[_0x3f2f('0x36')]=_[_0x3f2f('0x34')](_0x5a9e7b[_0x3f2f('0x35')],qs['fields'](_0x28e382[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x110832[_0x3f2f('0x36')]=_0x110832['attributes'][_0x3f2f('0x46')]?_0x110832[_0x3f2f('0x36')]:_0x5a9e7b[_0x3f2f('0x35')];if(!_0x28e382[_0x3f2f('0x32')][_0x3f2f('0x38')](_0x3f2f('0x39'))){_0x110832['limit']=qs[_0x3f2f('0x1d')](_0x28e382[_0x3f2f('0x32')]['limit']);_0x110832[_0x3f2f('0x1c')]=qs[_0x3f2f('0x1c')](_0x28e382[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}_0x110832[_0x3f2f('0x3a')]=qs[_0x3f2f('0x3b')](_0x28e382['query'][_0x3f2f('0x3b')]);_0x110832['where']=qs['filters'](_['pick'](_0x28e382['query'],_0x5a9e7b['filters']));_0x110832[_0x3f2f('0x3c')]['CampaignId']=_0xaa94ac['id'];if(_0x28e382['query'][_0x3f2f('0x3f')]){_0x110832[_0x3f2f('0x3c')]=_['merge'](_0x110832[_0x3f2f('0x3c')],{'$or':_['map'](_0x110832['attributes'],function(_0x2c5c99){var _0x5be5af={};_0x5be5af[_0x2c5c99]={'$like':'%'+_0x28e382[_0x3f2f('0x32')][_0x3f2f('0x3f')]+'%'};return _0x5be5af;})});}_0x110832=_[_0x3f2f('0x3e')]({},_0x110832,_0x28e382['options']);return db[_0x3f2f('0x5a')][_0x3f2f('0x1f')]({'where':_0x110832['where']})[_0x3f2f('0x24')](function(_0x10665f){_0x2fd1d6[_0x3f2f('0x1f')]=_0x10665f;if(_0x28e382[_0x3f2f('0x32')][_0x3f2f('0x47')]){_0x110832[_0x3f2f('0x42')]=[{'all':!![]}];}return db[_0x3f2f('0x5a')]['findAll'](_0x110832);})['then'](function(_0x4b597a){_0x2fd1d6[_0x3f2f('0x44')]=_0x4b597a;return _0x2fd1d6;});}})[_0x3f2f('0x24')](respondWithFilteredResult(_0x4f443c,_0x110832))[_0x3f2f('0x49')](handleError(_0x4f443c,null));};exports[_0x3f2f('0x5b')]=function(_0x177b3d,_0x31f29b,_0x1bfbfc){var _0xe556d6={'raw':!![],'where':{}};var _0x5a5367={};var _0x58e36b={'count':0x0,'rows':[]};return db[_0x3f2f('0x41')][_0x3f2f('0x59')]({'where':{'id':_0x177b3d[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x31f29b,null))[_0x3f2f('0x24')](function(_0x1742be){if(_0x1742be){_0x5a5367[_0x3f2f('0x35')]=_[_0x3f2f('0x45')](db[_0x3f2f('0x5c')][_0x3f2f('0x2e')]);_0x5a5367[_0x3f2f('0x32')]=_[_0x3f2f('0x45')](_0x177b3d['query']);_0x5a5367[_0x3f2f('0x33')]=_[_0x3f2f('0x34')](_0x5a5367['model'],_0x5a5367[_0x3f2f('0x32')]);_0xe556d6[_0x3f2f('0x36')]=_[_0x3f2f('0x34')](_0x5a5367[_0x3f2f('0x35')],qs[_0x3f2f('0x37')](_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0xe556d6[_0x3f2f('0x36')]=_0xe556d6[_0x3f2f('0x36')][_0x3f2f('0x46')]?_0xe556d6[_0x3f2f('0x36')]:_0x5a5367['model'];if(!_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x38')](_0x3f2f('0x39'))){_0xe556d6[_0x3f2f('0x1d')]=qs[_0x3f2f('0x1d')](_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x1d')]);_0xe556d6[_0x3f2f('0x1c')]=qs[_0x3f2f('0x1c')](_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}_0xe556d6[_0x3f2f('0x3a')]=qs[_0x3f2f('0x3b')](_0x177b3d['query'][_0x3f2f('0x3b')]);_0xe556d6[_0x3f2f('0x3c')]=qs['filters'](_[_0x3f2f('0x3d')](_0x177b3d[_0x3f2f('0x32')],_0x5a5367['filters']));_0xe556d6[_0x3f2f('0x3c')][_0x3f2f('0x5d')]=_0x1742be['id'];if(_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x3f')]){_0xe556d6['where']=_[_0x3f2f('0x3e')](_0xe556d6[_0x3f2f('0x3c')],{'$or':_[_0x3f2f('0x2d')](_0xe556d6['attributes'],function(_0x3c994d){var _0x944b0a={};_0x944b0a[_0x3c994d]={'$like':'%'+_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x3f')]+'%'};return _0x944b0a;})});}_0xe556d6=_[_0x3f2f('0x3e')]({},_0xe556d6,_0x177b3d[_0x3f2f('0x40')]);return db[_0x3f2f('0x5c')][_0x3f2f('0x1f')]({'where':_0xe556d6[_0x3f2f('0x3c')]})[_0x3f2f('0x24')](function(_0x5d5a33){_0x58e36b[_0x3f2f('0x1f')]=_0x5d5a33;if(_0x177b3d[_0x3f2f('0x32')][_0x3f2f('0x47')]){_0xe556d6['include']=[{'all':!![]}];}return db[_0x3f2f('0x5c')][_0x3f2f('0x43')](_0xe556d6);})[_0x3f2f('0x24')](function(_0x334947){_0x58e36b[_0x3f2f('0x44')]=_0x334947;return _0x58e36b;});}})[_0x3f2f('0x24')](respondWithFilteredResult(_0x31f29b,_0xe556d6))[_0x3f2f('0x49')](handleError(_0x31f29b,null));};exports['getHopperFinals']=function(_0x3e2c0c,_0x129cd5,_0x3f3168){var _0x29a7de={'raw':!![],'where':{}};var _0x4f72d6={};var _0x5c4810={'count':0x0,'rows':[]};return db[_0x3f2f('0x41')][_0x3f2f('0x59')]({'where':{'id':_0x3e2c0c[_0x3f2f('0x51')]['id']}})['then'](handleEntityNotFound(_0x129cd5,null))['then'](function(_0x3c0305){if(_0x3c0305){_0x4f72d6[_0x3f2f('0x35')]=_['keys'](db[_0x3f2f('0x5e')][_0x3f2f('0x2e')]);_0x4f72d6[_0x3f2f('0x32')]=_[_0x3f2f('0x45')](_0x3e2c0c[_0x3f2f('0x32')]);_0x4f72d6[_0x3f2f('0x33')]=_[_0x3f2f('0x34')](_0x4f72d6[_0x3f2f('0x35')],_0x4f72d6['query']);_0x29a7de[_0x3f2f('0x36')]=_[_0x3f2f('0x34')](_0x4f72d6[_0x3f2f('0x35')],qs[_0x3f2f('0x37')](_0x3e2c0c[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x29a7de[_0x3f2f('0x36')]=_0x29a7de[_0x3f2f('0x36')][_0x3f2f('0x46')]?_0x29a7de[_0x3f2f('0x36')]:_0x4f72d6[_0x3f2f('0x35')];if(!_0x3e2c0c[_0x3f2f('0x32')]['hasOwnProperty'](_0x3f2f('0x39'))){_0x29a7de[_0x3f2f('0x1d')]=qs[_0x3f2f('0x1d')](_0x3e2c0c[_0x3f2f('0x32')][_0x3f2f('0x1d')]);_0x29a7de[_0x3f2f('0x1c')]=qs[_0x3f2f('0x1c')](_0x3e2c0c[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}_0x29a7de[_0x3f2f('0x3a')]=qs[_0x3f2f('0x3b')](_0x3e2c0c[_0x3f2f('0x32')][_0x3f2f('0x3b')]);_0x29a7de['where']=qs[_0x3f2f('0x33')](_[_0x3f2f('0x3d')](_0x3e2c0c[_0x3f2f('0x32')],_0x4f72d6['filters']));_0x29a7de[_0x3f2f('0x3c')]['CampaignId']=_0x3c0305['id'];if(_0x3e2c0c['query'][_0x3f2f('0x3f')]){_0x29a7de[_0x3f2f('0x3c')]=_[_0x3f2f('0x3e')](_0x29a7de[_0x3f2f('0x3c')],{'$or':_[_0x3f2f('0x2d')](_0x29a7de[_0x3f2f('0x36')],function(_0x4627db){var _0x4b98d4={};_0x4b98d4[_0x4627db]={'$like':'%'+_0x3e2c0c[_0x3f2f('0x32')][_0x3f2f('0x3f')]+'%'};return _0x4b98d4;})});}_0x29a7de=_[_0x3f2f('0x3e')]({},_0x29a7de,_0x3e2c0c[_0x3f2f('0x40')]);return db[_0x3f2f('0x5e')]['count']({'where':_0x29a7de[_0x3f2f('0x3c')]})[_0x3f2f('0x24')](function(_0xd7939){_0x5c4810[_0x3f2f('0x1f')]=_0xd7939;if(_0x3e2c0c['query']['includeAll']){_0x29a7de['include']=[{'all':!![]}];}return db[_0x3f2f('0x5e')][_0x3f2f('0x43')](_0x29a7de);})['then'](function(_0x435aec){_0x5c4810['rows']=_0x435aec;return _0x5c4810;});}})['then'](respondWithFilteredResult(_0x129cd5,_0x29a7de))[_0x3f2f('0x49')](handleError(_0x129cd5,null));};exports[_0x3f2f('0x5f')]=function(_0x386d2e,_0xaed22,_0x2880b3){var _0x2731c2={'raw':!![],'where':{}};var _0x1c3421={};var _0x32c56a={'count':0x0,'rows':[]};return db[_0x3f2f('0x41')]['findOne']({'where':{'id':_0x386d2e[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0xaed22,null))[_0x3f2f('0x24')](function(_0x23fa9d){if(_0x23fa9d){_0x1c3421[_0x3f2f('0x35')]=_[_0x3f2f('0x45')](db[_0x3f2f('0x60')][_0x3f2f('0x2e')]);_0x1c3421[_0x3f2f('0x32')]=_[_0x3f2f('0x45')](_0x386d2e[_0x3f2f('0x32')]);_0x1c3421[_0x3f2f('0x33')]=_[_0x3f2f('0x34')](_0x1c3421[_0x3f2f('0x35')],_0x1c3421[_0x3f2f('0x32')]);_0x2731c2['attributes']=_[_0x3f2f('0x34')](_0x1c3421['model'],qs['fields'](_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x2731c2['attributes']=_0x2731c2[_0x3f2f('0x36')][_0x3f2f('0x46')]?_0x2731c2[_0x3f2f('0x36')]:_0x1c3421[_0x3f2f('0x35')];if(!_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x38')](_0x3f2f('0x39'))){_0x2731c2[_0x3f2f('0x1d')]=qs[_0x3f2f('0x1d')](_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x1d')]);_0x2731c2['offset']=qs[_0x3f2f('0x1c')](_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}_0x2731c2[_0x3f2f('0x3a')]=qs['sort'](_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x3b')]);_0x2731c2['where']=qs['filters'](_[_0x3f2f('0x3d')](_0x386d2e['query'],_0x1c3421[_0x3f2f('0x33')]));_0x2731c2['where']['CampaignId']=_0x23fa9d['id'];if(_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x3f')]){_0x2731c2['where']=_['merge'](_0x2731c2[_0x3f2f('0x3c')],{'$or':_[_0x3f2f('0x2d')](_0x2731c2[_0x3f2f('0x36')],function(_0x3b5454){var _0x27e158={};_0x27e158[_0x3b5454]={'$like':'%'+_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x3f')]+'%'};return _0x27e158;})});}_0x2731c2=_['merge']({},_0x2731c2,_0x386d2e['options']);return db[_0x3f2f('0x60')]['count']({'where':_0x2731c2[_0x3f2f('0x3c')]})[_0x3f2f('0x24')](function(_0x1e5c87){_0x32c56a['count']=_0x1e5c87;if(_0x386d2e[_0x3f2f('0x32')][_0x3f2f('0x47')]){_0x2731c2[_0x3f2f('0x42')]=[{'all':!![]}];}return db[_0x3f2f('0x60')]['findAll'](_0x2731c2);})['then'](function(_0x3ecd16){_0x32c56a[_0x3f2f('0x44')]=_0x3ecd16;return _0x32c56a;});}})[_0x3f2f('0x24')](respondWithFilteredResult(_0xaed22,_0x2731c2))['catch'](handleError(_0xaed22,null));};exports[_0x3f2f('0x61')]=function(_0x2f8aef,_0x4d78c8,_0x3114f0){var _0x2521d1={};var _0x37a7c4={};var _0x3bb359;var _0x44c127;return db[_0x3f2f('0x41')][_0x3f2f('0x59')]({'where':{'id':_0x2f8aef[_0x3f2f('0x51')]['id']}})['then'](handleEntityNotFound(_0x4d78c8,null))[_0x3f2f('0x24')](function(_0x510ac3){if(_0x510ac3){_0x3bb359=_0x510ac3;_0x37a7c4[_0x3f2f('0x35')]=_[_0x3f2f('0x45')](db['CmList']['rawAttributes']);_0x37a7c4['query']=_[_0x3f2f('0x45')](_0x2f8aef[_0x3f2f('0x32')]);_0x37a7c4[_0x3f2f('0x33')]=_['intersection'](_0x37a7c4['model'],_0x37a7c4[_0x3f2f('0x32')]);_0x2521d1[_0x3f2f('0x36')]=_[_0x3f2f('0x34')](_0x37a7c4[_0x3f2f('0x35')],qs[_0x3f2f('0x37')](_0x2f8aef[_0x3f2f('0x32')][_0x3f2f('0x37')]));_0x2521d1[_0x3f2f('0x36')]=_0x2521d1[_0x3f2f('0x36')]['length']?_0x2521d1[_0x3f2f('0x36')]:_0x37a7c4[_0x3f2f('0x35')];_0x2521d1[_0x3f2f('0x3a')]=qs['sort'](_0x2f8aef['query'][_0x3f2f('0x3b')]);_0x2521d1[_0x3f2f('0x3c')]=qs[_0x3f2f('0x33')](_[_0x3f2f('0x3d')](_0x2f8aef['query'],_0x37a7c4[_0x3f2f('0x33')]));if(_0x2f8aef['query'][_0x3f2f('0x3f')]){_0x2521d1[_0x3f2f('0x3c')]=_[_0x3f2f('0x3e')](_0x2521d1[_0x3f2f('0x3c')],{'$or':_[_0x3f2f('0x2d')](_0x2521d1[_0x3f2f('0x36')],function(_0x4dd88c){var _0x4459d1={};_0x4459d1[_0x4dd88c]={'$like':'%'+_0x2f8aef['query'][_0x3f2f('0x3f')]+'%'};return _0x4459d1;})});}_0x2521d1=_[_0x3f2f('0x3e')]({},_0x2521d1,_0x2f8aef[_0x3f2f('0x40')]);return _0x3bb359[_0x3f2f('0x61')](_0x2521d1);}})[_0x3f2f('0x24')](function(_0x28c30f){if(_0x28c30f){_0x44c127=_0x28c30f[_0x3f2f('0x46')];if(!_0x2f8aef[_0x3f2f('0x32')]['hasOwnProperty']('nolimit')){_0x2521d1['limit']=qs[_0x3f2f('0x1d')](_0x2f8aef[_0x3f2f('0x32')][_0x3f2f('0x1d')]);_0x2521d1['offset']=qs[_0x3f2f('0x1c')](_0x2f8aef[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}return _0x3bb359[_0x3f2f('0x61')](_0x2521d1);}})[_0x3f2f('0x24')](function(_0x166a73){if(_0x166a73){return _0x166a73?{'count':_0x44c127,'rows':_0x166a73}:null;}})['then'](respondWithResult(_0x4d78c8,null))[_0x3f2f('0x49')](handleError(_0x4d78c8,null));};exports['addLists']=function(_0x4f0924,_0x17fd8d,_0x3f3b03){var _0x2111be,_0x3f150f;var _0x5bdfeb=[];var _0x4ab8ae=moment()[_0x3f2f('0x62')]('YYYY-MM-DD\x20HH:mm:ss');return db[_0x3f2f('0x41')][_0x3f2f('0x48')]({'where':{'id':_0x4f0924[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x17fd8d,null))['then'](function(_0x2543e2){if(_0x2543e2){_0x3f150f=_0x2543e2;return _0x2543e2[_0x3f2f('0x63')](_0x4f0924[_0x3f2f('0x4b')][_0x3f2f('0x64')],_[_0x3f2f('0x52')](_0x4f0924[_0x3f2f('0x4b')],[_0x3f2f('0x64'),'id'])||{});}return null;})['spread'](function(_0xf499d5){var _0x97b2db;var _0xe5db56;_0x2111be=_0xf499d5||[];var _0x4388e2=[];if(_0xf499d5){for(var _0x2a9054=0x0;_0x2a9054<_0xf499d5[_0x3f2f('0x46')];_0x2a9054+=0x1){var _0x2b768d=_0xf499d5[_0x2a9054][_0x3f2f('0x26')]({'plain':!![]});_0x3f150f[_0x3f2f('0x65')]=_0x4f0924[_0x3f2f('0x4b')][_0x3f2f('0x65')]?_0x4f0924['body'][_0x3f2f('0x65')]:_0x3f150f[_0x3f2f('0x65')];switch(_0x3f150f[_0x3f2f('0x65')]){case _0x3f2f('0x66'):_0x97b2db=squel[_0x3f2f('0x67')]()[_0x3f2f('0x68')](_0x3f2f('0x69'))['fromQuery']([_0x3f2f('0x6a'),'scheduledAt',_0x3f2f('0x6b'),'ListId',_0x3f2f('0x5d'),_0x3f2f('0x53'),'updatedAt'],squel[_0x3f2f('0x6c')]()[_0x3f2f('0x6d')](_0x3f2f('0x6a'),_0x3f2f('0x6a'))[_0x3f2f('0x6d')]('NOW()','scheduledAt')[_0x3f2f('0x6d')]('id',_0x3f2f('0x6b'))[_0x3f2f('0x6d')](_0x2b768d['CmListId']['toString'](),_0x3f2f('0x6e'))[_0x3f2f('0x6d')](_0x4f0924[_0x3f2f('0x51')]['id'][_0x3f2f('0x6f')](),_0x3f2f('0x5d'))[_0x3f2f('0x6d')]('\x27'+_0x4ab8ae+'\x27','createdAt')['field']('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x54'))[_0x3f2f('0x70')](_0x3f2f('0x71'))['where'](_0x3f2f('0x72'))[_0x3f2f('0x3c')]('ListId\x20=\x20?',_0x2b768d[_0x3f2f('0x73')][_0x3f2f('0x6f')]())[_0x3f2f('0x3c')]('phone\x20IS\x20NOT\x20NULL')['where'](_0x3f2f('0x74'),squel[_0x3f2f('0x6c')]()[_0x3f2f('0x6d')](_0x3f2f('0x75'))[_0x3f2f('0x70')](_0x3f2f('0x76'))[_0x3f2f('0x3c')]('CampaignId\x20=\x20?',_0x4f0924['params']['id'][_0x3f2f('0x6f')]()))[_0x3f2f('0x3c')]('phone\x20NOT\x20IN\x20(?)',squel['select']()[_0x3f2f('0x6d')](_0x3f2f('0x77'))[_0x3f2f('0x70')](_0x3f2f('0x69'))[_0x3f2f('0x3c')](_0x3f2f('0x78'),_0x4f0924[_0x3f2f('0x51')]['id'][_0x3f2f('0x6f')]())))[_0x3f2f('0x6f')]();break;case _0x3f2f('0x79'):_0x97b2db=squel[_0x3f2f('0x67')]()[_0x3f2f('0x68')]('cm_hopper')['fromQuery'](['phone','scheduledAt',_0x3f2f('0x6b'),_0x3f2f('0x6e'),_0x3f2f('0x5d'),'createdAt','updatedAt'],squel[_0x3f2f('0x6c')]()[_0x3f2f('0x6d')]('phone',_0x3f2f('0x6a'))['field']('NOW()','scheduledAt')[_0x3f2f('0x6d')]('id',_0x3f2f('0x6b'))[_0x3f2f('0x6d')](_0x2b768d[_0x3f2f('0x73')][_0x3f2f('0x6f')](),_0x3f2f('0x6e'))[_0x3f2f('0x6d')](_0x4f0924[_0x3f2f('0x51')]['id'][_0x3f2f('0x6f')](),_0x3f2f('0x5d'))[_0x3f2f('0x6d')]('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x53'))[_0x3f2f('0x6d')]('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x54'))[_0x3f2f('0x70')](_0x3f2f('0x71'))[_0x3f2f('0x3c')](_0x3f2f('0x72'))[_0x3f2f('0x3c')](_0x3f2f('0x7a'),_0x2b768d[_0x3f2f('0x73')][_0x3f2f('0x6f')]())[_0x3f2f('0x3c')](_0x3f2f('0x7b'))['where'](_0x3f2f('0x74'),squel[_0x3f2f('0x6c')]()['field'](_0x3f2f('0x77'))['from'](_0x3f2f('0x69'))[_0x3f2f('0x3c')](_0x3f2f('0x78'),_0x4f0924[_0x3f2f('0x51')]['id'][_0x3f2f('0x6f')]())))[_0x3f2f('0x6f')]();break;default:_0x97b2db=squel[_0x3f2f('0x67')]()['into'](_0x3f2f('0x69'))['fromQuery']([_0x3f2f('0x6a'),_0x3f2f('0x7c'),'ContactId','ListId',_0x3f2f('0x5d'),'createdAt',_0x3f2f('0x54')],squel[_0x3f2f('0x6c')]()[_0x3f2f('0x6d')]('phone',_0x3f2f('0x6a'))[_0x3f2f('0x6d')]('NOW()',_0x3f2f('0x7c'))[_0x3f2f('0x6d')]('id',_0x3f2f('0x6b'))[_0x3f2f('0x6d')](_0x2b768d[_0x3f2f('0x73')][_0x3f2f('0x6f')](),_0x3f2f('0x6e'))[_0x3f2f('0x6d')](_0x4f0924[_0x3f2f('0x51')]['id']['toString'](),_0x3f2f('0x5d'))[_0x3f2f('0x6d')]('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x53'))['field']('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x54'))[_0x3f2f('0x70')](_0x3f2f('0x71'))[_0x3f2f('0x3c')](_0x3f2f('0x72'))[_0x3f2f('0x3c')](_0x3f2f('0x7a'),_0x2b768d[_0x3f2f('0x73')][_0x3f2f('0x6f')]())[_0x3f2f('0x3c')](_0x3f2f('0x7b')))['toString']();}_0xe5db56=squel[_0x3f2f('0x67')]()[_0x3f2f('0x68')](_0x3f2f('0x7d'))[_0x3f2f('0x7e')]([_0x3f2f('0x7f'),_0x3f2f('0x7c'),_0x3f2f('0x6a'),_0x3f2f('0x80'),'createdAt',_0x3f2f('0x54')],squel[_0x3f2f('0x6c')]()[_0x3f2f('0x6d')]('h.id','id')['field'](_0x3f2f('0x81'),'scheduledAt')[_0x3f2f('0x6d')]('ci.item',_0x3f2f('0x6a'))[_0x3f2f('0x6d')]('ci.OrderBY',_0x3f2f('0x80'))[_0x3f2f('0x6d')]('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x53'))[_0x3f2f('0x6d')]('\x27'+_0x4ab8ae+'\x27',_0x3f2f('0x54'))[_0x3f2f('0x70')](_0x3f2f('0x82'),'ci')[_0x3f2f('0x83')]('cm_hopper','h','h.ContactId\x20=\x20ci.CmContactId')[_0x3f2f('0x3c')](_0x3f2f('0x84'),_0x2b768d[_0x3f2f('0x73')][_0x3f2f('0x6f')]())['where'](_0x3f2f('0x85'),_0x4f0924[_0x3f2f('0x51')]['id'][_0x3f2f('0x6f')]())['where'](_0x3f2f('0x86'),_0x4ab8ae))[_0x3f2f('0x6f')]();_0x4388e2[_0x3f2f('0x87')](db['sequelize'][_0x3f2f('0x32')](_0x97b2db));_0x5bdfeb['push'](db[_0x3f2f('0x88')][_0x3f2f('0x32')](_0xe5db56));}return BPromise['all'](_0x4388e2);}})[_0x3f2f('0x24')](function(){return BPromise['all'](_0x5bdfeb);})[_0x3f2f('0x24')](function(){return _0x2111be;})['then'](respondWithResult(_0x17fd8d,null))['catch'](handleError(_0x17fd8d,null));};exports[_0x3f2f('0x89')]=function(_0x39f5a2,_0x2cd2b6,_0x55ddd9){return db[_0x3f2f('0x41')][_0x3f2f('0x48')]({'where':{'id':_0x39f5a2[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x2cd2b6,null))['then'](function(_0x4059a5){if(_0x4059a5){return _0x4059a5[_0x3f2f('0x89')](_0x39f5a2[_0x3f2f('0x32')][_0x3f2f('0x64')]);}})[_0x3f2f('0x24')](function(_0x503937){if(_0x503937){return db[_0x3f2f('0x5a')][_0x3f2f('0x25')]({'where':{'ListId':_0x39f5a2[_0x3f2f('0x32')][_0x3f2f('0x64')],'CampaignId':_0x39f5a2[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](function(){return _0x503937;});}})[_0x3f2f('0x24')](respondWithStatusCode(_0x2cd2b6,null))[_0x3f2f('0x49')](handleError(_0x2cd2b6,null));};exports['getBlackLists']=function(_0x4bd25a,_0x2ed07b,_0x10b9d2){var _0x44d5a9={};var _0x5ac6f5={};var _0x1cc1c5;var _0x37d6b9;return db[_0x3f2f('0x41')][_0x3f2f('0x59')]({'where':{'id':_0x4bd25a[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x2ed07b,null))[_0x3f2f('0x24')](function(_0x3ab4d2){if(_0x3ab4d2){_0x1cc1c5=_0x3ab4d2;_0x5ac6f5['model']=_[_0x3f2f('0x45')](db[_0x3f2f('0x8a')][_0x3f2f('0x2e')]);_0x5ac6f5[_0x3f2f('0x32')]=_[_0x3f2f('0x45')](_0x4bd25a['query']);_0x5ac6f5['filters']=_[_0x3f2f('0x34')](_0x5ac6f5[_0x3f2f('0x35')],_0x5ac6f5[_0x3f2f('0x32')]);_0x44d5a9[_0x3f2f('0x36')]=_['intersection'](_0x5ac6f5[_0x3f2f('0x35')],qs['fields'](_0x4bd25a['query'][_0x3f2f('0x37')]));_0x44d5a9['attributes']=_0x44d5a9[_0x3f2f('0x36')][_0x3f2f('0x46')]?_0x44d5a9['attributes']:_0x5ac6f5[_0x3f2f('0x35')];_0x44d5a9['order']=qs[_0x3f2f('0x3b')](_0x4bd25a[_0x3f2f('0x32')][_0x3f2f('0x3b')]);_0x44d5a9[_0x3f2f('0x3c')]=qs[_0x3f2f('0x33')](_[_0x3f2f('0x3d')](_0x4bd25a[_0x3f2f('0x32')],_0x5ac6f5[_0x3f2f('0x33')]));if(_0x4bd25a[_0x3f2f('0x32')][_0x3f2f('0x3f')]){_0x44d5a9[_0x3f2f('0x3c')]=_[_0x3f2f('0x3e')](_0x44d5a9[_0x3f2f('0x3c')],{'$or':_[_0x3f2f('0x2d')](_0x44d5a9[_0x3f2f('0x36')],function(_0x2339b1){var _0x9e9086={};_0x9e9086[_0x2339b1]={'$like':'%'+_0x4bd25a[_0x3f2f('0x32')]['filter']+'%'};return _0x9e9086;})});}_0x44d5a9=_['merge']({},_0x44d5a9,_0x4bd25a['options']);return _0x1cc1c5[_0x3f2f('0x8b')](_0x44d5a9);}})['then'](function(_0x1e9d76){if(_0x1e9d76){_0x37d6b9=_0x1e9d76[_0x3f2f('0x46')];if(!_0x4bd25a[_0x3f2f('0x32')][_0x3f2f('0x38')](_0x3f2f('0x39'))){_0x44d5a9[_0x3f2f('0x1d')]=qs['limit'](_0x4bd25a[_0x3f2f('0x32')]['limit']);_0x44d5a9[_0x3f2f('0x1c')]=qs[_0x3f2f('0x1c')](_0x4bd25a[_0x3f2f('0x32')][_0x3f2f('0x1c')]);}return _0x1cc1c5[_0x3f2f('0x8b')](_0x44d5a9);}})['then'](function(_0x14b969){if(_0x14b969){return _0x14b969?{'count':_0x37d6b9,'rows':_0x14b969}:null;}})[_0x3f2f('0x24')](respondWithResult(_0x2ed07b,null))[_0x3f2f('0x49')](handleError(_0x2ed07b,null));};exports['addBlackLists']=function(_0x178f38,_0x2f9897,_0x8873b0){var _0xe05e6c,_0x4cc102;var _0xaae38c=[];var _0x35f25e=moment()[_0x3f2f('0x62')]('YYYY-MM-DD\x20HH:mm:ss');return db['Campaign'][_0x3f2f('0x48')]({'where':{'id':_0x178f38[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x2f9897,null))[_0x3f2f('0x24')](function(_0x3e4927){if(_0x3e4927){_0x4cc102=_0x3e4927;return _0x3e4927[_0x3f2f('0x8c')](_0x178f38[_0x3f2f('0x4b')]['ids'],_[_0x3f2f('0x52')](_0x178f38[_0x3f2f('0x4b')],[_0x3f2f('0x64'),'id'])||{});}return null;})[_0x3f2f('0x8d')](function(_0x1427ba){var _0x354321;var _0x11c50a;_0xe05e6c=_0x1427ba||[];var _0x2b5541=[];if(_0x1427ba){for(var _0x449b58=0x0;_0x449b58<_0x1427ba[_0x3f2f('0x46')];_0x449b58+=0x1){var _0x3348db=_0x1427ba[_0x449b58][_0x3f2f('0x26')]({'plain':!![]});_0x354321=squel[_0x3f2f('0x67')]()[_0x3f2f('0x68')]('cm_hopper_black')[_0x3f2f('0x7e')](['phone',_0x3f2f('0x6b'),_0x3f2f('0x6e'),'CampaignId',_0x3f2f('0x53'),'updatedAt'],squel[_0x3f2f('0x6c')]()[_0x3f2f('0x6d')](_0x3f2f('0x6a'),_0x3f2f('0x6a'))[_0x3f2f('0x6d')]('id',_0x3f2f('0x6b'))[_0x3f2f('0x6d')](_0x3348db['CmListId'][_0x3f2f('0x6f')](),_0x3f2f('0x6e'))[_0x3f2f('0x6d')](_0x178f38[_0x3f2f('0x51')]['id'][_0x3f2f('0x6f')](),'CampaignId')[_0x3f2f('0x6d')]('NOW()',_0x3f2f('0x53'))['field'](_0x3f2f('0x81'),_0x3f2f('0x54'))[_0x3f2f('0x70')](_0x3f2f('0x71'))[_0x3f2f('0x3c')](_0x3f2f('0x72'))[_0x3f2f('0x3c')](_0x3f2f('0x7a'),_0x3348db[_0x3f2f('0x73')][_0x3f2f('0x6f')]())[_0x3f2f('0x3c')](_0x3f2f('0x7b')))[_0x3f2f('0x6f')]();_0x2b5541[_0x3f2f('0x87')](db[_0x3f2f('0x88')][_0x3f2f('0x32')](_0x354321));}return BPromise['all'](_0x2b5541);}})[_0x3f2f('0x24')](function(){return _0xe05e6c;})['then'](respondWithResult(_0x2f9897,null))[_0x3f2f('0x49')](handleError(_0x2f9897,null));};exports['removeBlackLists']=function(_0x36d59e,_0x2cea27,_0x217eae){return db[_0x3f2f('0x41')][_0x3f2f('0x48')]({'where':{'id':_0x36d59e[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](handleEntityNotFound(_0x2cea27,null))[_0x3f2f('0x24')](function(_0x32c8cd){if(_0x32c8cd){return _0x32c8cd[_0x3f2f('0x8e')](_0x36d59e[_0x3f2f('0x32')][_0x3f2f('0x64')]);}})[_0x3f2f('0x24')](function(_0x5ddbd9){if(_0x5ddbd9){return db['CmHopperBlack']['destroy']({'where':{'ListId':_0x36d59e[_0x3f2f('0x32')][_0x3f2f('0x64')],'CampaignId':_0x36d59e[_0x3f2f('0x51')]['id']}})[_0x3f2f('0x24')](function(){return _0x5ddbd9;});}})['then'](respondWithStatusCode(_0x2cea27,null))['catch'](handleError(_0x2cea27,null));};