Built motion from commit f16df95f.|2.5.40
[motion2.git] / server / api / cmList / cmList.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 _0xfbc1=['userCmList:save','removeAgents','userCmList:remove','getAgents','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','localhost','socket.io-emitter','./cmList.socket','register','sendStatus','status','end','undefined','limit','count','Content-Range','json','reject','update','then','destroy','get','Lists','UserProfileResource','error','send','map','CmList','type','model','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','offset','order','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','ListId','getDispositions','Disposition','rawAttributes','removeDispositions','ids','addContacts','CmContact','tags','isArray','omit','push','dataValues','message','Malformed\x20request\x20syntax','CmCustomField','CustomFields','concat','cf_%d','raw','getContacts','format','isEmpty','now','writeFileSync','/tmp/list_%d_%s.csv','setHeader','Content-disposition','Content-type','text/csv','download','addCustomField','findOne','addCustomFields','TEXT','text','number','switch','Sequelize','BOOLEAN','queryInterface','addColumn','cm_contacts','cf_%s','findAndCountAll','addAgents','spread','emit'];(function(_0x2b7764,_0x2606f1){var _0x848dcb=function(_0x1ae85b){while(--_0x1ae85b){_0x2b7764['push'](_0x2b7764['shift']());}};_0x848dcb(++_0x2606f1);}(_0xfbc1,0x118));var _0x1fbc=function(_0x819464,_0x46fc91){_0x819464=_0x819464-0x0;var _0x49dcc0=_0xfbc1[_0x819464];return _0x49dcc0;};'use strict';var emlformat=require(_0x1fbc('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x1fbc('0x1'));var rp=require(_0x1fbc('0x2'));var moment=require(_0x1fbc('0x3'));var BPromise=require(_0x1fbc('0x4'));var Mustache=require(_0x1fbc('0x5'));var util=require(_0x1fbc('0x6'));var path=require('path');var sox=require(_0x1fbc('0x7'));var csv=require(_0x1fbc('0x8'));var ejs=require(_0x1fbc('0x9'));var fs=require('fs');var fs_extra=require(_0x1fbc('0xa'));var _=require(_0x1fbc('0xb'));var squel=require('squel');var crypto=require(_0x1fbc('0xc'));var jsforce=require(_0x1fbc('0xd'));var deskjs=require(_0x1fbc('0xe'));var toCsv=require('to-csv');var querystring=require(_0x1fbc('0xf'));var Papa=require(_0x1fbc('0x10'));var Redis=require(_0x1fbc('0x11'));var authService=require(_0x1fbc('0x12'));var qs=require(_0x1fbc('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1fbc('0x14'));var logger=require(_0x1fbc('0x15'))('api');var utils=require(_0x1fbc('0x16'));var config=require(_0x1fbc('0x17'));var licenseUtil=require(_0x1fbc('0x18'));var db=require(_0x1fbc('0x19'))['db'];config['redis']=_['defaults'](config['redis'],{'host':_0x1fbc('0x1a'),'port':0x18eb});var socket=require(_0x1fbc('0x1b'))(new Redis(config['redis']));require(_0x1fbc('0x1c'))[_0x1fbc('0x1d')](socket);function respondWithStatusCode(_0x2caef2,_0x5dd4c4){_0x5dd4c4=_0x5dd4c4||0xcc;return function(_0x2ef5d4){if(_0x2ef5d4){return _0x2caef2[_0x1fbc('0x1e')](_0x5dd4c4);}return _0x2caef2[_0x1fbc('0x1f')](_0x5dd4c4)[_0x1fbc('0x20')]();};}function respondWithResult(_0x16207d,_0x5d52f9){_0x5d52f9=_0x5d52f9||0xc8;return function(_0x5e2ed7){if(_0x5e2ed7){return _0x16207d[_0x1fbc('0x1f')](_0x5d52f9)['json'](_0x5e2ed7);}};}function respondWithFilteredResult(_0x5675f5,_0xd1b8dd){return function(_0x53da1c){if(_0x53da1c){var _0x4ce8f5=typeof _0xd1b8dd['offset']===_0x1fbc('0x21')&&typeof _0xd1b8dd[_0x1fbc('0x22')]===_0x1fbc('0x21');var _0x1319a3=_0x53da1c[_0x1fbc('0x23')];var _0x5b68ed=_0x4ce8f5?0x0:_0xd1b8dd['offset'];var _0x3ffe38=_0x4ce8f5?_0x53da1c[_0x1fbc('0x23')]:_0xd1b8dd['offset']+_0xd1b8dd[_0x1fbc('0x22')];var _0x195f62;if(_0x3ffe38>=_0x1319a3){_0x3ffe38=_0x1319a3;_0x195f62=0xc8;}else{_0x195f62=0xce;}_0x5675f5['status'](_0x195f62);return _0x5675f5['set'](_0x1fbc('0x24'),_0x5b68ed+'-'+_0x3ffe38+'/'+_0x1319a3)[_0x1fbc('0x25')](_0x53da1c);}return null;};}function patchUpdates(_0x1f39ac){return function(_0x32ab48){try{jsonpatch['apply'](_0x32ab48,_0x1f39ac,!![]);}catch(_0x234d7f){return BPromise[_0x1fbc('0x26')](_0x234d7f);}return _0x32ab48['save']();};}function saveUpdates(_0x3a37e3,_0x5a9255){return function(_0x275de2){if(_0x275de2){return _0x275de2[_0x1fbc('0x27')](_0x3a37e3)[_0x1fbc('0x28')](function(_0x31e9e1){return _0x31e9e1;});}return null;};}function removeEntity(_0x32e2cb,_0x27cd4c){return function(_0x3e2ae0){if(_0x3e2ae0){return _0x3e2ae0[_0x1fbc('0x29')]()[_0x1fbc('0x28')](function(){var _0x591371=_0x3e2ae0[_0x1fbc('0x2a')]({'plain':!![]});var _0x7d87cc=_0x1fbc('0x2b');return db[_0x1fbc('0x2c')]['destroy']({'where':{'type':_0x7d87cc,'resourceId':_0x591371['id']}})[_0x1fbc('0x28')](function(){return _0x3e2ae0;});})[_0x1fbc('0x28')](function(){_0x32e2cb[_0x1fbc('0x1f')](0xcc)['end']();});}};}function handleEntityNotFound(_0x130717,_0x2f3d34){return function(_0x32d309){if(!_0x32d309){_0x130717[_0x1fbc('0x1e')](0x194);}return _0x32d309;};}function handleError(_0x366e90,_0x3b8cb0){_0x3b8cb0=_0x3b8cb0||0x1f4;return function(_0x31584f){logger[_0x1fbc('0x2d')](_0x31584f['stack']);if(_0x31584f['name']){delete _0x31584f['name'];}_0x366e90[_0x1fbc('0x1f')](_0x3b8cb0)[_0x1fbc('0x2e')](_0x31584f);};}exports['index']=function(_0x53e8b0,_0x21716c){var _0x249fe9={},_0x55258d={},_0x1be5df={'count':0x0,'rows':[]};var _0xe4c25c=_[_0x1fbc('0x2f')](db[_0x1fbc('0x30')]['rawAttributes'],function(_0x21b0b2){return{'name':_0x21b0b2['fieldName'],'type':_0x21b0b2[_0x1fbc('0x31')]['key']};});_0x55258d[_0x1fbc('0x32')]=_['map'](_0xe4c25c,_0x1fbc('0x33'));_0x55258d[_0x1fbc('0x34')]=_[_0x1fbc('0x35')](_0x53e8b0[_0x1fbc('0x34')]);_0x55258d[_0x1fbc('0x36')]=_[_0x1fbc('0x37')](_0x55258d[_0x1fbc('0x32')],_0x55258d[_0x1fbc('0x34')]);_0x249fe9[_0x1fbc('0x38')]=_['intersection'](_0x55258d[_0x1fbc('0x32')],qs[_0x1fbc('0x39')](_0x53e8b0[_0x1fbc('0x34')][_0x1fbc('0x39')]));_0x249fe9[_0x1fbc('0x38')]=_0x249fe9['attributes'][_0x1fbc('0x3a')]?_0x249fe9[_0x1fbc('0x38')]:_0x55258d['model'];if(!_0x53e8b0[_0x1fbc('0x34')][_0x1fbc('0x3b')](_0x1fbc('0x3c'))){_0x249fe9[_0x1fbc('0x22')]=qs[_0x1fbc('0x22')](_0x53e8b0['query'][_0x1fbc('0x22')]);_0x249fe9[_0x1fbc('0x3d')]=qs[_0x1fbc('0x3d')](_0x53e8b0['query'][_0x1fbc('0x3d')]);}_0x249fe9[_0x1fbc('0x3e')]=qs[_0x1fbc('0x3f')](_0x53e8b0[_0x1fbc('0x34')][_0x1fbc('0x3f')]);_0x249fe9[_0x1fbc('0x40')]=qs[_0x1fbc('0x36')](_[_0x1fbc('0x41')](_0x53e8b0[_0x1fbc('0x34')],_0x55258d[_0x1fbc('0x36')]),_0xe4c25c);if(_0x53e8b0['query']['filter']){_0x249fe9['where']=_[_0x1fbc('0x42')](_0x249fe9[_0x1fbc('0x40')],{'$or':_['map'](_0xe4c25c,function(_0x4b7176){if(_0x4b7176[_0x1fbc('0x31')]!==_0x1fbc('0x43')){var _0x4825d7={};_0x4825d7[_0x4b7176[_0x1fbc('0x33')]]={'$like':'%'+_0x53e8b0[_0x1fbc('0x34')][_0x1fbc('0x44')]+'%'};return _0x4825d7;}})});}_0x249fe9=_[_0x1fbc('0x42')]({},_0x249fe9,_0x53e8b0[_0x1fbc('0x45')]);var _0x3446a4={'where':_0x249fe9['where']};return db['CmList'][_0x1fbc('0x23')](_0x3446a4)[_0x1fbc('0x28')](function(_0x3c30c8){_0x1be5df['count']=_0x3c30c8;if(_0x53e8b0[_0x1fbc('0x34')][_0x1fbc('0x46')]){_0x249fe9[_0x1fbc('0x47')]=[{'all':!![]}];}return db[_0x1fbc('0x30')][_0x1fbc('0x48')](_0x249fe9);})[_0x1fbc('0x28')](function(_0x52dde4){_0x1be5df[_0x1fbc('0x49')]=_0x52dde4;return _0x1be5df;})[_0x1fbc('0x28')](respondWithFilteredResult(_0x21716c,_0x249fe9))[_0x1fbc('0x4a')](handleError(_0x21716c,null));};exports['show']=function(_0x4d3d89,_0x2e3e9f){var _0x1df941={'raw':![],'where':{'id':_0x4d3d89['params']['id']}},_0x2a34f9={};_0x2a34f9[_0x1fbc('0x32')]=_[_0x1fbc('0x35')](db[_0x1fbc('0x30')]['rawAttributes']);_0x2a34f9[_0x1fbc('0x34')]=_[_0x1fbc('0x35')](_0x4d3d89[_0x1fbc('0x34')]);_0x2a34f9[_0x1fbc('0x36')]=_[_0x1fbc('0x37')](_0x2a34f9['model'],_0x2a34f9['query']);_0x1df941[_0x1fbc('0x38')]=_[_0x1fbc('0x37')](_0x2a34f9['model'],qs['fields'](_0x4d3d89[_0x1fbc('0x34')]['fields']));_0x1df941[_0x1fbc('0x38')]=_0x1df941[_0x1fbc('0x38')][_0x1fbc('0x3a')]?_0x1df941[_0x1fbc('0x38')]:_0x2a34f9[_0x1fbc('0x32')];if(_0x4d3d89[_0x1fbc('0x34')][_0x1fbc('0x46')]){_0x1df941[_0x1fbc('0x47')]=[{'all':!![]}];}_0x1df941=_[_0x1fbc('0x42')]({},_0x1df941,_0x4d3d89[_0x1fbc('0x45')]);return db[_0x1fbc('0x30')][_0x1fbc('0x4b')](_0x1df941)['then'](handleEntityNotFound(_0x2e3e9f,null))[_0x1fbc('0x28')](respondWithResult(_0x2e3e9f,null))['catch'](handleError(_0x2e3e9f,null));};exports[_0x1fbc('0x4c')]=function(_0x180c91,_0xee8d9){return db[_0x1fbc('0x30')]['create'](_0x180c91[_0x1fbc('0x4d')],{})['then'](function(_0x20b0d7){var _0x50b466=_0x180c91[_0x1fbc('0x4e')][_0x1fbc('0x2a')]({'plain':!![]});if(!_0x50b466)throw new Error(_0x1fbc('0x4f'));if(_0x50b466[_0x1fbc('0x50')]===_0x1fbc('0x4e')){var _0x5d4690=_0x20b0d7[_0x1fbc('0x2a')]({'plain':!![]});var _0x43fb57=_0x1fbc('0x2b');return db[_0x1fbc('0x51')]['find']({'where':{'name':_0x43fb57,'userProfileId':_0x50b466['userProfileId']},'raw':!![]})[_0x1fbc('0x28')](function(_0xd1008c){if(_0xd1008c&&_0xd1008c[_0x1fbc('0x52')]===0x0){return db['UserProfileResource']['create']({'name':_0x5d4690[_0x1fbc('0x33')],'resourceId':_0x5d4690['id'],'type':_0xd1008c[_0x1fbc('0x33')],'sectionId':_0xd1008c['id']},{})[_0x1fbc('0x28')](function(){return _0x20b0d7;});}else{return _0x20b0d7;}})[_0x1fbc('0x4a')](function(_0x5b8609){logger['error'](_0x1fbc('0x53'),_0x5b8609);throw _0x5b8609;});}return _0x20b0d7;})[_0x1fbc('0x28')](respondWithResult(_0xee8d9,0xc9))[_0x1fbc('0x4a')](handleError(_0xee8d9,null));};exports[_0x1fbc('0x27')]=function(_0x2c8a1a,_0x225377){if(_0x2c8a1a['body']['id']){delete _0x2c8a1a[_0x1fbc('0x4d')]['id'];}return db['CmList']['find']({'where':{'id':_0x2c8a1a[_0x1fbc('0x54')]['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x225377,null))['then'](saveUpdates(_0x2c8a1a[_0x1fbc('0x4d')],null))[_0x1fbc('0x28')](respondWithResult(_0x225377,null))[_0x1fbc('0x4a')](handleError(_0x225377,null));};exports['destroy']=function(_0x119160,_0x1e352e){return db['CmList']['find']({'where':{'id':_0x119160[_0x1fbc('0x54')]['id']}})['then'](handleEntityNotFound(_0x1e352e,null))[_0x1fbc('0x28')](removeEntity(_0x1e352e,null))[_0x1fbc('0x4a')](handleError(_0x1e352e,null));};exports[_0x1fbc('0x55')]=function(_0x4e4b51,_0x432dc0){return db[_0x1fbc('0x30')]['describe']()[_0x1fbc('0x28')](respondWithResult(_0x432dc0,null))[_0x1fbc('0x4a')](handleError(_0x432dc0,null));};exports['addDisposition']=function(_0x21b34e,_0x2d9494,_0x4b61e1){if(_0x21b34e[_0x1fbc('0x4d')]['id']){delete _0x21b34e[_0x1fbc('0x4d')]['id'];}return db['CmList'][_0x1fbc('0x4b')]({'where':{'id':_0x21b34e[_0x1fbc('0x54')]['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x2d9494,null))[_0x1fbc('0x28')](function(_0x243045){if(_0x243045){_0x21b34e[_0x1fbc('0x4d')][_0x1fbc('0x56')]=_0x243045['id'];return db['Disposition'][_0x1fbc('0x4c')](_0x21b34e[_0x1fbc('0x4d')]);}})[_0x1fbc('0x28')](respondWithResult(_0x2d9494,null))['catch'](handleError(_0x2d9494,null));};exports[_0x1fbc('0x57')]=function(_0x5ca045,_0x5a5848,_0x5e8d02){var _0x394d3d={'raw':![],'where':{}};var _0x4ac40d={};var _0x427f74={'count':0x0,'rows':[]};return db[_0x1fbc('0x30')]['findOne']({'where':{'id':_0x5ca045[_0x1fbc('0x54')]['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x5a5848,null))[_0x1fbc('0x28')](function(_0xaae69e){if(_0xaae69e){_0x4ac40d[_0x1fbc('0x32')]=_[_0x1fbc('0x35')](db[_0x1fbc('0x58')][_0x1fbc('0x59')]);_0x4ac40d['query']=_[_0x1fbc('0x35')](_0x5ca045['query']);_0x4ac40d[_0x1fbc('0x36')]=_['intersection'](_0x4ac40d[_0x1fbc('0x32')],_0x4ac40d[_0x1fbc('0x34')]);_0x394d3d[_0x1fbc('0x38')]=_[_0x1fbc('0x37')](_0x4ac40d[_0x1fbc('0x32')],qs[_0x1fbc('0x39')](_0x5ca045['query'][_0x1fbc('0x39')]));_0x394d3d[_0x1fbc('0x38')]=_0x394d3d[_0x1fbc('0x38')][_0x1fbc('0x3a')]?_0x394d3d['attributes']:_0x4ac40d['model'];if(!_0x5ca045[_0x1fbc('0x34')][_0x1fbc('0x3b')]('nolimit')){_0x394d3d[_0x1fbc('0x22')]=qs[_0x1fbc('0x22')](_0x5ca045[_0x1fbc('0x34')][_0x1fbc('0x22')]);_0x394d3d[_0x1fbc('0x3d')]=qs['offset'](_0x5ca045['query'][_0x1fbc('0x3d')]);}_0x394d3d[_0x1fbc('0x3e')]=qs[_0x1fbc('0x3f')](_0x5ca045[_0x1fbc('0x34')]['sort']);_0x394d3d['where']=qs[_0x1fbc('0x36')](_['pick'](_0x5ca045[_0x1fbc('0x34')],_0x4ac40d['filters']));_0x394d3d[_0x1fbc('0x40')][_0x1fbc('0x56')]=_0xaae69e['id'];if(_0x5ca045['query'][_0x1fbc('0x44')]){_0x394d3d['where']=_[_0x1fbc('0x42')](_0x394d3d[_0x1fbc('0x40')],{'$or':_[_0x1fbc('0x2f')](_0x394d3d[_0x1fbc('0x38')],function(_0x1b499a){var _0x359a39={};_0x359a39[_0x1b499a]={'$like':'%'+_0x5ca045[_0x1fbc('0x34')][_0x1fbc('0x44')]+'%'};return _0x359a39;})});}_0x394d3d=_[_0x1fbc('0x42')]({},_0x394d3d,_0x5ca045[_0x1fbc('0x45')]);return db['Disposition'][_0x1fbc('0x23')]({'where':_0x394d3d[_0x1fbc('0x40')]})[_0x1fbc('0x28')](function(_0x3edf36){_0x427f74[_0x1fbc('0x23')]=_0x3edf36;if(_0x5ca045[_0x1fbc('0x34')][_0x1fbc('0x46')]){_0x394d3d[_0x1fbc('0x47')]=[{'all':!![]}];}return db[_0x1fbc('0x58')]['findAll'](_0x394d3d);})['then'](function(_0x3de46b){_0x427f74[_0x1fbc('0x49')]=_0x3de46b;return _0x427f74;});}})[_0x1fbc('0x28')](respondWithFilteredResult(_0x5a5848,_0x394d3d))['catch'](handleError(_0x5a5848,null));};exports[_0x1fbc('0x5a')]=function(_0x25b690,_0x533390,_0x468b82){return db[_0x1fbc('0x30')]['find']({'where':{'id':_0x25b690[_0x1fbc('0x54')]['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x533390,null))[_0x1fbc('0x28')](function(_0xda67fe){if(_0xda67fe){return _0xda67fe[_0x1fbc('0x5a')](_0x25b690[_0x1fbc('0x34')][_0x1fbc('0x5b')]);}})['then'](respondWithStatusCode(_0x533390,null))[_0x1fbc('0x4a')](handleError(_0x533390,null));};exports[_0x1fbc('0x5c')]=function(_0x165dad,_0x3a8380,_0x127a97){return db[_0x1fbc('0x30')][_0x1fbc('0x4b')]({'where':{'id':_0x165dad[_0x1fbc('0x54')]['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x3a8380,null))[_0x1fbc('0x28')](function(_0x5bb297){if(_0x5bb297){var _0xa1d13=[];var _0x1bedf3={'success':[],'errors':[]};return db[_0x1fbc('0x5d')][_0x1fbc('0x55')]()['then'](function(_0xa7bf82){if(_0x165dad[_0x1fbc('0x4d')][_0x1fbc('0x5e')]&&_[_0x1fbc('0x5f')](_0x165dad[_0x1fbc('0x4d')][_0x1fbc('0x5e')])){if(_0x165dad[_0x1fbc('0x4d')][_0x1fbc('0x5e')][_0x1fbc('0x3a')]){_0x165dad[_0x1fbc('0x4d')]['tags']=_0x165dad[_0x1fbc('0x4d')]['tags']['join'](';')+';';}else{_0x165dad[_0x1fbc('0x4d')]['tags']=null;}}else{_0x165dad[_0x1fbc('0x4d')][_0x1fbc('0x5e')]=null;}if(_0x165dad[_0x1fbc('0x4d')]&&_[_0x1fbc('0x5f')](_0x165dad['body'])){for(var _0x2e3300=0x0;_0x2e3300<_0x165dad[_0x1fbc('0x4d')][_0x1fbc('0x3a')];_0x2e3300+=0x1){_0x165dad[_0x1fbc('0x4d')][_0x2e3300]['ListId']=_0x165dad[_0x1fbc('0x54')]['id'];_0xa1d13['push'](_0x165dad[_0x1fbc('0x4d')][_0x2e3300]);}return BPromise['each'](_0xa1d13,function(_0x58340f){return db[_0x1fbc('0x5d')]['create'](_[_0x1fbc('0x60')](_0x58340f,[_0x1fbc('0x5b'),'id'])||{},{'fields':_['keys'](_0xa7bf82),'raw':!![]})[_0x1fbc('0x28')](function(_0x51b2b5){_0x1bedf3['success'][_0x1fbc('0x61')](_0x51b2b5[_0x1fbc('0x62')]);})['catch'](function(_0x6d524f){_0x1bedf3['errors'][_0x1fbc('0x61')]({'data':_0x58340f,'error':_0x6d524f[_0x1fbc('0x63')]});});})[_0x1fbc('0x28')](function(_0x847f38){return _0x1bedf3;})[_0x1fbc('0x4a')](function(_0x50e8ac){return _0x50e8ac;});}else{_0x3a8380[_0x1fbc('0x1f')](0x190)[_0x1fbc('0x25')]({'message':_0x1fbc('0x64')});}});}})[_0x1fbc('0x28')](respondWithResult(_0x3a8380,null))[_0x1fbc('0x4a')](handleError(_0x3a8380,null));};exports['getContacts']=function(_0x404285,_0x2f39fa,_0x586c3e){var _0x343181;return db[_0x1fbc('0x30')][_0x1fbc('0x4b')]({'where':{'id':_0x404285[_0x1fbc('0x54')]['id']},'include':[{'model':db[_0x1fbc('0x65')],'as':_0x1fbc('0x66')}]})[_0x1fbc('0x28')](handleEntityNotFound(_0x2f39fa,null))[_0x1fbc('0x28')](function(_0x4cc2b0){if(_0x4cc2b0){_0x343181=_0x4cc2b0;return db[_0x1fbc('0x5d')][_0x1fbc('0x59')];}})[_0x1fbc('0x28')](function(_0x7cf460){if(_0x7cf460){var _0x382671={};var _0x33474a={};_0x33474a['model']=_[_0x1fbc('0x67')](_[_0x1fbc('0x35')](_0x7cf460),_[_0x1fbc('0x2f')](_0x343181['CustomFields'],function(_0x216711){return util['format'](_0x1fbc('0x68'),_0x216711['id']);}));_0x33474a[_0x1fbc('0x34')]=_[_0x1fbc('0x35')](_0x404285['query']);_0x33474a['filters']=_['intersection'](_0x33474a['model'],_0x33474a[_0x1fbc('0x34')]);_0x382671[_0x1fbc('0x38')]=_[_0x1fbc('0x37')](_0x33474a['model'],qs[_0x1fbc('0x39')](_0x404285['query'][_0x1fbc('0x39')]));_0x382671[_0x1fbc('0x38')]=_0x382671[_0x1fbc('0x38')][_0x1fbc('0x3a')]?_0x382671[_0x1fbc('0x38')]:_0x33474a[_0x1fbc('0x32')];if(!_0x404285[_0x1fbc('0x34')][_0x1fbc('0x3b')]('nolimit')){_0x382671[_0x1fbc('0x22')]=qs[_0x1fbc('0x22')](_0x404285[_0x1fbc('0x34')][_0x1fbc('0x22')]);_0x382671[_0x1fbc('0x3d')]=qs[_0x1fbc('0x3d')](_0x404285[_0x1fbc('0x34')]['offset']);}_0x382671[_0x1fbc('0x3e')]=qs['sort'](_0x404285[_0x1fbc('0x34')][_0x1fbc('0x3f')]);_0x382671['where']=qs[_0x1fbc('0x36')](_[_0x1fbc('0x41')](_0x404285[_0x1fbc('0x34')],_0x33474a[_0x1fbc('0x36')]));_0x382671[_0x1fbc('0x69')]=!![];if(_0x404285[_0x1fbc('0x34')][_0x1fbc('0x44')]){_0x382671[_0x1fbc('0x40')]=_[_0x1fbc('0x42')](_0x382671[_0x1fbc('0x40')],{'$or':_[_0x1fbc('0x2f')](_0x382671[_0x1fbc('0x38')],function(_0x40ad52){var _0x4e40c5={};_0x4e40c5[_0x40ad52]={'$like':'%'+_0x404285[_0x1fbc('0x34')][_0x1fbc('0x44')]+'%'};return _0x4e40c5;})});}_0x382671=_[_0x1fbc('0x42')]({},_0x382671,_0x404285[_0x1fbc('0x45')]);return _0x343181[_0x1fbc('0x6a')](_0x382671);}})[_0x1fbc('0x28')](respondWithResult(_0x2f39fa,null))['catch'](handleError(_0x2f39fa,null));};exports['getContactsCsv']=function(_0x30325b,_0x5e9260,_0x41b7d6){var _0x52b44d;return db[_0x1fbc('0x30')][_0x1fbc('0x4b')]({'where':{'id':_0x30325b[_0x1fbc('0x54')]['id']},'include':[{'model':db[_0x1fbc('0x65')],'as':_0x1fbc('0x66')}]})[_0x1fbc('0x28')](handleEntityNotFound(_0x5e9260,null))[_0x1fbc('0x28')](function(_0x305702){if(_0x305702){_0x52b44d=_0x305702;return db[_0x1fbc('0x5d')][_0x1fbc('0x59')];}})[_0x1fbc('0x28')](function(_0x5ae5cd){if(_0x5ae5cd){var _0x56dfc8={};var _0xacbb97={};_0xacbb97[_0x1fbc('0x32')]=_[_0x1fbc('0x67')](_[_0x1fbc('0x35')](_0x5ae5cd),_[_0x1fbc('0x2f')](_0x52b44d[_0x1fbc('0x66')],function(_0xea0a6d){return util[_0x1fbc('0x6b')](_0x1fbc('0x68'),_0xea0a6d['id']);}));_0xacbb97[_0x1fbc('0x34')]=_[_0x1fbc('0x35')](_0x30325b[_0x1fbc('0x34')]);_0xacbb97[_0x1fbc('0x36')]=_[_0x1fbc('0x37')](_0xacbb97[_0x1fbc('0x32')],_0xacbb97['query']);_0x56dfc8['attributes']=_[_0x1fbc('0x37')](_0xacbb97['model'],qs[_0x1fbc('0x39')](_0x30325b['query']['fields']));_0x56dfc8[_0x1fbc('0x38')]=_0x56dfc8[_0x1fbc('0x38')][_0x1fbc('0x3a')]?_0x56dfc8[_0x1fbc('0x38')]:_0xacbb97[_0x1fbc('0x32')];if(!_0x30325b['query'][_0x1fbc('0x3b')](_0x1fbc('0x3c'))){_0x56dfc8[_0x1fbc('0x22')]=qs['limit'](_0x30325b[_0x1fbc('0x34')]['limit']);_0x56dfc8['offset']=qs[_0x1fbc('0x3d')](_0x30325b[_0x1fbc('0x34')][_0x1fbc('0x3d')]);}_0x56dfc8['order']=qs[_0x1fbc('0x3f')](_0x30325b[_0x1fbc('0x34')][_0x1fbc('0x3f')]);_0x56dfc8['where']=qs[_0x1fbc('0x36')](_['pick'](_0x30325b['query'],_0xacbb97[_0x1fbc('0x36')]));_0x56dfc8[_0x1fbc('0x69')]=!![];if(_0x30325b['query'][_0x1fbc('0x44')]){_0x56dfc8[_0x1fbc('0x40')]=_[_0x1fbc('0x42')](_0x56dfc8[_0x1fbc('0x40')],{'$or':_['map'](_0x56dfc8['attributes'],function(_0x36118a){var _0x350d32={};_0x350d32[_0x36118a]={'$like':'%'+_0x30325b[_0x1fbc('0x34')][_0x1fbc('0x44')]+'%'};return _0x350d32;})});}_0x56dfc8=_[_0x1fbc('0x42')]({},_0x56dfc8,_0x30325b['options']);return _0x52b44d[_0x1fbc('0x6a')](_0x56dfc8);}})[_0x1fbc('0x28')](function(_0x477c10){if(!_[_0x1fbc('0x6c')](_0x477c10)){var _0x4dbc71=toCsv(_0x477c10);var _0x338c8d=Date[_0x1fbc('0x6d')]();fs[_0x1fbc('0x6e')](util['format'](_0x1fbc('0x6f'),_0x52b44d['id'],_0x338c8d),_0x4dbc71);_0x5e9260[_0x1fbc('0x70')](_0x1fbc('0x71'),'attachment;\x20filename='+util[_0x1fbc('0x6b')]('list_%d_%s.csv',_0x52b44d['id'],_0x338c8d));_0x5e9260[_0x1fbc('0x70')](_0x1fbc('0x72'),_0x1fbc('0x73'));return _0x5e9260[_0x1fbc('0x74')](util['format']('/tmp/list_%d_%s.csv',_0x52b44d['id'],_0x338c8d));}else{return _0x5e9260[_0x1fbc('0x1e')](0xcc);}})[_0x1fbc('0x4a')](handleError(_0x5e9260,null));};exports[_0x1fbc('0x75')]=function(_0x16db0a,_0x478d6a,_0x47309d){var _0x2b9476;delete _0x16db0a[_0x1fbc('0x4d')]['id'];return db[_0x1fbc('0x30')][_0x1fbc('0x76')]({'where':{'id':_0x16db0a[_0x1fbc('0x54')]['id']}})['then'](handleEntityNotFound(_0x478d6a,null))[_0x1fbc('0x28')](function(_0x5d5d05){if(_0x5d5d05){return db['sequelize']['transaction'](function(_0x4189bf){return db['CmCustomField'][_0x1fbc('0x4c')](_0x16db0a[_0x1fbc('0x4d')],{'transaction':_0x4189bf})[_0x1fbc('0x28')](function(_0x1a0607){_0x2b9476=_0x1a0607;return _0x5d5d05[_0x1fbc('0x77')](_0x1a0607,{'transaction':_0x4189bf});})[_0x1fbc('0x28')](function(){var _0x965c30={'type':db['Sequelize'][_0x1fbc('0x78')],'transaction':_0x4189bf};switch(_0x16db0a[_0x1fbc('0x4d')][_0x1fbc('0x31')]){case _0x1fbc('0x79'):_0x965c30[_0x1fbc('0x31')]=db['Sequelize'][_0x1fbc('0x78')];break;case _0x1fbc('0x7a'):_0x965c30[_0x1fbc('0x31')]=db['Sequelize']['INTEGER'];break;case _0x1fbc('0x7b'):_0x965c30[_0x1fbc('0x31')]=db[_0x1fbc('0x7c')][_0x1fbc('0x7d')];_0x965c30['defaultValue']=![];break;default:}return db['sequelize'][_0x1fbc('0x7e')][_0x1fbc('0x7f')](_0x1fbc('0x80'),util[_0x1fbc('0x6b')](_0x1fbc('0x81'),_0x2b9476['id']),_0x965c30);})[_0x1fbc('0x28')](function(){return _0x2b9476;});});}})[_0x1fbc('0x28')](respondWithResult(_0x478d6a,null))[_0x1fbc('0x4a')](handleError(_0x478d6a,null));};exports['getCustomFields']=function(_0x73475,_0x2dafa8,_0x5d3c20){var _0x13f34c={};var _0x1f5493={};var _0x8aedcf;var _0x11d5da;return db['CmList'][_0x1fbc('0x76')]({'where':{'id':_0x73475[_0x1fbc('0x54')]['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x2dafa8,null))[_0x1fbc('0x28')](function(_0x5daee2){if(_0x5daee2){_0x8aedcf=_0x5daee2;_0x1f5493[_0x1fbc('0x32')]=_[_0x1fbc('0x35')](db['CmCustomField'][_0x1fbc('0x59')]);_0x1f5493[_0x1fbc('0x34')]=_['keys'](_0x73475[_0x1fbc('0x34')]);_0x1f5493[_0x1fbc('0x36')]=_['intersection'](_0x1f5493[_0x1fbc('0x32')],_0x1f5493[_0x1fbc('0x34')]);_0x13f34c[_0x1fbc('0x38')]=_[_0x1fbc('0x37')](_0x1f5493[_0x1fbc('0x32')],qs['fields'](_0x73475[_0x1fbc('0x34')]['fields']));_0x13f34c[_0x1fbc('0x38')]=_0x13f34c[_0x1fbc('0x38')][_0x1fbc('0x3a')]?_0x13f34c[_0x1fbc('0x38')]:_0x1f5493[_0x1fbc('0x32')];_0x13f34c[_0x1fbc('0x3e')]=qs[_0x1fbc('0x3f')](_0x73475[_0x1fbc('0x34')]['sort']);_0x13f34c['where']=qs['filters'](_['pick'](_0x73475[_0x1fbc('0x34')],_0x1f5493[_0x1fbc('0x36')]));_0x13f34c[_0x1fbc('0x40')]=_['merge'](_0x13f34c[_0x1fbc('0x40')],{'$or':[{'ListId':_0x5daee2['id']},{'ListId':null}]});if(_0x73475[_0x1fbc('0x34')][_0x1fbc('0x44')]){_0x13f34c[_0x1fbc('0x40')]=_[_0x1fbc('0x42')](_0x13f34c['where'],{'$or':_[_0x1fbc('0x2f')](_0x13f34c[_0x1fbc('0x38')],function(_0x1008a9){var _0x5b1c77={};_0x5b1c77[_0x1008a9]={'$like':'%'+_0x73475['query'][_0x1fbc('0x44')]+'%'};return _0x5b1c77;})});}_0x13f34c=_[_0x1fbc('0x42')]({},_0x13f34c,_0x73475[_0x1fbc('0x45')]);return db[_0x1fbc('0x65')][_0x1fbc('0x82')](_0x13f34c);}})[_0x1fbc('0x28')](respondWithResult(_0x2dafa8,null))[_0x1fbc('0x4a')](handleError(_0x2dafa8,null));};exports['addAgents']=function(_0x4d255b,_0x39db64,_0x15939b){return db[_0x1fbc('0x30')][_0x1fbc('0x4b')]({'where':{'id':_0x4d255b['params']['id']}})[_0x1fbc('0x28')](handleEntityNotFound(_0x39db64,null))[_0x1fbc('0x28')](function(_0x4e8ea3){if(_0x4e8ea3){return _0x4e8ea3[_0x1fbc('0x83')](_0x4d255b[_0x1fbc('0x4d')][_0x1fbc('0x5b')],_[_0x1fbc('0x60')](_0x4d255b['body'],[_0x1fbc('0x5b'),'id'])||{})[_0x1fbc('0x84')](function(_0x17cd6d){for(var _0x159bd7=0x0;_0x159bd7<_0x4d255b[_0x1fbc('0x4d')][_0x1fbc('0x5b')]['length'];_0x159bd7+=0x1){socket[_0x1fbc('0x85')](_0x1fbc('0x86'),{'UserId':Number(_0x4d255b[_0x1fbc('0x4d')]['ids'][_0x159bd7]),'CmListId':Number(_0x4d255b[_0x1fbc('0x54')]['id'])});}return _0x17cd6d;});}})[_0x1fbc('0x28')](respondWithResult(_0x39db64,null))['catch'](handleError(_0x39db64,null));};exports[_0x1fbc('0x87')]=function(_0x591a9f,_0x56c30e,_0x1c0d91){return db[_0x1fbc('0x30')][_0x1fbc('0x4b')]({'where':{'id':_0x591a9f[_0x1fbc('0x54')]['id']}})['then'](handleEntityNotFound(_0x56c30e,null))[_0x1fbc('0x28')](function(_0x4e3593){if(_0x4e3593){return _0x4e3593[_0x1fbc('0x87')](_0x591a9f[_0x1fbc('0x34')][_0x1fbc('0x5b')])[_0x1fbc('0x28')](function(){if(_[_0x1fbc('0x5f')](_0x591a9f[_0x1fbc('0x34')][_0x1fbc('0x5b')])){for(var _0x5b9222=0x0;_0x5b9222<_0x591a9f[_0x1fbc('0x34')]['ids'][_0x1fbc('0x3a')];_0x5b9222+=0x1){socket[_0x1fbc('0x85')]('userCmList:remove',{'UserId':Number(_0x591a9f[_0x1fbc('0x34')][_0x1fbc('0x5b')][_0x5b9222]),'CmListId':Number(_0x591a9f['params']['id'])});}}else{socket[_0x1fbc('0x85')](_0x1fbc('0x88'),{'UserId':Number(_0x591a9f[_0x1fbc('0x34')][_0x1fbc('0x5b')]),'CmListId':Number(_0x591a9f[_0x1fbc('0x54')]['id'])});}});}})[_0x1fbc('0x28')](respondWithStatusCode(_0x56c30e,null))[_0x1fbc('0x4a')](handleError(_0x56c30e,null));};exports[_0x1fbc('0x89')]=function(_0x12a4e4,_0x325f07,_0x4efcb7){var _0x564720={};var _0x1cbc62={};var _0x31e2fe;var _0x3e8aba;return db['CmList'][_0x1fbc('0x76')]({'where':{'id':_0x12a4e4[_0x1fbc('0x54')]['id']}})['then'](handleEntityNotFound(_0x325f07,null))[_0x1fbc('0x28')](function(_0x3cf851){if(_0x3cf851){_0x31e2fe=_0x3cf851;_0x1cbc62[_0x1fbc('0x32')]=_[_0x1fbc('0x35')](db['User']['rawAttributes']);_0x1cbc62[_0x1fbc('0x34')]=_['keys'](_0x12a4e4[_0x1fbc('0x34')]);_0x1cbc62['filters']=_[_0x1fbc('0x37')](_0x1cbc62[_0x1fbc('0x32')],_0x1cbc62[_0x1fbc('0x34')]);_0x564720[_0x1fbc('0x38')]=_[_0x1fbc('0x37')](_0x1cbc62[_0x1fbc('0x32')],qs[_0x1fbc('0x39')](_0x12a4e4[_0x1fbc('0x34')][_0x1fbc('0x39')]));_0x564720['attributes']=_0x564720['attributes'][_0x1fbc('0x3a')]?_0x564720['attributes']:_0x1cbc62[_0x1fbc('0x32')];_0x564720[_0x1fbc('0x3e')]=qs['sort'](_0x12a4e4['query']['sort']);_0x564720[_0x1fbc('0x40')]=qs[_0x1fbc('0x36')](_['pick'](_0x12a4e4['query'],_0x1cbc62[_0x1fbc('0x36')]));if(_0x12a4e4['query'][_0x1fbc('0x44')]){_0x564720[_0x1fbc('0x40')]=_[_0x1fbc('0x42')](_0x564720[_0x1fbc('0x40')],{'$or':_['map'](_0x564720[_0x1fbc('0x38')],function(_0x5c1b28){var _0x57e281={};_0x57e281[_0x5c1b28]={'$like':'%'+_0x12a4e4[_0x1fbc('0x34')]['filter']+'%'};return _0x57e281;})});}_0x564720=_['merge']({},_0x564720,_0x12a4e4['options']);return _0x31e2fe['getAgents'](_0x564720);}})[_0x1fbc('0x28')](function(_0x16f806){if(_0x16f806){_0x3e8aba=_0x16f806[_0x1fbc('0x3a')];if(!_0x12a4e4[_0x1fbc('0x34')][_0x1fbc('0x3b')](_0x1fbc('0x3c'))){_0x564720[_0x1fbc('0x22')]=qs[_0x1fbc('0x22')](_0x12a4e4[_0x1fbc('0x34')]['limit']);_0x564720[_0x1fbc('0x3d')]=qs['offset'](_0x12a4e4['query'][_0x1fbc('0x3d')]);}return _0x31e2fe[_0x1fbc('0x89')](_0x564720);}})['then'](function(_0x329c89){if(_0x329c89){return _0x329c89?{'count':_0x3e8aba,'rows':_0x329c89}:null;}})[_0x1fbc('0x28')](respondWithResult(_0x325f07,null))[_0x1fbc('0x4a')](handleError(_0x325f07,null));};