3e628e125ad52aad6b89bd0a81d563be22cea031
[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 _0xb612=['writeFileSync','setHeader','list_%d_%s.csv','Content-type','text/csv','download','/tmp/list_%d_%s.csv','addCustomField','sequelize','transaction','addCustomFields','text','Sequelize','number','INTEGER','switch','BOOLEAN','defaultValue','queryInterface','addColumn','cm_contacts','cf_%s','getCustomFields','findAndCountAll','addAgents','emit','userCmList:save','removeAgents','userCmList:remove','getAgents','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','socket.io-emitter','register','sendStatus','end','json','offset','undefined','count','limit','status','set','Content-Range','apply','save','update','destroy','then','get','UserProfileResource','error','name','send','index','CmList','rawAttributes','fieldName','type','keys','query','filters','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','map','rows','show','params','includeAll','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Lists','UserProfileSection','userProfileId','autoAssociation','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','ListId','Disposition','getDispositions','findOne','include','findAll','removeDispositions','addContacts','isArray','tags','each','CmContact','omit','ids','success','push','errors','message','getContacts','concat','CustomFields','format','cf_%d','raw','getContactsCsv','CmCustomField','isEmpty','now'];(function(_0x150155,_0x1157c5){var _0x30a2a5=function(_0x32a549){while(--_0x32a549){_0x150155['push'](_0x150155['shift']());}};_0x30a2a5(++_0x1157c5);}(_0xb612,0x146));var _0x2b61=function(_0x1bb0ed,_0x12614f){_0x1bb0ed=_0x1bb0ed-0x0;var _0x25e9d1=_0xb612[_0x1bb0ed];return _0x25e9d1;};'use strict';var emlformat=require(_0x2b61('0x0'));var rimraf=require(_0x2b61('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x2b61('0x2'));var rp=require(_0x2b61('0x3'));var moment=require(_0x2b61('0x4'));var BPromise=require(_0x2b61('0x5'));var Mustache=require('mustache');var util=require(_0x2b61('0x6'));var path=require(_0x2b61('0x7'));var sox=require(_0x2b61('0x8'));var csv=require(_0x2b61('0x9'));var ejs=require(_0x2b61('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x2b61('0xb'));var squel=require(_0x2b61('0xc'));var crypto=require('crypto');var jsforce=require(_0x2b61('0xd'));var deskjs=require(_0x2b61('0xe'));var toCsv=require('to-csv');var querystring=require(_0x2b61('0xf'));var Papa=require(_0x2b61('0x10'));var Redis=require(_0x2b61('0x11'));var authService=require(_0x2b61('0x12'));var qs=require(_0x2b61('0x13'));var as=require(_0x2b61('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x2b61('0x15'))(_0x2b61('0x16'));var utils=require(_0x2b61('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x2b61('0x18'));var db=require(_0x2b61('0x19'))['db'];config[_0x2b61('0x1a')]=_[_0x2b61('0x1b')](config[_0x2b61('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0x2b61('0x1c'))(new Redis(config['redis']));require('./cmList.socket')[_0x2b61('0x1d')](socket);function respondWithStatusCode(_0x975f48,_0x385614){_0x385614=_0x385614||0xcc;return function(_0x17c46c){if(_0x17c46c){return _0x975f48[_0x2b61('0x1e')](_0x385614);}return _0x975f48['status'](_0x385614)[_0x2b61('0x1f')]();};}function respondWithResult(_0x5c0dfa,_0x2d51e5){_0x2d51e5=_0x2d51e5||0xc8;return function(_0x51d174){if(_0x51d174){return _0x5c0dfa['status'](_0x2d51e5)[_0x2b61('0x20')](_0x51d174);}};}function respondWithFilteredResult(_0x1ef28e,_0x33b565){return function(_0xab0458){if(_0xab0458){var _0x2c70bb=typeof _0x33b565[_0x2b61('0x21')]===_0x2b61('0x22')&&typeof _0x33b565['limit']==='undefined';var _0x251ab8=_0xab0458[_0x2b61('0x23')];var _0x384fc9=_0x2c70bb?0x0:_0x33b565['offset'];var _0x1ea791=_0x2c70bb?_0xab0458['count']:_0x33b565[_0x2b61('0x21')]+_0x33b565[_0x2b61('0x24')];var _0x25f9fb;if(_0x1ea791>=_0x251ab8){_0x1ea791=_0x251ab8;_0x25f9fb=0xc8;}else{_0x25f9fb=0xce;}_0x1ef28e[_0x2b61('0x25')](_0x25f9fb);return _0x1ef28e[_0x2b61('0x26')](_0x2b61('0x27'),_0x384fc9+'-'+_0x1ea791+'/'+_0x251ab8)[_0x2b61('0x20')](_0xab0458);}return null;};}function patchUpdates(_0x181482){return function(_0x5a2c05){try{jsonpatch[_0x2b61('0x28')](_0x5a2c05,_0x181482,!![]);}catch(_0x4669c7){return BPromise['reject'](_0x4669c7);}return _0x5a2c05[_0x2b61('0x29')]();};}function saveUpdates(_0x375d90,_0x1af20e){return function(_0x58e1bb){if(_0x58e1bb){return _0x58e1bb[_0x2b61('0x2a')](_0x375d90)['then'](function(_0x4bb57e){return _0x4bb57e;});}return null;};}function removeEntity(_0x46813b,_0x86905e){return function(_0x29f62b){if(_0x29f62b){return _0x29f62b[_0x2b61('0x2b')]()[_0x2b61('0x2c')](function(){var _0x23efe5=_0x29f62b[_0x2b61('0x2d')]({'plain':!![]});var _0x1848ac='Lists';return db[_0x2b61('0x2e')][_0x2b61('0x2b')]({'where':{'type':_0x1848ac,'resourceId':_0x23efe5['id']}})['then'](function(){return _0x29f62b;});})[_0x2b61('0x2c')](function(){_0x46813b[_0x2b61('0x25')](0xcc)['end']();});}};}function handleEntityNotFound(_0x372cd1,_0x190a07){return function(_0x1a6c19){if(!_0x1a6c19){_0x372cd1[_0x2b61('0x1e')](0x194);}return _0x1a6c19;};}function handleError(_0x43f6c2,_0x5b04d0){_0x5b04d0=_0x5b04d0||0x1f4;return function(_0x31a6a0){logger[_0x2b61('0x2f')](_0x31a6a0['stack']);if(_0x31a6a0[_0x2b61('0x30')]){delete _0x31a6a0[_0x2b61('0x30')];}_0x43f6c2['status'](_0x5b04d0)[_0x2b61('0x31')](_0x31a6a0);};}exports[_0x2b61('0x32')]=function(_0x59feb1,_0x277f62){var _0x11d2cc={},_0x34e89f={},_0x21ccc2={'count':0x0,'rows':[]};var _0x3b4695=_['map'](db[_0x2b61('0x33')][_0x2b61('0x34')],function(_0x16d3f4){return{'name':_0x16d3f4[_0x2b61('0x35')],'type':_0x16d3f4[_0x2b61('0x36')]['key']};});_0x34e89f['model']=_['map'](_0x3b4695,_0x2b61('0x30'));_0x34e89f['query']=_[_0x2b61('0x37')](_0x59feb1[_0x2b61('0x38')]);_0x34e89f[_0x2b61('0x39')]=_['intersection'](_0x34e89f[_0x2b61('0x3a')],_0x34e89f['query']);_0x11d2cc[_0x2b61('0x3b')]=_[_0x2b61('0x3c')](_0x34e89f['model'],qs[_0x2b61('0x3d')](_0x59feb1['query'][_0x2b61('0x3d')]));_0x11d2cc[_0x2b61('0x3b')]=_0x11d2cc[_0x2b61('0x3b')][_0x2b61('0x3e')]?_0x11d2cc[_0x2b61('0x3b')]:_0x34e89f['model'];if(!_0x59feb1[_0x2b61('0x38')][_0x2b61('0x3f')](_0x2b61('0x40'))){_0x11d2cc[_0x2b61('0x24')]=qs[_0x2b61('0x24')](_0x59feb1['query'][_0x2b61('0x24')]);_0x11d2cc[_0x2b61('0x21')]=qs[_0x2b61('0x21')](_0x59feb1['query']['offset']);}_0x11d2cc[_0x2b61('0x41')]=qs[_0x2b61('0x42')](_0x59feb1[_0x2b61('0x38')][_0x2b61('0x42')]);_0x11d2cc[_0x2b61('0x43')]=qs['filters'](_[_0x2b61('0x44')](_0x59feb1['query'],_0x34e89f['filters']),_0x3b4695);if(_0x59feb1[_0x2b61('0x38')][_0x2b61('0x45')]){_0x11d2cc[_0x2b61('0x43')]=_[_0x2b61('0x46')](_0x11d2cc[_0x2b61('0x43')],{'$or':_[_0x2b61('0x47')](_0x3b4695,function(_0x4c1d0e){if(_0x4c1d0e['type']!=='VIRTUAL'){var _0x563253={};_0x563253[_0x4c1d0e[_0x2b61('0x30')]]={'$like':'%'+_0x59feb1['query'][_0x2b61('0x45')]+'%'};return _0x563253;}})});}_0x11d2cc=_['merge']({},_0x11d2cc,_0x59feb1['options']);var _0x57a30d={'where':_0x11d2cc[_0x2b61('0x43')]};return db[_0x2b61('0x33')][_0x2b61('0x23')](_0x57a30d)['then'](function(_0x4c385c){_0x21ccc2['count']=_0x4c385c;if(_0x59feb1[_0x2b61('0x38')]['includeAll']){_0x11d2cc['include']=[{'all':!![]}];}return db[_0x2b61('0x33')]['findAll'](_0x11d2cc);})['then'](function(_0x4580b6){_0x21ccc2[_0x2b61('0x48')]=_0x4580b6;return _0x21ccc2;})[_0x2b61('0x2c')](respondWithFilteredResult(_0x277f62,_0x11d2cc))['catch'](handleError(_0x277f62,null));};exports[_0x2b61('0x49')]=function(_0x3f9974,_0x535d95){var _0x543f04={'raw':![],'where':{'id':_0x3f9974[_0x2b61('0x4a')]['id']}},_0x4c1fa4={};_0x4c1fa4[_0x2b61('0x3a')]=_['keys'](db['CmList'][_0x2b61('0x34')]);_0x4c1fa4[_0x2b61('0x38')]=_[_0x2b61('0x37')](_0x3f9974['query']);_0x4c1fa4['filters']=_[_0x2b61('0x3c')](_0x4c1fa4['model'],_0x4c1fa4[_0x2b61('0x38')]);_0x543f04[_0x2b61('0x3b')]=_['intersection'](_0x4c1fa4[_0x2b61('0x3a')],qs[_0x2b61('0x3d')](_0x3f9974[_0x2b61('0x38')][_0x2b61('0x3d')]));_0x543f04[_0x2b61('0x3b')]=_0x543f04[_0x2b61('0x3b')][_0x2b61('0x3e')]?_0x543f04[_0x2b61('0x3b')]:_0x4c1fa4[_0x2b61('0x3a')];if(_0x3f9974[_0x2b61('0x38')][_0x2b61('0x4b')]){_0x543f04['include']=[{'all':!![]}];}_0x543f04=_[_0x2b61('0x46')]({},_0x543f04,_0x3f9974[_0x2b61('0x4c')]);return db[_0x2b61('0x33')][_0x2b61('0x4d')](_0x543f04)[_0x2b61('0x2c')](handleEntityNotFound(_0x535d95,null))['then'](respondWithResult(_0x535d95,null))['catch'](handleError(_0x535d95,null));};exports[_0x2b61('0x4e')]=function(_0x5712bd,_0x1ebe9d){return db[_0x2b61('0x33')][_0x2b61('0x4e')](_0x5712bd[_0x2b61('0x4f')],{})[_0x2b61('0x2c')](function(_0x1f463d){var _0x981a4b=_0x5712bd['user'][_0x2b61('0x2d')]({'plain':!![]});if(!_0x981a4b)throw new Error(_0x2b61('0x50'));if(_0x981a4b[_0x2b61('0x51')]==='user'){var _0x175b61=_0x1f463d[_0x2b61('0x2d')]({'plain':!![]});var _0x26994a=_0x2b61('0x52');return db[_0x2b61('0x53')][_0x2b61('0x4d')]({'where':{'name':_0x26994a,'userProfileId':_0x981a4b[_0x2b61('0x54')]},'raw':!![]})['then'](function(_0xa49707){if(_0xa49707&&_0xa49707[_0x2b61('0x55')]===0x0){return db['UserProfileResource'][_0x2b61('0x4e')]({'name':_0x175b61[_0x2b61('0x30')],'resourceId':_0x175b61['id'],'type':_0xa49707[_0x2b61('0x30')],'sectionId':_0xa49707['id']},{})[_0x2b61('0x2c')](function(){return _0x1f463d;});}else{return _0x1f463d;}})[_0x2b61('0x56')](function(_0x22ac29){logger['error'](_0x2b61('0x57'),_0x22ac29);throw _0x22ac29;});}return _0x1f463d;})[_0x2b61('0x2c')](respondWithResult(_0x1ebe9d,0xc9))['catch'](handleError(_0x1ebe9d,null));};exports[_0x2b61('0x2a')]=function(_0x472800,_0x756536){if(_0x472800['body']['id']){delete _0x472800['body']['id'];}return db[_0x2b61('0x33')][_0x2b61('0x4d')]({'where':{'id':_0x472800[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x756536,null))[_0x2b61('0x2c')](saveUpdates(_0x472800['body'],null))[_0x2b61('0x2c')](respondWithResult(_0x756536,null))[_0x2b61('0x56')](handleError(_0x756536,null));};exports[_0x2b61('0x2b')]=function(_0xb6e356,_0x3e2d68){return db[_0x2b61('0x33')][_0x2b61('0x4d')]({'where':{'id':_0xb6e356[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x3e2d68,null))[_0x2b61('0x2c')](removeEntity(_0x3e2d68,null))[_0x2b61('0x56')](handleError(_0x3e2d68,null));};exports[_0x2b61('0x58')]=function(_0x2bac81,_0x28fe8e){return db[_0x2b61('0x33')][_0x2b61('0x58')]()[_0x2b61('0x2c')](respondWithResult(_0x28fe8e,null))[_0x2b61('0x56')](handleError(_0x28fe8e,null));};exports[_0x2b61('0x59')]=function(_0x2cc8b5,_0x1ed834,_0x3d3306){if(_0x2cc8b5['body']['id']){delete _0x2cc8b5[_0x2b61('0x4f')]['id'];}return db['CmList'][_0x2b61('0x4d')]({'where':{'id':_0x2cc8b5[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x1ed834,null))[_0x2b61('0x2c')](function(_0x2e3293){if(_0x2e3293){_0x2cc8b5[_0x2b61('0x4f')][_0x2b61('0x5a')]=_0x2e3293['id'];return db[_0x2b61('0x5b')][_0x2b61('0x4e')](_0x2cc8b5[_0x2b61('0x4f')]);}})['then'](respondWithResult(_0x1ed834,null))[_0x2b61('0x56')](handleError(_0x1ed834,null));};exports[_0x2b61('0x5c')]=function(_0x2f2187,_0x36554d,_0x445045){var _0x281fb2={'raw':![],'where':{}};var _0x901a73={};var _0x166bad={'count':0x0,'rows':[]};return db[_0x2b61('0x33')][_0x2b61('0x5d')]({'where':{'id':_0x2f2187[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x36554d,null))['then'](function(_0xfa25b9){if(_0xfa25b9){_0x901a73[_0x2b61('0x3a')]=_['keys'](db['Disposition'][_0x2b61('0x34')]);_0x901a73['query']=_[_0x2b61('0x37')](_0x2f2187[_0x2b61('0x38')]);_0x901a73['filters']=_[_0x2b61('0x3c')](_0x901a73[_0x2b61('0x3a')],_0x901a73[_0x2b61('0x38')]);_0x281fb2['attributes']=_[_0x2b61('0x3c')](_0x901a73[_0x2b61('0x3a')],qs[_0x2b61('0x3d')](_0x2f2187[_0x2b61('0x38')][_0x2b61('0x3d')]));_0x281fb2[_0x2b61('0x3b')]=_0x281fb2[_0x2b61('0x3b')][_0x2b61('0x3e')]?_0x281fb2[_0x2b61('0x3b')]:_0x901a73[_0x2b61('0x3a')];if(!_0x2f2187['query'][_0x2b61('0x3f')](_0x2b61('0x40'))){_0x281fb2[_0x2b61('0x24')]=qs[_0x2b61('0x24')](_0x2f2187[_0x2b61('0x38')][_0x2b61('0x24')]);_0x281fb2['offset']=qs[_0x2b61('0x21')](_0x2f2187[_0x2b61('0x38')][_0x2b61('0x21')]);}_0x281fb2[_0x2b61('0x41')]=qs[_0x2b61('0x42')](_0x2f2187[_0x2b61('0x38')][_0x2b61('0x42')]);_0x281fb2[_0x2b61('0x43')]=qs['filters'](_['pick'](_0x2f2187['query'],_0x901a73[_0x2b61('0x39')]));_0x281fb2[_0x2b61('0x43')][_0x2b61('0x5a')]=_0xfa25b9['id'];if(_0x2f2187[_0x2b61('0x38')][_0x2b61('0x45')]){_0x281fb2[_0x2b61('0x43')]=_[_0x2b61('0x46')](_0x281fb2[_0x2b61('0x43')],{'$or':_[_0x2b61('0x47')](_0x281fb2['attributes'],function(_0x273c11){var _0x592fdc={};_0x592fdc[_0x273c11]={'$like':'%'+_0x2f2187[_0x2b61('0x38')][_0x2b61('0x45')]+'%'};return _0x592fdc;})});}_0x281fb2=_[_0x2b61('0x46')]({},_0x281fb2,_0x2f2187[_0x2b61('0x4c')]);return db[_0x2b61('0x5b')][_0x2b61('0x23')]({'where':_0x281fb2[_0x2b61('0x43')]})[_0x2b61('0x2c')](function(_0x1a9430){_0x166bad[_0x2b61('0x23')]=_0x1a9430;if(_0x2f2187[_0x2b61('0x38')][_0x2b61('0x4b')]){_0x281fb2[_0x2b61('0x5e')]=[{'all':!![]}];}return db[_0x2b61('0x5b')][_0x2b61('0x5f')](_0x281fb2);})[_0x2b61('0x2c')](function(_0x3ad74a){_0x166bad[_0x2b61('0x48')]=_0x3ad74a;return _0x166bad;});}})['then'](respondWithFilteredResult(_0x36554d,_0x281fb2))['catch'](handleError(_0x36554d,null));};exports['removeDispositions']=function(_0x11f839,_0x5c1879,_0x3999c9){return db[_0x2b61('0x33')][_0x2b61('0x4d')]({'where':{'id':_0x11f839[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x5c1879,null))[_0x2b61('0x2c')](function(_0x34cc77){if(_0x34cc77){return _0x34cc77[_0x2b61('0x60')](_0x11f839['query']['ids']);}})[_0x2b61('0x2c')](respondWithStatusCode(_0x5c1879,null))[_0x2b61('0x56')](handleError(_0x5c1879,null));};exports[_0x2b61('0x61')]=function(_0x577a88,_0x5abe24,_0x4fa0a7){return db[_0x2b61('0x33')][_0x2b61('0x4d')]({'where':{'id':_0x577a88[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x5abe24,null))[_0x2b61('0x2c')](function(_0x4f524c){if(_0x4f524c){var _0xa7e47e=[];var _0x5b250e={'success':[],'errors':[]};return db['CmContact']['describe']()['then'](function(_0x2628c3){if(_0x577a88[_0x2b61('0x4f')]['tags']&&_[_0x2b61('0x62')](_0x577a88['body']['tags'])){if(_0x577a88[_0x2b61('0x4f')][_0x2b61('0x63')][_0x2b61('0x3e')]){_0x577a88['body']['tags']=_0x577a88[_0x2b61('0x4f')][_0x2b61('0x63')]['join'](';')+';';}else{_0x577a88[_0x2b61('0x4f')][_0x2b61('0x63')]=null;}}else{_0x577a88[_0x2b61('0x4f')][_0x2b61('0x63')]=null;}if(_0x577a88[_0x2b61('0x4f')]&&_[_0x2b61('0x62')](_0x577a88['body'])){for(var _0x2de749=0x0;_0x2de749<_0x577a88['body'][_0x2b61('0x3e')];_0x2de749+=0x1){_0x577a88[_0x2b61('0x4f')][_0x2de749][_0x2b61('0x5a')]=_0x577a88[_0x2b61('0x4a')]['id'];_0xa7e47e['push'](_0x577a88[_0x2b61('0x4f')][_0x2de749]);}return BPromise[_0x2b61('0x64')](_0xa7e47e,function(_0xcedec2){return db[_0x2b61('0x65')][_0x2b61('0x4e')](_[_0x2b61('0x66')](_0xcedec2,[_0x2b61('0x67'),'id'])||{},{'fields':_['keys'](_0x2628c3),'raw':!![]})[_0x2b61('0x2c')](function(_0x2bbe56){_0x5b250e[_0x2b61('0x68')][_0x2b61('0x69')](_0x2bbe56['dataValues']);})[_0x2b61('0x56')](function(_0x2b0256){_0x5b250e[_0x2b61('0x6a')][_0x2b61('0x69')]({'data':_0xcedec2,'error':_0x2b0256[_0x2b61('0x6b')]});});})['then'](function(_0x2cf982){return _0x5b250e;})[_0x2b61('0x56')](function(_0x45fd8a){return _0x45fd8a;});}else{_0x5abe24[_0x2b61('0x25')](0x190)['json']({'message':'Malformed\x20request\x20syntax'});}});}})['then'](respondWithResult(_0x5abe24,null))['catch'](handleError(_0x5abe24,null));};exports[_0x2b61('0x6c')]=function(_0x4889c7,_0x276476,_0x4c164e){var _0x41509d;return db[_0x2b61('0x33')][_0x2b61('0x4d')]({'where':{'id':_0x4889c7[_0x2b61('0x4a')]['id']},'include':[{'model':db['CmCustomField'],'as':'CustomFields'}]})[_0x2b61('0x2c')](handleEntityNotFound(_0x276476,null))[_0x2b61('0x2c')](function(_0x439865){if(_0x439865){_0x41509d=_0x439865;return db[_0x2b61('0x65')][_0x2b61('0x34')];}})[_0x2b61('0x2c')](function(_0x356bc3){if(_0x356bc3){var _0x33485d={};var _0x4d57a5={};_0x4d57a5[_0x2b61('0x3a')]=_[_0x2b61('0x6d')](_['keys'](_0x356bc3),_[_0x2b61('0x47')](_0x41509d[_0x2b61('0x6e')],function(_0x58a04d){return util[_0x2b61('0x6f')](_0x2b61('0x70'),_0x58a04d['id']);}));_0x4d57a5[_0x2b61('0x38')]=_[_0x2b61('0x37')](_0x4889c7[_0x2b61('0x38')]);_0x4d57a5[_0x2b61('0x39')]=_['intersection'](_0x4d57a5[_0x2b61('0x3a')],_0x4d57a5['query']);_0x33485d[_0x2b61('0x3b')]=_[_0x2b61('0x3c')](_0x4d57a5[_0x2b61('0x3a')],qs['fields'](_0x4889c7['query']['fields']));_0x33485d[_0x2b61('0x3b')]=_0x33485d['attributes'][_0x2b61('0x3e')]?_0x33485d['attributes']:_0x4d57a5[_0x2b61('0x3a')];if(!_0x4889c7[_0x2b61('0x38')][_0x2b61('0x3f')](_0x2b61('0x40'))){_0x33485d[_0x2b61('0x24')]=qs[_0x2b61('0x24')](_0x4889c7[_0x2b61('0x38')][_0x2b61('0x24')]);_0x33485d[_0x2b61('0x21')]=qs[_0x2b61('0x21')](_0x4889c7[_0x2b61('0x38')]['offset']);}_0x33485d[_0x2b61('0x41')]=qs[_0x2b61('0x42')](_0x4889c7[_0x2b61('0x38')][_0x2b61('0x42')]);_0x33485d['where']=qs[_0x2b61('0x39')](_[_0x2b61('0x44')](_0x4889c7[_0x2b61('0x38')],_0x4d57a5[_0x2b61('0x39')]));_0x33485d[_0x2b61('0x71')]=!![];if(_0x4889c7[_0x2b61('0x38')][_0x2b61('0x45')]){_0x33485d[_0x2b61('0x43')]=_[_0x2b61('0x46')](_0x33485d['where'],{'$or':_[_0x2b61('0x47')](_0x33485d['attributes'],function(_0x417298){var _0x29bd42={};_0x29bd42[_0x417298]={'$like':'%'+_0x4889c7[_0x2b61('0x38')][_0x2b61('0x45')]+'%'};return _0x29bd42;})});}_0x33485d=_['merge']({},_0x33485d,_0x4889c7['options']);return _0x41509d[_0x2b61('0x6c')](_0x33485d);}})[_0x2b61('0x2c')](respondWithResult(_0x276476,null))[_0x2b61('0x56')](handleError(_0x276476,null));};exports[_0x2b61('0x72')]=function(_0x53dba4,_0x44ed37,_0x4f695a){var _0x212a8d;return db['CmList'][_0x2b61('0x4d')]({'where':{'id':_0x53dba4['params']['id']},'include':[{'model':db[_0x2b61('0x73')],'as':_0x2b61('0x6e')}]})[_0x2b61('0x2c')](handleEntityNotFound(_0x44ed37,null))['then'](function(_0x383414){if(_0x383414){_0x212a8d=_0x383414;return db[_0x2b61('0x65')][_0x2b61('0x34')];}})[_0x2b61('0x2c')](function(_0x439b00){if(_0x439b00){var _0x461f1f={};var _0x40bb62={};_0x40bb62[_0x2b61('0x3a')]=_[_0x2b61('0x6d')](_[_0x2b61('0x37')](_0x439b00),_[_0x2b61('0x47')](_0x212a8d[_0x2b61('0x6e')],function(_0xbc22f4){return util[_0x2b61('0x6f')]('cf_%d',_0xbc22f4['id']);}));_0x40bb62[_0x2b61('0x38')]=_[_0x2b61('0x37')](_0x53dba4[_0x2b61('0x38')]);_0x40bb62['filters']=_[_0x2b61('0x3c')](_0x40bb62['model'],_0x40bb62[_0x2b61('0x38')]);_0x461f1f[_0x2b61('0x3b')]=_['intersection'](_0x40bb62['model'],qs[_0x2b61('0x3d')](_0x53dba4[_0x2b61('0x38')][_0x2b61('0x3d')]));_0x461f1f[_0x2b61('0x3b')]=_0x461f1f[_0x2b61('0x3b')][_0x2b61('0x3e')]?_0x461f1f[_0x2b61('0x3b')]:_0x40bb62[_0x2b61('0x3a')];if(!_0x53dba4[_0x2b61('0x38')][_0x2b61('0x3f')](_0x2b61('0x40'))){_0x461f1f[_0x2b61('0x24')]=qs[_0x2b61('0x24')](_0x53dba4[_0x2b61('0x38')]['limit']);_0x461f1f[_0x2b61('0x21')]=qs['offset'](_0x53dba4['query'][_0x2b61('0x21')]);}_0x461f1f[_0x2b61('0x41')]=qs[_0x2b61('0x42')](_0x53dba4[_0x2b61('0x38')][_0x2b61('0x42')]);_0x461f1f['where']=qs['filters'](_[_0x2b61('0x44')](_0x53dba4[_0x2b61('0x38')],_0x40bb62[_0x2b61('0x39')]));_0x461f1f[_0x2b61('0x71')]=!![];if(_0x53dba4[_0x2b61('0x38')][_0x2b61('0x45')]){_0x461f1f[_0x2b61('0x43')]=_[_0x2b61('0x46')](_0x461f1f[_0x2b61('0x43')],{'$or':_['map'](_0x461f1f[_0x2b61('0x3b')],function(_0x573cc7){var _0x374161={};_0x374161[_0x573cc7]={'$like':'%'+_0x53dba4[_0x2b61('0x38')][_0x2b61('0x45')]+'%'};return _0x374161;})});}_0x461f1f=_['merge']({},_0x461f1f,_0x53dba4[_0x2b61('0x4c')]);return _0x212a8d[_0x2b61('0x6c')](_0x461f1f);}})[_0x2b61('0x2c')](function(_0x2b3d06){if(!_[_0x2b61('0x74')](_0x2b3d06)){var _0x5d949c=toCsv(_0x2b3d06);var _0x34346f=Date[_0x2b61('0x75')]();fs[_0x2b61('0x76')](util[_0x2b61('0x6f')]('/tmp/list_%d_%s.csv',_0x212a8d['id'],_0x34346f),_0x5d949c);_0x44ed37[_0x2b61('0x77')]('Content-disposition','attachment;\x20filename='+util[_0x2b61('0x6f')](_0x2b61('0x78'),_0x212a8d['id'],_0x34346f));_0x44ed37['setHeader'](_0x2b61('0x79'),_0x2b61('0x7a'));return _0x44ed37[_0x2b61('0x7b')](util[_0x2b61('0x6f')](_0x2b61('0x7c'),_0x212a8d['id'],_0x34346f));}else{return _0x44ed37[_0x2b61('0x1e')](0xcc);}})[_0x2b61('0x56')](handleError(_0x44ed37,null));};exports[_0x2b61('0x7d')]=function(_0x45b108,_0x47353f,_0x118ec9){var _0x13e8ab;delete _0x45b108[_0x2b61('0x4f')]['id'];return db[_0x2b61('0x33')][_0x2b61('0x5d')]({'where':{'id':_0x45b108['params']['id']}})['then'](handleEntityNotFound(_0x47353f,null))['then'](function(_0xcbbc7b){if(_0xcbbc7b){return db[_0x2b61('0x7e')][_0x2b61('0x7f')](function(_0x5392f8){return db['CmCustomField'][_0x2b61('0x4e')](_0x45b108[_0x2b61('0x4f')],{'transaction':_0x5392f8})[_0x2b61('0x2c')](function(_0x3a967f){_0x13e8ab=_0x3a967f;return _0xcbbc7b[_0x2b61('0x80')](_0x3a967f,{'transaction':_0x5392f8});})[_0x2b61('0x2c')](function(){var _0x31bfea={'type':db['Sequelize']['TEXT'],'transaction':_0x5392f8};switch(_0x45b108[_0x2b61('0x4f')]['type']){case _0x2b61('0x81'):_0x31bfea[_0x2b61('0x36')]=db[_0x2b61('0x82')]['TEXT'];break;case _0x2b61('0x83'):_0x31bfea[_0x2b61('0x36')]=db[_0x2b61('0x82')][_0x2b61('0x84')];break;case _0x2b61('0x85'):_0x31bfea[_0x2b61('0x36')]=db[_0x2b61('0x82')][_0x2b61('0x86')];_0x31bfea[_0x2b61('0x87')]=![];break;default:}return db['sequelize'][_0x2b61('0x88')][_0x2b61('0x89')](_0x2b61('0x8a'),util[_0x2b61('0x6f')](_0x2b61('0x8b'),_0x13e8ab['id']),_0x31bfea);})[_0x2b61('0x2c')](function(){return _0x13e8ab;});});}})['then'](respondWithResult(_0x47353f,null))['catch'](handleError(_0x47353f,null));};exports[_0x2b61('0x8c')]=function(_0x1f6405,_0x434888,_0x299c6f){var _0x263974={};var _0x27bc44={};var _0x24f2de;var _0x3d30ef;return db['CmList'][_0x2b61('0x5d')]({'where':{'id':_0x1f6405[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x434888,null))[_0x2b61('0x2c')](function(_0x352802){if(_0x352802){_0x24f2de=_0x352802;_0x27bc44[_0x2b61('0x3a')]=_[_0x2b61('0x37')](db['CmCustomField']['rawAttributes']);_0x27bc44[_0x2b61('0x38')]=_[_0x2b61('0x37')](_0x1f6405[_0x2b61('0x38')]);_0x27bc44[_0x2b61('0x39')]=_['intersection'](_0x27bc44[_0x2b61('0x3a')],_0x27bc44[_0x2b61('0x38')]);_0x263974[_0x2b61('0x3b')]=_[_0x2b61('0x3c')](_0x27bc44[_0x2b61('0x3a')],qs['fields'](_0x1f6405[_0x2b61('0x38')][_0x2b61('0x3d')]));_0x263974[_0x2b61('0x3b')]=_0x263974[_0x2b61('0x3b')][_0x2b61('0x3e')]?_0x263974[_0x2b61('0x3b')]:_0x27bc44['model'];_0x263974[_0x2b61('0x41')]=qs[_0x2b61('0x42')](_0x1f6405[_0x2b61('0x38')]['sort']);_0x263974[_0x2b61('0x43')]=qs[_0x2b61('0x39')](_[_0x2b61('0x44')](_0x1f6405[_0x2b61('0x38')],_0x27bc44[_0x2b61('0x39')]));_0x263974[_0x2b61('0x43')]=_[_0x2b61('0x46')](_0x263974[_0x2b61('0x43')],{'$or':[{'ListId':_0x352802['id']},{'ListId':null}]});if(_0x1f6405['query'][_0x2b61('0x45')]){_0x263974[_0x2b61('0x43')]=_[_0x2b61('0x46')](_0x263974['where'],{'$or':_[_0x2b61('0x47')](_0x263974[_0x2b61('0x3b')],function(_0x5957d8){var _0x22aa90={};_0x22aa90[_0x5957d8]={'$like':'%'+_0x1f6405[_0x2b61('0x38')][_0x2b61('0x45')]+'%'};return _0x22aa90;})});}_0x263974=_[_0x2b61('0x46')]({},_0x263974,_0x1f6405[_0x2b61('0x4c')]);return db[_0x2b61('0x73')][_0x2b61('0x8d')](_0x263974);}})[_0x2b61('0x2c')](respondWithResult(_0x434888,null))[_0x2b61('0x56')](handleError(_0x434888,null));};exports[_0x2b61('0x8e')]=function(_0x1c2de4,_0x334f09,_0x3f3858){return db[_0x2b61('0x33')][_0x2b61('0x4d')]({'where':{'id':_0x1c2de4[_0x2b61('0x4a')]['id']}})['then'](handleEntityNotFound(_0x334f09,null))[_0x2b61('0x2c')](function(_0xa99b4c){if(_0xa99b4c){return _0xa99b4c['addAgents'](_0x1c2de4[_0x2b61('0x4f')][_0x2b61('0x67')],_[_0x2b61('0x66')](_0x1c2de4[_0x2b61('0x4f')],[_0x2b61('0x67'),'id'])||{})['spread'](function(_0x56ffe2){for(var _0x382726=0x0;_0x382726<_0x1c2de4[_0x2b61('0x4f')]['ids']['length'];_0x382726+=0x1){socket[_0x2b61('0x8f')](_0x2b61('0x90'),{'UserId':Number(_0x1c2de4[_0x2b61('0x4f')][_0x2b61('0x67')][_0x382726]),'CmListId':Number(_0x1c2de4[_0x2b61('0x4a')]['id'])});}return _0x56ffe2;});}})[_0x2b61('0x2c')](respondWithResult(_0x334f09,null))[_0x2b61('0x56')](handleError(_0x334f09,null));};exports[_0x2b61('0x91')]=function(_0x47120d,_0x300673,_0x213ee0){return db['CmList'][_0x2b61('0x4d')]({'where':{'id':_0x47120d[_0x2b61('0x4a')]['id']}})['then'](handleEntityNotFound(_0x300673,null))[_0x2b61('0x2c')](function(_0x3c1cd7){if(_0x3c1cd7){return _0x3c1cd7[_0x2b61('0x91')](_0x47120d['query'][_0x2b61('0x67')])['then'](function(){if(_[_0x2b61('0x62')](_0x47120d[_0x2b61('0x38')]['ids'])){for(var _0x25c636=0x0;_0x25c636<_0x47120d[_0x2b61('0x38')][_0x2b61('0x67')]['length'];_0x25c636+=0x1){socket['emit'](_0x2b61('0x92'),{'UserId':Number(_0x47120d[_0x2b61('0x38')][_0x2b61('0x67')][_0x25c636]),'CmListId':Number(_0x47120d['params']['id'])});}}else{socket['emit'](_0x2b61('0x92'),{'UserId':Number(_0x47120d['query']['ids']),'CmListId':Number(_0x47120d[_0x2b61('0x4a')]['id'])});}});}})[_0x2b61('0x2c')](respondWithStatusCode(_0x300673,null))[_0x2b61('0x56')](handleError(_0x300673,null));};exports[_0x2b61('0x93')]=function(_0x324935,_0x1c9a13,_0x4f28f2){var _0x43921f={};var _0x205653={};var _0x2e4170;var _0xe39d98;return db[_0x2b61('0x33')]['findOne']({'where':{'id':_0x324935[_0x2b61('0x4a')]['id']}})[_0x2b61('0x2c')](handleEntityNotFound(_0x1c9a13,null))['then'](function(_0x1516a4){if(_0x1516a4){_0x2e4170=_0x1516a4;_0x205653[_0x2b61('0x3a')]=_[_0x2b61('0x37')](db['User'][_0x2b61('0x34')]);_0x205653[_0x2b61('0x38')]=_[_0x2b61('0x37')](_0x324935[_0x2b61('0x38')]);_0x205653[_0x2b61('0x39')]=_[_0x2b61('0x3c')](_0x205653[_0x2b61('0x3a')],_0x205653[_0x2b61('0x38')]);_0x43921f[_0x2b61('0x3b')]=_[_0x2b61('0x3c')](_0x205653[_0x2b61('0x3a')],qs[_0x2b61('0x3d')](_0x324935[_0x2b61('0x38')][_0x2b61('0x3d')]));_0x43921f[_0x2b61('0x3b')]=_0x43921f[_0x2b61('0x3b')][_0x2b61('0x3e')]?_0x43921f[_0x2b61('0x3b')]:_0x205653['model'];_0x43921f[_0x2b61('0x41')]=qs[_0x2b61('0x42')](_0x324935[_0x2b61('0x38')][_0x2b61('0x42')]);_0x43921f['where']=qs[_0x2b61('0x39')](_['pick'](_0x324935[_0x2b61('0x38')],_0x205653[_0x2b61('0x39')]));if(_0x324935[_0x2b61('0x38')][_0x2b61('0x45')]){_0x43921f[_0x2b61('0x43')]=_['merge'](_0x43921f[_0x2b61('0x43')],{'$or':_[_0x2b61('0x47')](_0x43921f[_0x2b61('0x3b')],function(_0x68c68d){var _0x3b4efa={};_0x3b4efa[_0x68c68d]={'$like':'%'+_0x324935[_0x2b61('0x38')][_0x2b61('0x45')]+'%'};return _0x3b4efa;})});}_0x43921f=_[_0x2b61('0x46')]({},_0x43921f,_0x324935['options']);return _0x2e4170[_0x2b61('0x93')](_0x43921f);}})[_0x2b61('0x2c')](function(_0x279400){if(_0x279400){_0xe39d98=_0x279400['length'];if(!_0x324935[_0x2b61('0x38')][_0x2b61('0x3f')](_0x2b61('0x40'))){_0x43921f[_0x2b61('0x24')]=qs[_0x2b61('0x24')](_0x324935[_0x2b61('0x38')][_0x2b61('0x24')]);_0x43921f[_0x2b61('0x21')]=qs[_0x2b61('0x21')](_0x324935['query']['offset']);}return _0x2e4170[_0x2b61('0x93')](_0x43921f);}})['then'](function(_0x17c1a0){if(_0x17c1a0){return _0x17c1a0?{'count':_0xe39d98,'rows':_0x17c1a0}:null;}})[_0x2b61('0x2c')](respondWithResult(_0x1c9a13,null))[_0x2b61('0x56')](handleError(_0x1c9a13,null));};