34765c7ea5c8da10d3f6141fdcd3bb4f9b8191de
[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 _0xbf3d=['user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','ListId','Disposition','getDispositions','findOne','nolimit','order','removeDispositions','ids','addContacts','tags','isArray','join','push','each','omit','dataValues','errors','message','Malformed\x20request\x20syntax','getContacts','CmCustomField','CustomFields','CmContact','cf_%d','raw','getContactsCsv','OrderBy','select','cm_contacts','c.ListId\x20=\x20?','c.deletedAt\x20is\x20null','distinct','field','item','from','cm_contact_has_items','ItemTypeId\x20=\x20?','CmContactId\x20=\x20c.id','additionalPhone_','description','description_additionalPhone_','toString','isEmpty','now','writeFileSync','format','/tmp/list_%d_%s.csv','setHeader','Content-disposition','attachment;\x20filename=','list_%d_%s.csv','text/csv','addCustomField','sequelize','transaction','addCustomFields','Sequelize','text','TEXT','number','INTEGER','switch','BOOLEAN','queryInterface','cf_%s','getCustomFields','findAndCountAll','getGlobalCustomFields','addAgents','spread','emit','userCmList:save','removeAgents','userCmList:remove','User','getAgents','info','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','redis','localhost','socket.io-emitter','./cmList.socket','register','sendStatus','status','end','json','offset','limit','undefined','count','set','apply','update','destroy','then','Lists','UserProfileResource','error','stack','index','map','CmList','rawAttributes','type','key','model','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','pick','filter','include','findAll','rows','catch','show','includeAll','merge','options','find','create','body'];(function(_0x3b0e0c,_0x3f3e40){var _0x5baa46=function(_0x54bc82){while(--_0x54bc82){_0x3b0e0c['push'](_0x3b0e0c['shift']());}};_0x5baa46(++_0x3f3e40);}(_0xbf3d,0xfb));var _0xdbf3=function(_0x3ae690,_0x406b36){_0x3ae690=_0x3ae690-0x0;var _0x3dd33c=_0xbf3d[_0x3ae690];return _0x3dd33c;};'use strict';var emlformat=require(_0xdbf3('0x0'));var rimraf=require(_0xdbf3('0x1'));var zipdir=require(_0xdbf3('0x2'));var jsonpatch=require(_0xdbf3('0x3'));var rp=require(_0xdbf3('0x4'));var moment=require(_0xdbf3('0x5'));var BPromise=require(_0xdbf3('0x6'));var Mustache=require('mustache');var util=require('util');var path=require(_0xdbf3('0x7'));var sox=require(_0xdbf3('0x8'));var csv=require(_0xdbf3('0x9'));var ejs=require(_0xdbf3('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xdbf3('0xb'));var squel=require(_0xdbf3('0xc'));var crypto=require(_0xdbf3('0xd'));var jsforce=require(_0xdbf3('0xe'));var deskjs=require(_0xdbf3('0xf'));var toCsv=require(_0xdbf3('0x9'));var querystring=require(_0xdbf3('0x10'));var Papa=require(_0xdbf3('0x11'));var Redis=require(_0xdbf3('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xdbf3('0x13'));var as=require(_0xdbf3('0x14'));var hardwareService=require(_0xdbf3('0x15'));var logger=require(_0xdbf3('0x16'))(_0xdbf3('0x17'));var utils=require(_0xdbf3('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0xdbf3('0x19'));var db=require('../../mysqldb')['db'];var csv_results;config[_0xdbf3('0x1a')]=_['defaults'](config['redis'],{'host':_0xdbf3('0x1b'),'port':0x18eb});var socket=require(_0xdbf3('0x1c'))(new Redis(config[_0xdbf3('0x1a')]));require(_0xdbf3('0x1d'))[_0xdbf3('0x1e')](socket);function respondWithStatusCode(_0x3c9bae,_0x7df5ff){_0x7df5ff=_0x7df5ff||0xcc;return function(_0xf1a052){if(_0xf1a052){return _0x3c9bae[_0xdbf3('0x1f')](_0x7df5ff);}return _0x3c9bae[_0xdbf3('0x20')](_0x7df5ff)[_0xdbf3('0x21')]();};}function respondWithResult(_0x435fb9,_0x3ddbe1){_0x3ddbe1=_0x3ddbe1||0xc8;return function(_0x13080f){if(_0x13080f){return _0x435fb9[_0xdbf3('0x20')](_0x3ddbe1)[_0xdbf3('0x22')](_0x13080f);}};}function respondWithFilteredResult(_0x1be8f5,_0x36b1d4){return function(_0x2cc3f8){if(_0x2cc3f8){var _0x2564ee=typeof _0x36b1d4[_0xdbf3('0x23')]==='undefined'&&typeof _0x36b1d4[_0xdbf3('0x24')]===_0xdbf3('0x25');var _0x3ab130=_0x2cc3f8[_0xdbf3('0x26')];var _0x45889d=_0x2564ee?0x0:_0x36b1d4[_0xdbf3('0x23')];var _0x4a741c=_0x2564ee?_0x2cc3f8[_0xdbf3('0x26')]:_0x36b1d4[_0xdbf3('0x23')]+_0x36b1d4[_0xdbf3('0x24')];var _0x3f4ebb;if(_0x4a741c>=_0x3ab130){_0x4a741c=_0x3ab130;_0x3f4ebb=0xc8;}else{_0x3f4ebb=0xce;}_0x1be8f5[_0xdbf3('0x20')](_0x3f4ebb);return _0x1be8f5[_0xdbf3('0x27')]('Content-Range',_0x45889d+'-'+_0x4a741c+'/'+_0x3ab130)[_0xdbf3('0x22')](_0x2cc3f8);}return null;};}function patchUpdates(_0x430eff){return function(_0x53deba){try{jsonpatch[_0xdbf3('0x28')](_0x53deba,_0x430eff,!![]);}catch(_0x574dde){return BPromise['reject'](_0x574dde);}return _0x53deba['save']();};}function saveUpdates(_0x3d5609,_0x537b04){return function(_0x1e6ae0){if(_0x1e6ae0){return _0x1e6ae0[_0xdbf3('0x29')](_0x3d5609)['then'](function(_0x33fc5e){return _0x33fc5e;});}return null;};}function removeEntity(_0x413533,_0x524ce7){return function(_0x289c4d){if(_0x289c4d){return _0x289c4d[_0xdbf3('0x2a')]()[_0xdbf3('0x2b')](function(){var _0x2ffaba=_0x289c4d['get']({'plain':!![]});var _0x51dc84=_0xdbf3('0x2c');return db[_0xdbf3('0x2d')][_0xdbf3('0x2a')]({'where':{'type':_0x51dc84,'resourceId':_0x2ffaba['id']}})['then'](function(){return _0x289c4d;});})[_0xdbf3('0x2b')](function(){_0x413533[_0xdbf3('0x20')](0xcc)[_0xdbf3('0x21')]();});}};}function handleEntityNotFound(_0x30e009,_0x3bf1fe){return function(_0x31abdf){if(!_0x31abdf){_0x30e009['sendStatus'](0x194);}return _0x31abdf;};}function handleError(_0x4c3133,_0x3b5110){_0x3b5110=_0x3b5110||0x1f4;return function(_0x1d0c57){logger[_0xdbf3('0x2e')](_0x1d0c57[_0xdbf3('0x2f')]);if(_0x1d0c57['name']){delete _0x1d0c57['name'];}_0x4c3133[_0xdbf3('0x20')](_0x3b5110)['send'](_0x1d0c57);};}exports[_0xdbf3('0x30')]=function(_0x43d8bb,_0x1bd638){var _0x492d87={},_0x38b10c={},_0x3869e8={'count':0x0,'rows':[]};var _0x475854=_[_0xdbf3('0x31')](db[_0xdbf3('0x32')][_0xdbf3('0x33')],function(_0x2338ca){return{'name':_0x2338ca['fieldName'],'type':_0x2338ca[_0xdbf3('0x34')][_0xdbf3('0x35')]};});_0x38b10c[_0xdbf3('0x36')]=_[_0xdbf3('0x31')](_0x475854,_0xdbf3('0x37'));_0x38b10c[_0xdbf3('0x38')]=_[_0xdbf3('0x39')](_0x43d8bb[_0xdbf3('0x38')]);_0x38b10c[_0xdbf3('0x3a')]=_[_0xdbf3('0x3b')](_0x38b10c[_0xdbf3('0x36')],_0x38b10c[_0xdbf3('0x38')]);_0x492d87[_0xdbf3('0x3c')]=_[_0xdbf3('0x3b')](_0x38b10c[_0xdbf3('0x36')],qs[_0xdbf3('0x3d')](_0x43d8bb['query'][_0xdbf3('0x3d')]));_0x492d87['attributes']=_0x492d87['attributes'][_0xdbf3('0x3e')]?_0x492d87[_0xdbf3('0x3c')]:_0x38b10c[_0xdbf3('0x36')];if(!_0x43d8bb[_0xdbf3('0x38')][_0xdbf3('0x3f')]('nolimit')){_0x492d87[_0xdbf3('0x24')]=qs[_0xdbf3('0x24')](_0x43d8bb[_0xdbf3('0x38')][_0xdbf3('0x24')]);_0x492d87[_0xdbf3('0x23')]=qs[_0xdbf3('0x23')](_0x43d8bb[_0xdbf3('0x38')][_0xdbf3('0x23')]);}_0x492d87['order']=qs[_0xdbf3('0x40')](_0x43d8bb[_0xdbf3('0x38')][_0xdbf3('0x40')]);_0x492d87[_0xdbf3('0x41')]=qs[_0xdbf3('0x3a')](_[_0xdbf3('0x42')](_0x43d8bb[_0xdbf3('0x38')],_0x38b10c[_0xdbf3('0x3a')]),_0x475854);if(_0x43d8bb[_0xdbf3('0x38')][_0xdbf3('0x43')]){_0x492d87[_0xdbf3('0x41')]=_['merge'](_0x492d87[_0xdbf3('0x41')],{'$or':_[_0xdbf3('0x31')](_0x475854,function(_0x29f5dd){if(_0x29f5dd['type']!=='VIRTUAL'){var _0x3af03a={};_0x3af03a[_0x29f5dd[_0xdbf3('0x37')]]={'$like':'%'+_0x43d8bb[_0xdbf3('0x38')][_0xdbf3('0x43')]+'%'};return _0x3af03a;}})});}_0x492d87=_['merge']({},_0x492d87,_0x43d8bb['options']);var _0x1d7a14={'where':_0x492d87['where']};return db['CmList'][_0xdbf3('0x26')](_0x1d7a14)[_0xdbf3('0x2b')](function(_0x5e1262){_0x3869e8[_0xdbf3('0x26')]=_0x5e1262;if(_0x43d8bb[_0xdbf3('0x38')]['includeAll']){_0x492d87[_0xdbf3('0x44')]=[{'all':!![]}];}return db['CmList'][_0xdbf3('0x45')](_0x492d87);})[_0xdbf3('0x2b')](function(_0x130669){_0x3869e8[_0xdbf3('0x46')]=_0x130669;return _0x3869e8;})['then'](respondWithFilteredResult(_0x1bd638,_0x492d87))[_0xdbf3('0x47')](handleError(_0x1bd638,null));};exports[_0xdbf3('0x48')]=function(_0x586fde,_0x1aa9a8){var _0x1405bf={'raw':![],'where':{'id':_0x586fde['params']['id']}},_0x2e0cbe={};_0x2e0cbe[_0xdbf3('0x36')]=_['keys'](db[_0xdbf3('0x32')][_0xdbf3('0x33')]);_0x2e0cbe['query']=_['keys'](_0x586fde[_0xdbf3('0x38')]);_0x2e0cbe[_0xdbf3('0x3a')]=_[_0xdbf3('0x3b')](_0x2e0cbe['model'],_0x2e0cbe[_0xdbf3('0x38')]);_0x1405bf[_0xdbf3('0x3c')]=_[_0xdbf3('0x3b')](_0x2e0cbe['model'],qs[_0xdbf3('0x3d')](_0x586fde['query']['fields']));_0x1405bf[_0xdbf3('0x3c')]=_0x1405bf['attributes'][_0xdbf3('0x3e')]?_0x1405bf[_0xdbf3('0x3c')]:_0x2e0cbe[_0xdbf3('0x36')];if(_0x586fde[_0xdbf3('0x38')][_0xdbf3('0x49')]){_0x1405bf[_0xdbf3('0x44')]=[{'all':!![]}];}_0x1405bf=_[_0xdbf3('0x4a')]({},_0x1405bf,_0x586fde[_0xdbf3('0x4b')]);return db[_0xdbf3('0x32')][_0xdbf3('0x4c')](_0x1405bf)[_0xdbf3('0x2b')](handleEntityNotFound(_0x1aa9a8,null))[_0xdbf3('0x2b')](respondWithResult(_0x1aa9a8,null))['catch'](handleError(_0x1aa9a8,null));};exports[_0xdbf3('0x4d')]=function(_0x29ce38,_0x570b22){return db[_0xdbf3('0x32')]['create'](_0x29ce38[_0xdbf3('0x4e')],{})[_0xdbf3('0x2b')](function(_0x23b81d){var _0x3af6aa=_0x29ce38[_0xdbf3('0x4f')]['get']({'plain':!![]});if(!_0x3af6aa)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3af6aa[_0xdbf3('0x50')]===_0xdbf3('0x4f')){var _0x1f0bbd=_0x23b81d['get']({'plain':!![]});var _0x2a93cd='Lists';return db[_0xdbf3('0x51')][_0xdbf3('0x4c')]({'where':{'name':_0x2a93cd,'userProfileId':_0x3af6aa[_0xdbf3('0x52')]},'raw':!![]})[_0xdbf3('0x2b')](function(_0x119b05){if(_0x119b05&&_0x119b05[_0xdbf3('0x53')]===0x0){return db[_0xdbf3('0x2d')][_0xdbf3('0x4d')]({'name':_0x1f0bbd[_0xdbf3('0x37')],'resourceId':_0x1f0bbd['id'],'type':_0x119b05[_0xdbf3('0x37')],'sectionId':_0x119b05['id']},{})[_0xdbf3('0x2b')](function(){return _0x23b81d;});}else{return _0x23b81d;}})[_0xdbf3('0x47')](function(_0x5a3618){logger['error'](_0xdbf3('0x54'),_0x5a3618);throw _0x5a3618;});}return _0x23b81d;})[_0xdbf3('0x2b')](respondWithResult(_0x570b22,0xc9))['catch'](handleError(_0x570b22,null));};exports[_0xdbf3('0x29')]=function(_0x24e6cd,_0x519c1d){if(_0x24e6cd['body']['id']){delete _0x24e6cd['body']['id'];}return db['CmList'][_0xdbf3('0x4c')]({'where':{'id':_0x24e6cd[_0xdbf3('0x55')]['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x519c1d,null))[_0xdbf3('0x2b')](saveUpdates(_0x24e6cd[_0xdbf3('0x4e')],null))[_0xdbf3('0x2b')](respondWithResult(_0x519c1d,null))['catch'](handleError(_0x519c1d,null));};exports[_0xdbf3('0x2a')]=function(_0x59f55d,_0x1f132c){return db[_0xdbf3('0x32')]['find']({'where':{'id':_0x59f55d[_0xdbf3('0x55')]['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x1f132c,null))[_0xdbf3('0x2b')](removeEntity(_0x1f132c,null))[_0xdbf3('0x47')](handleError(_0x1f132c,null));};exports[_0xdbf3('0x56')]=function(_0x3d2350,_0x234c51){return db[_0xdbf3('0x32')][_0xdbf3('0x56')]()[_0xdbf3('0x2b')](respondWithResult(_0x234c51,null))[_0xdbf3('0x47')](handleError(_0x234c51,null));};exports[_0xdbf3('0x57')]=function(_0x45fba9,_0x231ebe,_0x350d6c){if(_0x45fba9[_0xdbf3('0x4e')]['id']){delete _0x45fba9[_0xdbf3('0x4e')]['id'];}return db[_0xdbf3('0x32')][_0xdbf3('0x4c')]({'where':{'id':_0x45fba9['params']['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x231ebe,null))[_0xdbf3('0x2b')](function(_0x270cd9){if(_0x270cd9){_0x45fba9['body'][_0xdbf3('0x58')]=_0x270cd9['id'];return db[_0xdbf3('0x59')][_0xdbf3('0x4d')](_0x45fba9['body']);}})[_0xdbf3('0x2b')](respondWithResult(_0x231ebe,null))['catch'](handleError(_0x231ebe,null));};exports[_0xdbf3('0x5a')]=function(_0x184906,_0x1e2aff,_0x3535ca){var _0x67afff={'raw':![],'where':{}};var _0xff691b={};var _0x169695={'count':0x0,'rows':[]};return db[_0xdbf3('0x32')][_0xdbf3('0x5b')]({'where':{'id':_0x184906[_0xdbf3('0x55')]['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x1e2aff,null))[_0xdbf3('0x2b')](function(_0x468397){if(_0x468397){_0xff691b[_0xdbf3('0x36')]=_['keys'](db['Disposition'][_0xdbf3('0x33')]);_0xff691b[_0xdbf3('0x38')]=_[_0xdbf3('0x39')](_0x184906[_0xdbf3('0x38')]);_0xff691b['filters']=_[_0xdbf3('0x3b')](_0xff691b['model'],_0xff691b['query']);_0x67afff['attributes']=_['intersection'](_0xff691b[_0xdbf3('0x36')],qs[_0xdbf3('0x3d')](_0x184906['query'][_0xdbf3('0x3d')]));_0x67afff[_0xdbf3('0x3c')]=_0x67afff[_0xdbf3('0x3c')]['length']?_0x67afff[_0xdbf3('0x3c')]:_0xff691b[_0xdbf3('0x36')];if(!_0x184906['query']['hasOwnProperty'](_0xdbf3('0x5c'))){_0x67afff[_0xdbf3('0x24')]=qs['limit'](_0x184906[_0xdbf3('0x38')]['limit']);_0x67afff[_0xdbf3('0x23')]=qs['offset'](_0x184906[_0xdbf3('0x38')]['offset']);}_0x67afff[_0xdbf3('0x5d')]=qs['sort'](_0x184906[_0xdbf3('0x38')][_0xdbf3('0x40')]);_0x67afff[_0xdbf3('0x41')]=qs['filters'](_[_0xdbf3('0x42')](_0x184906[_0xdbf3('0x38')],_0xff691b[_0xdbf3('0x3a')]));_0x67afff[_0xdbf3('0x41')][_0xdbf3('0x58')]=_0x468397['id'];if(_0x184906['query'][_0xdbf3('0x43')]){_0x67afff['where']=_[_0xdbf3('0x4a')](_0x67afff[_0xdbf3('0x41')],{'$or':_[_0xdbf3('0x31')](_0x67afff[_0xdbf3('0x3c')],function(_0xf81132){var _0x2154fe={};_0x2154fe[_0xf81132]={'$like':'%'+_0x184906[_0xdbf3('0x38')]['filter']+'%'};return _0x2154fe;})});}_0x67afff=_[_0xdbf3('0x4a')]({},_0x67afff,_0x184906[_0xdbf3('0x4b')]);return db[_0xdbf3('0x59')]['count']({'where':_0x67afff[_0xdbf3('0x41')]})[_0xdbf3('0x2b')](function(_0xaff07c){_0x169695[_0xdbf3('0x26')]=_0xaff07c;if(_0x184906[_0xdbf3('0x38')][_0xdbf3('0x49')]){_0x67afff[_0xdbf3('0x44')]=[{'all':!![]}];}return db[_0xdbf3('0x59')]['findAll'](_0x67afff);})[_0xdbf3('0x2b')](function(_0x2482d1){_0x169695[_0xdbf3('0x46')]=_0x2482d1;return _0x169695;});}})[_0xdbf3('0x2b')](respondWithFilteredResult(_0x1e2aff,_0x67afff))['catch'](handleError(_0x1e2aff,null));};exports[_0xdbf3('0x5e')]=function(_0x1c68fc,_0x5a2caf,_0x1186cd){return db[_0xdbf3('0x32')][_0xdbf3('0x4c')]({'where':{'id':_0x1c68fc['params']['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x5a2caf,null))[_0xdbf3('0x2b')](function(_0x4f5b05){if(_0x4f5b05){return _0x4f5b05[_0xdbf3('0x5e')](_0x1c68fc['query'][_0xdbf3('0x5f')]);}})[_0xdbf3('0x2b')](respondWithStatusCode(_0x5a2caf,null))[_0xdbf3('0x47')](handleError(_0x5a2caf,null));};exports[_0xdbf3('0x60')]=function(_0xd4c699,_0x4a6d0c,_0x90de9e){return db['CmList'][_0xdbf3('0x4c')]({'where':{'id':_0xd4c699[_0xdbf3('0x55')]['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x4a6d0c,null))[_0xdbf3('0x2b')](function(_0x47cd85){if(_0x47cd85){var _0x48535e=[];var _0x5d3532={'success':[],'errors':[]};return db['CmContact'][_0xdbf3('0x56')]()[_0xdbf3('0x2b')](function(_0x34cb4c){if(_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x61')]&&_[_0xdbf3('0x62')](_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x61')])){if(_0xd4c699['body']['tags'][_0xdbf3('0x3e')]){_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x61')]=_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x61')][_0xdbf3('0x63')](';')+';';}else{_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x61')]=null;}}else{_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x61')]=null;}if(_0xd4c699['body']&&_[_0xdbf3('0x62')](_0xd4c699[_0xdbf3('0x4e')])){for(var _0x4d9e8a=0x0;_0x4d9e8a<_0xd4c699[_0xdbf3('0x4e')][_0xdbf3('0x3e')];_0x4d9e8a+=0x1){_0xd4c699[_0xdbf3('0x4e')][_0x4d9e8a]['ListId']=_0xd4c699[_0xdbf3('0x55')]['id'];_0x48535e[_0xdbf3('0x64')](_0xd4c699[_0xdbf3('0x4e')][_0x4d9e8a]);}return BPromise[_0xdbf3('0x65')](_0x48535e,function(_0x2ba0c0){return db['CmContact'][_0xdbf3('0x4d')](_[_0xdbf3('0x66')](_0x2ba0c0,['ids','id'])||{},{'fields':_[_0xdbf3('0x39')](_0x34cb4c),'raw':!![]})[_0xdbf3('0x2b')](function(_0x24d341){_0x5d3532['success'][_0xdbf3('0x64')](_0x24d341[_0xdbf3('0x67')]);})[_0xdbf3('0x47')](function(_0x1d1cf2){_0x5d3532[_0xdbf3('0x68')][_0xdbf3('0x64')]({'data':_0x2ba0c0,'error':_0x1d1cf2[_0xdbf3('0x69')]});});})['then'](function(_0x3cbc8a){return _0x5d3532;})['catch'](function(_0x4f82fd){return _0x4f82fd;});}else{_0x4a6d0c[_0xdbf3('0x20')](0x190)[_0xdbf3('0x22')]({'message':_0xdbf3('0x6a')});}});}})[_0xdbf3('0x2b')](respondWithResult(_0x4a6d0c,null))[_0xdbf3('0x47')](handleError(_0x4a6d0c,null));};exports[_0xdbf3('0x6b')]=function(_0x527ad5,_0x176342,_0x4c2324){var _0x2dfe78;return db[_0xdbf3('0x32')]['find']({'where':{'id':_0x527ad5[_0xdbf3('0x55')]['id']},'include':[{'model':db[_0xdbf3('0x6c')],'as':_0xdbf3('0x6d')}]})[_0xdbf3('0x2b')](handleEntityNotFound(_0x176342,null))[_0xdbf3('0x2b')](function(_0x2671c3){if(_0x2671c3){_0x2dfe78=_0x2671c3;return db[_0xdbf3('0x6e')][_0xdbf3('0x33')];}})['then'](function(_0x371e82){if(_0x371e82){var _0xbafc6a={};var _0x20d7cb={};_0x20d7cb[_0xdbf3('0x36')]=_['concat'](_['keys'](_0x371e82),_[_0xdbf3('0x31')](_0x2dfe78['CustomFields'],function(_0x39218e){return util['format'](_0xdbf3('0x6f'),_0x39218e['id']);}));_0x20d7cb[_0xdbf3('0x38')]=_[_0xdbf3('0x39')](_0x527ad5[_0xdbf3('0x38')]);_0x20d7cb[_0xdbf3('0x3a')]=_[_0xdbf3('0x3b')](_0x20d7cb[_0xdbf3('0x36')],_0x20d7cb[_0xdbf3('0x38')]);_0xbafc6a['attributes']=_[_0xdbf3('0x3b')](_0x20d7cb[_0xdbf3('0x36')],qs[_0xdbf3('0x3d')](_0x527ad5[_0xdbf3('0x38')][_0xdbf3('0x3d')]));_0xbafc6a[_0xdbf3('0x3c')]=_0xbafc6a[_0xdbf3('0x3c')][_0xdbf3('0x3e')]?_0xbafc6a[_0xdbf3('0x3c')]:_0x20d7cb[_0xdbf3('0x36')];if(!_0x527ad5[_0xdbf3('0x38')]['hasOwnProperty']('nolimit')){_0xbafc6a[_0xdbf3('0x24')]=qs[_0xdbf3('0x24')](_0x527ad5[_0xdbf3('0x38')][_0xdbf3('0x24')]);_0xbafc6a['offset']=qs[_0xdbf3('0x23')](_0x527ad5['query'][_0xdbf3('0x23')]);}_0xbafc6a['order']=qs[_0xdbf3('0x40')](_0x527ad5[_0xdbf3('0x38')][_0xdbf3('0x40')]);_0xbafc6a[_0xdbf3('0x41')]=qs[_0xdbf3('0x3a')](_[_0xdbf3('0x42')](_0x527ad5['query'],_0x20d7cb['filters']));_0xbafc6a[_0xdbf3('0x70')]=!![];if(_0x527ad5[_0xdbf3('0x38')][_0xdbf3('0x43')]){_0xbafc6a[_0xdbf3('0x41')]=_[_0xdbf3('0x4a')](_0xbafc6a[_0xdbf3('0x41')],{'$or':_[_0xdbf3('0x31')](_0xbafc6a['attributes'],function(_0x4fa354){var _0x80468={};_0x80468[_0x4fa354]={'$like':'%'+_0x527ad5[_0xdbf3('0x38')][_0xdbf3('0x43')]+'%'};return _0x80468;})});}_0xbafc6a=_[_0xdbf3('0x4a')]({},_0xbafc6a,_0x527ad5['options']);return _0x2dfe78[_0xdbf3('0x6b')](_0xbafc6a);}})[_0xdbf3('0x2b')](respondWithResult(_0x176342,null))[_0xdbf3('0x47')](handleError(_0x176342,null));};exports[_0xdbf3('0x71')]=function(_0x334572,_0x1572d4,_0x4cbe25){var _0x2f01b0;var _0xf30a0b;var _0x1e462a;var _0x4dd2dc=_0x334572[_0xdbf3('0x55')]['id'];csv_results=[];return db['ContactItemType'][_0xdbf3('0x45')]({'attributes':['id',_0xdbf3('0x37')],'raw':!![],'order':[_0xdbf3('0x72')]})[_0xdbf3('0x2b')](function(_0x40fe1f){_0x2f01b0=_0x40fe1f;var _0x585033=_['keys'](db[_0xdbf3('0x6e')]['rawAttributes']);return db['CmCustomField'][_0xdbf3('0x45')]({'raw':!![],'attributes':['id','alias']})[_0xdbf3('0x2b')](function(_0x4b1df7){_0xf30a0b=_0x4b1df7;var _0x595032=squel[_0xdbf3('0x73')]()[_0xdbf3('0x3d')](_0x585033)['from'](_0xdbf3('0x74'),'c')[_0xdbf3('0x41')](_0xdbf3('0x75'),_0x4dd2dc)['where'](_0xdbf3('0x76'))[_0xdbf3('0x77')]();for(var _0x406641=0x0;_0x406641<_0xf30a0b[_0xdbf3('0x3e')];_0x406641++){_0x595032[_0xdbf3('0x78')]('c.cf_'+_0xf30a0b[_0x406641]['id'],'customField_'+_0xf30a0b[_0x406641]['alias']);}for(var _0x406641=0x0;_0x406641<_0x2f01b0[_0xdbf3('0x3e')];_0x406641++){_0x595032[_0xdbf3('0x78')](squel[_0xdbf3('0x73')]()[_0xdbf3('0x78')](_0xdbf3('0x79'))[_0xdbf3('0x7a')](_0xdbf3('0x7b'))[_0xdbf3('0x41')](_0xdbf3('0x7c'),_0x2f01b0[_0x406641]['id'])[_0xdbf3('0x41')](_0xdbf3('0x7d')),_0xdbf3('0x7e')+_0x2f01b0[_0x406641]['name']);_0x595032['field'](squel[_0xdbf3('0x73')]()[_0xdbf3('0x78')](_0xdbf3('0x7f'))[_0xdbf3('0x7a')]('cm_contact_has_items')[_0xdbf3('0x41')](_0xdbf3('0x7c'),_0x2f01b0[_0x406641]['id'])[_0xdbf3('0x41')]('CmContactId\x20=\x20c.id'),_0xdbf3('0x80')+_0x2f01b0[_0x406641][_0xdbf3('0x37')]);}var _0x33ce14=[];_0x33ce14[_0xdbf3('0x64')](_0x595032[_0xdbf3('0x81')]());BPromise['each'](_0x33ce14,handleQuery)[_0xdbf3('0x2b')](function(_0x4088ed){handleQuery(_0x595032[_0xdbf3('0x81')]());var _0x4c111a=csv_results[0x0];if(!_[_0xdbf3('0x82')](_0x4c111a)){var _0x5bb959=toCsv(_0x4c111a);var _0x1be169=Date[_0xdbf3('0x83')]();fs[_0xdbf3('0x84')](util[_0xdbf3('0x85')](_0xdbf3('0x86'),_0x4dd2dc,_0x1be169),_0x5bb959);_0x1572d4[_0xdbf3('0x87')](_0xdbf3('0x88'),_0xdbf3('0x89')+util[_0xdbf3('0x85')](_0xdbf3('0x8a'),_0x4dd2dc,_0x1be169));_0x1572d4[_0xdbf3('0x87')]('Content-type',_0xdbf3('0x8b'));return _0x1572d4['download'](util[_0xdbf3('0x85')](_0xdbf3('0x86'),_0x4dd2dc,_0x1be169));}else{return _0x1572d4[_0xdbf3('0x1f')](0xcc);}});});});};exports[_0xdbf3('0x8c')]=function(_0x99d2be,_0x28c222,_0x121c5c){var _0x381c09;delete _0x99d2be[_0xdbf3('0x4e')]['id'];return db[_0xdbf3('0x32')][_0xdbf3('0x5b')]({'where':{'id':_0x99d2be[_0xdbf3('0x55')]['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x28c222,null))['then'](function(_0x2d315a){if(_0x2d315a){return db[_0xdbf3('0x8d')][_0xdbf3('0x8e')](function(_0x5af9dc){return db[_0xdbf3('0x6c')][_0xdbf3('0x4d')](_0x99d2be[_0xdbf3('0x4e')],{'transaction':_0x5af9dc})[_0xdbf3('0x2b')](function(_0x1b9807){_0x381c09=_0x1b9807;return _0x2d315a[_0xdbf3('0x8f')](_0x1b9807,{'transaction':_0x5af9dc});})[_0xdbf3('0x2b')](function(){var _0x4b241e={'type':db[_0xdbf3('0x90')]['TEXT'],'transaction':_0x5af9dc};switch(_0x99d2be[_0xdbf3('0x4e')][_0xdbf3('0x34')]){case _0xdbf3('0x91'):_0x4b241e[_0xdbf3('0x34')]=db[_0xdbf3('0x90')][_0xdbf3('0x92')];break;case _0xdbf3('0x93'):_0x4b241e[_0xdbf3('0x34')]=db['Sequelize'][_0xdbf3('0x94')];break;case _0xdbf3('0x95'):_0x4b241e[_0xdbf3('0x34')]=db[_0xdbf3('0x90')][_0xdbf3('0x96')];_0x4b241e['defaultValue']=![];break;default:}return db[_0xdbf3('0x8d')][_0xdbf3('0x97')]['addColumn']('cm_contacts',util[_0xdbf3('0x85')](_0xdbf3('0x98'),_0x381c09['id']),_0x4b241e);})[_0xdbf3('0x2b')](function(){return _0x381c09;});});}})[_0xdbf3('0x2b')](respondWithResult(_0x28c222,null))[_0xdbf3('0x47')](handleError(_0x28c222,null));};exports[_0xdbf3('0x99')]=function(_0xdd0245,_0x2075cc,_0x35facc){var _0x2c63b9={};var _0x465c8b={};var _0x2e592c;var _0xce6fc0;return db[_0xdbf3('0x32')][_0xdbf3('0x5b')]({'where':{'id':_0xdd0245[_0xdbf3('0x55')]['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x2075cc,null))[_0xdbf3('0x2b')](function(_0xe8e8f0){if(_0xe8e8f0){_0x2e592c=_0xe8e8f0;_0x465c8b[_0xdbf3('0x36')]=_[_0xdbf3('0x39')](db[_0xdbf3('0x6c')]['rawAttributes']);_0x465c8b['query']=_[_0xdbf3('0x39')](_0xdd0245[_0xdbf3('0x38')]);_0x465c8b[_0xdbf3('0x3a')]=_[_0xdbf3('0x3b')](_0x465c8b[_0xdbf3('0x36')],_0x465c8b['query']);_0x2c63b9[_0xdbf3('0x3c')]=_[_0xdbf3('0x3b')](_0x465c8b['model'],qs[_0xdbf3('0x3d')](_0xdd0245[_0xdbf3('0x38')]['fields']));_0x2c63b9['attributes']=_0x2c63b9['attributes'][_0xdbf3('0x3e')]?_0x2c63b9[_0xdbf3('0x3c')]:_0x465c8b['model'];_0x2c63b9[_0xdbf3('0x5d')]=qs[_0xdbf3('0x40')](_0xdd0245[_0xdbf3('0x38')]['sort']);_0x2c63b9['where']=qs['filters'](_[_0xdbf3('0x42')](_0xdd0245['query'],_0x465c8b[_0xdbf3('0x3a')]));_0x2c63b9[_0xdbf3('0x41')]=_['merge'](_0x2c63b9['where'],{'$or':[{'ListId':_0xe8e8f0['id']},{'ListId':null}]});if(_0xdd0245[_0xdbf3('0x38')][_0xdbf3('0x43')]){_0x2c63b9['where']=_[_0xdbf3('0x4a')](_0x2c63b9[_0xdbf3('0x41')],{'$or':_[_0xdbf3('0x31')](_0x2c63b9[_0xdbf3('0x3c')],function(_0x2d719e){var _0x4a3b74={};_0x4a3b74[_0x2d719e]={'$like':'%'+_0xdd0245['query'][_0xdbf3('0x43')]+'%'};return _0x4a3b74;})});}_0x2c63b9=_[_0xdbf3('0x4a')]({},_0x2c63b9,_0xdd0245[_0xdbf3('0x4b')]);return db[_0xdbf3('0x6c')][_0xdbf3('0x9a')](_0x2c63b9);}})[_0xdbf3('0x2b')](respondWithResult(_0x2075cc,null))[_0xdbf3('0x47')](handleError(_0x2075cc,null));};exports[_0xdbf3('0x9b')]=function(_0x5b8b65,_0x5d68cd){return db[_0xdbf3('0x6c')][_0xdbf3('0x9a')]({'where':{'ListId':null}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x5d68cd,null))[_0xdbf3('0x2b')](function(_0x59ffb5){return _0x59ffb5;})[_0xdbf3('0x2b')](respondWithResult(_0x5d68cd,null))[_0xdbf3('0x47')](handleError(_0x5d68cd,null));};exports[_0xdbf3('0x9c')]=function(_0x1b36ec,_0x189eed,_0xcc89a7){return db[_0xdbf3('0x32')][_0xdbf3('0x4c')]({'where':{'id':_0x1b36ec['params']['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x189eed,null))[_0xdbf3('0x2b')](function(_0x5bfaed){if(_0x5bfaed){return _0x5bfaed[_0xdbf3('0x9c')](_0x1b36ec[_0xdbf3('0x4e')][_0xdbf3('0x5f')],_[_0xdbf3('0x66')](_0x1b36ec['body'],[_0xdbf3('0x5f'),'id'])||{})[_0xdbf3('0x9d')](function(_0x4d22ea){for(var _0x5138b6=0x0;_0x5138b6<_0x1b36ec[_0xdbf3('0x4e')][_0xdbf3('0x5f')]['length'];_0x5138b6+=0x1){socket[_0xdbf3('0x9e')](_0xdbf3('0x9f'),{'UserId':Number(_0x1b36ec[_0xdbf3('0x4e')]['ids'][_0x5138b6]),'CmListId':Number(_0x1b36ec['params']['id'])});}return _0x4d22ea;});}})[_0xdbf3('0x2b')](respondWithResult(_0x189eed,null))[_0xdbf3('0x47')](handleError(_0x189eed,null));};exports[_0xdbf3('0xa0')]=function(_0x29ed3b,_0x7ae3a0,_0x459d0b){return db[_0xdbf3('0x32')][_0xdbf3('0x4c')]({'where':{'id':_0x29ed3b['params']['id']}})[_0xdbf3('0x2b')](handleEntityNotFound(_0x7ae3a0,null))[_0xdbf3('0x2b')](function(_0x31194c){if(_0x31194c){return _0x31194c[_0xdbf3('0xa0')](_0x29ed3b['query'][_0xdbf3('0x5f')])[_0xdbf3('0x2b')](function(){if(_[_0xdbf3('0x62')](_0x29ed3b[_0xdbf3('0x38')]['ids'])){for(var _0x3605e0=0x0;_0x3605e0<_0x29ed3b[_0xdbf3('0x38')][_0xdbf3('0x5f')][_0xdbf3('0x3e')];_0x3605e0+=0x1){socket[_0xdbf3('0x9e')](_0xdbf3('0xa1'),{'UserId':Number(_0x29ed3b[_0xdbf3('0x38')][_0xdbf3('0x5f')][_0x3605e0]),'CmListId':Number(_0x29ed3b[_0xdbf3('0x55')]['id'])});}}else{socket['emit'](_0xdbf3('0xa1'),{'UserId':Number(_0x29ed3b[_0xdbf3('0x38')][_0xdbf3('0x5f')]),'CmListId':Number(_0x29ed3b['params']['id'])});}});}})['then'](respondWithStatusCode(_0x7ae3a0,null))[_0xdbf3('0x47')](handleError(_0x7ae3a0,null));};exports['getAgents']=function(_0x564d0d,_0x44631b,_0x1fb6d7){var _0x156cb={};var _0x548233={};var _0x469408;var _0x4f0e3b;return db[_0xdbf3('0x32')][_0xdbf3('0x5b')]({'where':{'id':_0x564d0d['params']['id']}})['then'](handleEntityNotFound(_0x44631b,null))[_0xdbf3('0x2b')](function(_0x4789b9){if(_0x4789b9){_0x469408=_0x4789b9;_0x548233['model']=_[_0xdbf3('0x39')](db[_0xdbf3('0xa2')]['rawAttributes']);_0x548233[_0xdbf3('0x38')]=_[_0xdbf3('0x39')](_0x564d0d[_0xdbf3('0x38')]);_0x548233[_0xdbf3('0x3a')]=_['intersection'](_0x548233['model'],_0x548233['query']);_0x156cb[_0xdbf3('0x3c')]=_[_0xdbf3('0x3b')](_0x548233[_0xdbf3('0x36')],qs['fields'](_0x564d0d[_0xdbf3('0x38')][_0xdbf3('0x3d')]));_0x156cb['attributes']=_0x156cb[_0xdbf3('0x3c')][_0xdbf3('0x3e')]?_0x156cb[_0xdbf3('0x3c')]:_0x548233[_0xdbf3('0x36')];_0x156cb[_0xdbf3('0x5d')]=qs[_0xdbf3('0x40')](_0x564d0d[_0xdbf3('0x38')][_0xdbf3('0x40')]);_0x156cb['where']=qs[_0xdbf3('0x3a')](_[_0xdbf3('0x42')](_0x564d0d[_0xdbf3('0x38')],_0x548233['filters']));if(_0x564d0d['query']['filter']){_0x156cb[_0xdbf3('0x41')]=_[_0xdbf3('0x4a')](_0x156cb[_0xdbf3('0x41')],{'$or':_['map'](_0x156cb['attributes'],function(_0x23de18){var _0x32c235={};_0x32c235[_0x23de18]={'$like':'%'+_0x564d0d['query']['filter']+'%'};return _0x32c235;})});}_0x156cb=_[_0xdbf3('0x4a')]({},_0x156cb,_0x564d0d['options']);return _0x469408[_0xdbf3('0xa3')](_0x156cb);}})['then'](function(_0x373d46){if(_0x373d46){_0x4f0e3b=_0x373d46[_0xdbf3('0x3e')];if(!_0x564d0d[_0xdbf3('0x38')][_0xdbf3('0x3f')](_0xdbf3('0x5c'))){_0x156cb[_0xdbf3('0x24')]=qs[_0xdbf3('0x24')](_0x564d0d[_0xdbf3('0x38')][_0xdbf3('0x24')]);_0x156cb[_0xdbf3('0x23')]=qs['offset'](_0x564d0d['query'][_0xdbf3('0x23')]);}return _0x469408[_0xdbf3('0xa3')](_0x156cb);}})[_0xdbf3('0x2b')](function(_0x243443){if(_0x243443){return _0x243443?{'count':_0x4f0e3b,'rows':_0x243443}:null;}})['then'](respondWithResult(_0x44631b,null))[_0xdbf3('0x47')](handleError(_0x44631b,null));};function handleQuery(_0x2d9190){logger[_0xdbf3('0xa4')](_0x2d9190);return db[_0xdbf3('0x8d')]['query'](_0x2d9190)[_0xdbf3('0x9d')](function(_0x11920f){csv_results['push'](_0x11920f);})['catch'](function(_0x1cb909){logger['error'](_0x1cb909[_0xdbf3('0x69')]);});}