be18326dde597770352be25fc5ebf527d6831cf9
[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 _0xbb63=['autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','describe','addDisposition','Disposition','getDispositions','findAll','rows','removeDispositions','addContacts','CmContact','tags','isArray','join','ListId','each','omit','ids','success','dataValues','message','Malformed\x20request\x20syntax','CmCustomField','CustomFields','concat','format','cf_%d','getContacts','getContactsCsv','raw','isEmpty','writeFileSync','/tmp/list_%d_%s.csv','Content-disposition','list_%d_%s.csv','setHeader','Content-type','text/csv','download','addCustomField','transaction','addCustomFields','Sequelize','TEXT','INTEGER','switch','BOOLEAN','defaultValue','sequelize','queryInterface','addColumn','cm_contacts','cf_%s','findOne','addAgents','spread','emit','userCmList:save','removeAgents','userCmList:remove','getAgents','User','eml-format','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../mysqldb','redis','localhost','./cmList.socket','register','sendStatus','end','status','json','count','limit','apply','reject','save','update','destroy','then','get','Lists','UserProfileResource','error','name','map','CmList','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','offset','order','sort','pick','filter','where','VIRTUAL','merge','options','includeAll','include','catch','show','params','rawAttributes','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId'];(function(_0x33c8b3,_0x27dc52){var _0x25089b=function(_0x392058){while(--_0x392058){_0x33c8b3['push'](_0x33c8b3['shift']());}};_0x25089b(++_0x27dc52);}(_0xbb63,0x1e3));var _0x3bb6=function(_0x4cd11c,_0x11925c){_0x4cd11c=_0x4cd11c-0x0;var _0x2bf15f=_0xbb63[_0x4cd11c];return _0x2bf15f;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x3bb6('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x3bb6('0x1'));var rp=require(_0x3bb6('0x2'));var moment=require(_0x3bb6('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x3bb6('0x4'));var util=require('util');var path=require(_0x3bb6('0x5'));var sox=require(_0x3bb6('0x6'));var csv=require(_0x3bb6('0x7'));var ejs=require(_0x3bb6('0x8'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x3bb6('0x9'));var jsforce=require(_0x3bb6('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x3bb6('0x7'));var querystring=require(_0x3bb6('0xb'));var Papa=require('papaparse');var Redis=require(_0x3bb6('0xc'));var authService=require(_0x3bb6('0xd'));var qs=require(_0x3bb6('0xe'));var as=require(_0x3bb6('0xf'));var hardwareService=require(_0x3bb6('0x10'));var logger=require('../../config/logger')(_0x3bb6('0x11'));var utils=require(_0x3bb6('0x12'));var config=require('../../config/environment');var db=require(_0x3bb6('0x13'))['db'];config[_0x3bb6('0x14')]=_['defaults'](config[_0x3bb6('0x14')],{'host':_0x3bb6('0x15'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x3bb6('0x14')]));require(_0x3bb6('0x16'))[_0x3bb6('0x17')](socket);function respondWithStatusCode(_0xa1fb88,_0x15036d){_0x15036d=_0x15036d||0xcc;return function(_0x2f3e54){if(_0x2f3e54){return _0xa1fb88[_0x3bb6('0x18')](_0x15036d);}return _0xa1fb88['status'](_0x15036d)[_0x3bb6('0x19')]();};}function respondWithResult(_0x372004,_0x45530d){_0x45530d=_0x45530d||0xc8;return function(_0x4617ac){if(_0x4617ac){return _0x372004[_0x3bb6('0x1a')](_0x45530d)[_0x3bb6('0x1b')](_0x4617ac);}};}function respondWithFilteredResult(_0x14e257,_0x2c9781){return function(_0x282be5){if(_0x282be5){var _0x2376fe=_0x282be5[_0x3bb6('0x1c')],_0x470087=_0x2c9781['offset'],_0xfaa93d=_0x2c9781['offset']+_0x2c9781[_0x3bb6('0x1d')],_0x16f390;if(_0xfaa93d>=_0x2376fe){_0xfaa93d=_0x2376fe;_0x16f390=0xc8;}else{_0x16f390=0xce;}_0x14e257[_0x3bb6('0x1a')](_0x16f390);return _0x14e257['set']('Content-Range',_0x470087+'-'+_0xfaa93d+'/'+_0x2376fe)[_0x3bb6('0x1b')](_0x282be5);}return null;};}function patchUpdates(_0x5b287e){return function(_0x33548f){try{jsonpatch[_0x3bb6('0x1e')](_0x33548f,_0x5b287e,!![]);}catch(_0x520d9f){return BPromise[_0x3bb6('0x1f')](_0x520d9f);}return _0x33548f[_0x3bb6('0x20')]();};}function saveUpdates(_0x44ec5c,_0x4a8b36){return function(_0x495d20){if(_0x495d20){return _0x495d20[_0x3bb6('0x21')](_0x44ec5c)['then'](function(_0x354907){return _0x354907;});}return null;};}function removeEntity(_0x1b0d7c,_0x3bbe6d){return function(_0xb1902b){if(_0xb1902b){return _0xb1902b[_0x3bb6('0x22')]()[_0x3bb6('0x23')](function(){var _0x297093=_0xb1902b[_0x3bb6('0x24')]({'plain':!![]});var _0xd794dd=_0x3bb6('0x25');return db[_0x3bb6('0x26')][_0x3bb6('0x22')]({'where':{'type':_0xd794dd,'resourceId':_0x297093['id']}})[_0x3bb6('0x23')](function(){return _0xb1902b;});})[_0x3bb6('0x23')](function(){_0x1b0d7c[_0x3bb6('0x1a')](0xcc)[_0x3bb6('0x19')]();});}};}function handleEntityNotFound(_0x58186d,_0x4a4fe9){return function(_0x54a686){if(!_0x54a686){_0x58186d[_0x3bb6('0x18')](0x194);}return _0x54a686;};}function handleError(_0x488fb0,_0xfa4042){_0xfa4042=_0xfa4042||0x1f4;return function(_0x34d5eb){logger[_0x3bb6('0x27')](_0x34d5eb['stack']);if(_0x34d5eb[_0x3bb6('0x28')]){delete _0x34d5eb[_0x3bb6('0x28')];}_0x488fb0['status'](_0xfa4042)['send'](_0x34d5eb);};}exports['index']=function(_0x349f23,_0x4580d6){var _0x105b3b={},_0x16dd89={},_0x1f238e={'count':0x0,'rows':[]};var _0xf0c651=_[_0x3bb6('0x29')](db[_0x3bb6('0x2a')]['rawAttributes'],function(_0x4a5806){return{'name':_0x4a5806[_0x3bb6('0x2b')],'type':_0x4a5806[_0x3bb6('0x2c')][_0x3bb6('0x2d')]};});_0x16dd89[_0x3bb6('0x2e')]=_[_0x3bb6('0x29')](_0xf0c651,_0x3bb6('0x28'));_0x16dd89[_0x3bb6('0x2f')]=_[_0x3bb6('0x30')](_0x349f23[_0x3bb6('0x2f')]);_0x16dd89[_0x3bb6('0x31')]=_[_0x3bb6('0x32')](_0x16dd89['model'],_0x16dd89[_0x3bb6('0x2f')]);_0x105b3b[_0x3bb6('0x33')]=_[_0x3bb6('0x32')](_0x16dd89[_0x3bb6('0x2e')],qs[_0x3bb6('0x34')](_0x349f23['query'][_0x3bb6('0x34')]));_0x105b3b[_0x3bb6('0x33')]=_0x105b3b[_0x3bb6('0x33')][_0x3bb6('0x35')]?_0x105b3b['attributes']:_0x16dd89['model'];if(!_0x349f23[_0x3bb6('0x2f')][_0x3bb6('0x36')](_0x3bb6('0x37'))){_0x105b3b[_0x3bb6('0x1d')]=qs[_0x3bb6('0x1d')](_0x349f23[_0x3bb6('0x2f')][_0x3bb6('0x1d')]);_0x105b3b[_0x3bb6('0x38')]=qs['offset'](_0x349f23['query'][_0x3bb6('0x38')]);}_0x105b3b[_0x3bb6('0x39')]=qs[_0x3bb6('0x3a')](_0x349f23[_0x3bb6('0x2f')][_0x3bb6('0x3a')]);_0x105b3b['where']=qs['filters'](_[_0x3bb6('0x3b')](_0x349f23['query'],_0x16dd89[_0x3bb6('0x31')]),_0xf0c651);if(_0x349f23['query'][_0x3bb6('0x3c')]){_0x105b3b[_0x3bb6('0x3d')]=_['merge'](_0x105b3b[_0x3bb6('0x3d')],{'$or':_[_0x3bb6('0x29')](_0xf0c651,function(_0x2ed737){if(_0x2ed737[_0x3bb6('0x2c')]!==_0x3bb6('0x3e')){var _0x3a9749={};_0x3a9749[_0x2ed737['name']]={'$like':'%'+_0x349f23[_0x3bb6('0x2f')][_0x3bb6('0x3c')]+'%'};return _0x3a9749;}})});}_0x105b3b=_[_0x3bb6('0x3f')]({},_0x105b3b,_0x349f23[_0x3bb6('0x40')]);var _0x12b176={'where':_0x105b3b[_0x3bb6('0x3d')]};return db[_0x3bb6('0x2a')][_0x3bb6('0x1c')](_0x12b176)[_0x3bb6('0x23')](function(_0x4316a3){_0x1f238e[_0x3bb6('0x1c')]=_0x4316a3;if(_0x349f23[_0x3bb6('0x2f')][_0x3bb6('0x41')]){_0x105b3b[_0x3bb6('0x42')]=[{'all':!![]}];}return db[_0x3bb6('0x2a')]['findAll'](_0x105b3b);})[_0x3bb6('0x23')](function(_0x3f39f6){_0x1f238e['rows']=_0x3f39f6;return _0x1f238e;})['then'](respondWithFilteredResult(_0x4580d6,_0x105b3b))[_0x3bb6('0x43')](handleError(_0x4580d6,null));};exports[_0x3bb6('0x44')]=function(_0x1e2d37,_0xf89cc4){var _0x263eaa={'raw':![],'where':{'id':_0x1e2d37[_0x3bb6('0x45')]['id']}},_0xb4f974={};_0xb4f974['model']=_['keys'](db['CmList'][_0x3bb6('0x46')]);_0xb4f974[_0x3bb6('0x2f')]=_['keys'](_0x1e2d37['query']);_0xb4f974[_0x3bb6('0x31')]=_[_0x3bb6('0x32')](_0xb4f974[_0x3bb6('0x2e')],_0xb4f974[_0x3bb6('0x2f')]);_0x263eaa[_0x3bb6('0x33')]=_[_0x3bb6('0x32')](_0xb4f974[_0x3bb6('0x2e')],qs[_0x3bb6('0x34')](_0x1e2d37['query'][_0x3bb6('0x34')]));_0x263eaa[_0x3bb6('0x33')]=_0x263eaa[_0x3bb6('0x33')][_0x3bb6('0x35')]?_0x263eaa[_0x3bb6('0x33')]:_0xb4f974[_0x3bb6('0x2e')];if(_0x1e2d37['query'][_0x3bb6('0x41')]){_0x263eaa[_0x3bb6('0x42')]=[{'all':!![]}];}_0x263eaa=_[_0x3bb6('0x3f')]({},_0x263eaa,_0x1e2d37['options']);return db[_0x3bb6('0x2a')]['find'](_0x263eaa)[_0x3bb6('0x23')](handleEntityNotFound(_0xf89cc4,null))['then'](respondWithResult(_0xf89cc4,null))[_0x3bb6('0x43')](handleError(_0xf89cc4,null));};exports[_0x3bb6('0x47')]=function(_0x1fd317,_0x2ab6d8){return db[_0x3bb6('0x2a')][_0x3bb6('0x47')](_0x1fd317[_0x3bb6('0x48')],{})[_0x3bb6('0x23')](function(_0x4d7079){var _0x5512c7=_0x1fd317['user'][_0x3bb6('0x24')]({'plain':!![]});if(!_0x5512c7)throw new Error(_0x3bb6('0x49'));if(_0x5512c7['role']===_0x3bb6('0x4a')){var _0x3a3fe4=_0x4d7079[_0x3bb6('0x24')]({'plain':!![]});var _0x5c3920=_0x3bb6('0x25');return db[_0x3bb6('0x4b')]['find']({'where':{'name':_0x5c3920,'userProfileId':_0x5512c7[_0x3bb6('0x4c')]},'raw':!![]})[_0x3bb6('0x23')](function(_0x417fd2){if(_0x417fd2&&_0x417fd2[_0x3bb6('0x4d')]===0x0){return db[_0x3bb6('0x26')][_0x3bb6('0x47')]({'name':_0x3a3fe4[_0x3bb6('0x28')],'resourceId':_0x3a3fe4['id'],'type':_0x417fd2[_0x3bb6('0x28')],'sectionId':_0x417fd2['id']},{})[_0x3bb6('0x23')](function(){return _0x4d7079;});}else{return _0x4d7079;}})[_0x3bb6('0x43')](function(_0x400d2d){logger[_0x3bb6('0x27')](_0x3bb6('0x4e'),_0x400d2d);throw _0x400d2d;});}return _0x4d7079;})[_0x3bb6('0x23')](respondWithResult(_0x2ab6d8,0xc9))[_0x3bb6('0x43')](handleError(_0x2ab6d8,null));};exports[_0x3bb6('0x21')]=function(_0x245160,_0x431a11){if(_0x245160['body']['id']){delete _0x245160[_0x3bb6('0x48')]['id'];}return db[_0x3bb6('0x2a')][_0x3bb6('0x4f')]({'where':{'id':_0x245160[_0x3bb6('0x45')]['id']}})['then'](handleEntityNotFound(_0x431a11,null))[_0x3bb6('0x23')](saveUpdates(_0x245160[_0x3bb6('0x48')],null))[_0x3bb6('0x23')](respondWithResult(_0x431a11,null))[_0x3bb6('0x43')](handleError(_0x431a11,null));};exports[_0x3bb6('0x22')]=function(_0x17a7d8,_0x3b0332){return db[_0x3bb6('0x2a')]['find']({'where':{'id':_0x17a7d8[_0x3bb6('0x45')]['id']}})['then'](handleEntityNotFound(_0x3b0332,null))['then'](removeEntity(_0x3b0332,null))[_0x3bb6('0x43')](handleError(_0x3b0332,null));};exports[_0x3bb6('0x50')]=function(_0x3cd954,_0xa5f3f7){return db['CmList'][_0x3bb6('0x50')]()[_0x3bb6('0x23')](respondWithResult(_0xa5f3f7,null))['catch'](handleError(_0xa5f3f7,null));};exports[_0x3bb6('0x51')]=function(_0x34a845,_0xd4af44,_0xc0f283){if(_0x34a845[_0x3bb6('0x48')]['id']){delete _0x34a845[_0x3bb6('0x48')]['id'];}return db['CmList'][_0x3bb6('0x4f')]({'where':{'id':_0x34a845['params']['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0xd4af44,null))[_0x3bb6('0x23')](function(_0x24b4ce){if(_0x24b4ce){_0x34a845['body']['ListId']=_0x24b4ce['id'];return db[_0x3bb6('0x52')]['create'](_0x34a845[_0x3bb6('0x48')]);}})[_0x3bb6('0x23')](respondWithResult(_0xd4af44,null))['catch'](handleError(_0xd4af44,null));};exports[_0x3bb6('0x53')]=function(_0x27efd7,_0xd9e5e5,_0x13d163){var _0x4b358d={'raw':![],'where':{}};var _0x1ba8cc={};var _0x1e1250={'count':0x0,'rows':[]};return db[_0x3bb6('0x2a')]['findOne']({'where':{'id':_0x27efd7[_0x3bb6('0x45')]['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0xd9e5e5,null))[_0x3bb6('0x23')](function(_0x4a948e){if(_0x4a948e){_0x1ba8cc[_0x3bb6('0x2e')]=_[_0x3bb6('0x30')](db[_0x3bb6('0x52')][_0x3bb6('0x46')]);_0x1ba8cc[_0x3bb6('0x2f')]=_[_0x3bb6('0x30')](_0x27efd7[_0x3bb6('0x2f')]);_0x1ba8cc[_0x3bb6('0x31')]=_[_0x3bb6('0x32')](_0x1ba8cc[_0x3bb6('0x2e')],_0x1ba8cc[_0x3bb6('0x2f')]);_0x4b358d[_0x3bb6('0x33')]=_[_0x3bb6('0x32')](_0x1ba8cc[_0x3bb6('0x2e')],qs['fields'](_0x27efd7[_0x3bb6('0x2f')][_0x3bb6('0x34')]));_0x4b358d[_0x3bb6('0x33')]=_0x4b358d['attributes'][_0x3bb6('0x35')]?_0x4b358d['attributes']:_0x1ba8cc[_0x3bb6('0x2e')];if(!_0x27efd7['query'][_0x3bb6('0x36')](_0x3bb6('0x37'))){_0x4b358d[_0x3bb6('0x1d')]=qs[_0x3bb6('0x1d')](_0x27efd7[_0x3bb6('0x2f')][_0x3bb6('0x1d')]);_0x4b358d[_0x3bb6('0x38')]=qs[_0x3bb6('0x38')](_0x27efd7[_0x3bb6('0x2f')][_0x3bb6('0x38')]);}_0x4b358d['order']=qs[_0x3bb6('0x3a')](_0x27efd7[_0x3bb6('0x2f')][_0x3bb6('0x3a')]);_0x4b358d[_0x3bb6('0x3d')]=qs[_0x3bb6('0x31')](_[_0x3bb6('0x3b')](_0x27efd7[_0x3bb6('0x2f')],_0x1ba8cc[_0x3bb6('0x31')]));_0x4b358d[_0x3bb6('0x3d')]['ListId']=_0x4a948e['id'];if(_0x27efd7[_0x3bb6('0x2f')][_0x3bb6('0x3c')]){_0x4b358d[_0x3bb6('0x3d')]=_['merge'](_0x4b358d[_0x3bb6('0x3d')],{'$or':_[_0x3bb6('0x29')](_0x4b358d['attributes'],function(_0x9ab4c4){var _0x490bb8={};_0x490bb8[_0x9ab4c4]={'$like':'%'+_0x27efd7[_0x3bb6('0x2f')][_0x3bb6('0x3c')]+'%'};return _0x490bb8;})});}_0x4b358d=_[_0x3bb6('0x3f')]({},_0x4b358d,_0x27efd7[_0x3bb6('0x40')]);return db['Disposition'][_0x3bb6('0x1c')]({'where':_0x4b358d['where']})['then'](function(_0x19e0f9){_0x1e1250['count']=_0x19e0f9;if(_0x27efd7[_0x3bb6('0x2f')]['includeAll']){_0x4b358d[_0x3bb6('0x42')]=[{'all':!![]}];}return db['Disposition'][_0x3bb6('0x54')](_0x4b358d);})[_0x3bb6('0x23')](function(_0x2a010c){_0x1e1250[_0x3bb6('0x55')]=_0x2a010c;return _0x1e1250;});}})[_0x3bb6('0x23')](respondWithFilteredResult(_0xd9e5e5,_0x4b358d))[_0x3bb6('0x43')](handleError(_0xd9e5e5,null));};exports[_0x3bb6('0x56')]=function(_0xbce05a,_0x1a46d0,_0x1e1ebd){return db[_0x3bb6('0x2a')][_0x3bb6('0x4f')]({'where':{'id':_0xbce05a[_0x3bb6('0x45')]['id']}})['then'](handleEntityNotFound(_0x1a46d0,null))[_0x3bb6('0x23')](function(_0x348254){if(_0x348254){return _0x348254['removeDispositions'](_0xbce05a[_0x3bb6('0x2f')]['ids']);}})['then'](respondWithStatusCode(_0x1a46d0,null))[_0x3bb6('0x43')](handleError(_0x1a46d0,null));};exports[_0x3bb6('0x57')]=function(_0x425009,_0x490238,_0x231fc7){return db[_0x3bb6('0x2a')][_0x3bb6('0x4f')]({'where':{'id':_0x425009['params']['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0x490238,null))[_0x3bb6('0x23')](function(_0x5dc906){if(_0x5dc906){var _0x4cc5be=[];var _0xf9b3cf={'success':[],'errors':[]};return db[_0x3bb6('0x58')][_0x3bb6('0x50')]()['then'](function(_0x2c62fe){if(_0x425009[_0x3bb6('0x48')][_0x3bb6('0x59')]&&_[_0x3bb6('0x5a')](_0x425009['body']['tags'])){if(_0x425009[_0x3bb6('0x48')][_0x3bb6('0x59')]['length']){_0x425009[_0x3bb6('0x48')][_0x3bb6('0x59')]=_0x425009[_0x3bb6('0x48')]['tags'][_0x3bb6('0x5b')](';')+';';}else{_0x425009[_0x3bb6('0x48')][_0x3bb6('0x59')]=null;}}else{_0x425009[_0x3bb6('0x48')][_0x3bb6('0x59')]=null;}if(_0x425009[_0x3bb6('0x48')]&&_[_0x3bb6('0x5a')](_0x425009[_0x3bb6('0x48')])){for(var _0x3634b3=0x0;_0x3634b3<_0x425009[_0x3bb6('0x48')]['length'];_0x3634b3+=0x1){_0x425009[_0x3bb6('0x48')][_0x3634b3][_0x3bb6('0x5c')]=_0x425009[_0x3bb6('0x45')]['id'];_0x4cc5be['push'](_0x425009['body'][_0x3634b3]);}return BPromise[_0x3bb6('0x5d')](_0x4cc5be,function(_0x10d27f){return db[_0x3bb6('0x58')][_0x3bb6('0x47')](_[_0x3bb6('0x5e')](_0x10d27f,[_0x3bb6('0x5f'),'id'])||{},{'fields':_[_0x3bb6('0x30')](_0x2c62fe),'raw':!![]})[_0x3bb6('0x23')](function(_0x294646){_0xf9b3cf[_0x3bb6('0x60')]['push'](_0x294646[_0x3bb6('0x61')]);})[_0x3bb6('0x43')](function(_0x150ceb){_0xf9b3cf['errors']['push']({'data':_0x10d27f,'error':_0x150ceb[_0x3bb6('0x62')]});});})[_0x3bb6('0x23')](function(_0x5624b4){return _0xf9b3cf;})['catch'](function(_0x47162d){return _0x47162d;});}else{_0x490238[_0x3bb6('0x1a')](0x190)[_0x3bb6('0x1b')]({'message':_0x3bb6('0x63')});}});}})[_0x3bb6('0x23')](respondWithResult(_0x490238,null))[_0x3bb6('0x43')](handleError(_0x490238,null));};exports['getContacts']=function(_0x598666,_0x197211,_0x5bdb87){var _0x10be7f;return db['CmList'][_0x3bb6('0x4f')]({'where':{'id':_0x598666['params']['id']},'include':[{'model':db[_0x3bb6('0x64')],'as':_0x3bb6('0x65')}]})['then'](handleEntityNotFound(_0x197211,null))[_0x3bb6('0x23')](function(_0x30184a){if(_0x30184a){_0x10be7f=_0x30184a;return db[_0x3bb6('0x58')][_0x3bb6('0x46')];}})[_0x3bb6('0x23')](function(_0x463790){if(_0x463790){var _0x1061c4={};var _0x5d6f96={};_0x5d6f96[_0x3bb6('0x2e')]=_[_0x3bb6('0x66')](_['keys'](_0x463790),_[_0x3bb6('0x29')](_0x10be7f[_0x3bb6('0x65')],function(_0x5c34be){return util[_0x3bb6('0x67')](_0x3bb6('0x68'),_0x5c34be['id']);}));_0x5d6f96[_0x3bb6('0x2f')]=_['keys'](_0x598666[_0x3bb6('0x2f')]);_0x5d6f96[_0x3bb6('0x31')]=_['intersection'](_0x5d6f96[_0x3bb6('0x2e')],_0x5d6f96[_0x3bb6('0x2f')]);_0x1061c4[_0x3bb6('0x33')]=_[_0x3bb6('0x32')](_0x5d6f96['model'],qs['fields'](_0x598666[_0x3bb6('0x2f')][_0x3bb6('0x34')]));_0x1061c4[_0x3bb6('0x33')]=_0x1061c4[_0x3bb6('0x33')]['length']?_0x1061c4[_0x3bb6('0x33')]:_0x5d6f96[_0x3bb6('0x2e')];if(!_0x598666[_0x3bb6('0x2f')]['hasOwnProperty'](_0x3bb6('0x37'))){_0x1061c4[_0x3bb6('0x1d')]=qs[_0x3bb6('0x1d')](_0x598666[_0x3bb6('0x2f')]['limit']);_0x1061c4[_0x3bb6('0x38')]=qs['offset'](_0x598666[_0x3bb6('0x2f')][_0x3bb6('0x38')]);}_0x1061c4[_0x3bb6('0x39')]=qs[_0x3bb6('0x3a')](_0x598666[_0x3bb6('0x2f')][_0x3bb6('0x3a')]);_0x1061c4[_0x3bb6('0x3d')]=qs[_0x3bb6('0x31')](_['pick'](_0x598666[_0x3bb6('0x2f')],_0x5d6f96[_0x3bb6('0x31')]));_0x1061c4['raw']=!![];if(_0x598666[_0x3bb6('0x2f')]['filter']){_0x1061c4[_0x3bb6('0x3d')]=_[_0x3bb6('0x3f')](_0x1061c4[_0x3bb6('0x3d')],{'$or':_[_0x3bb6('0x29')](_0x1061c4['attributes'],function(_0x1b66be){var _0x313236={};_0x313236[_0x1b66be]={'$like':'%'+_0x598666[_0x3bb6('0x2f')][_0x3bb6('0x3c')]+'%'};return _0x313236;})});}_0x1061c4=_[_0x3bb6('0x3f')]({},_0x1061c4,_0x598666['options']);return _0x10be7f[_0x3bb6('0x69')](_0x1061c4);}})['then'](respondWithResult(_0x197211,null))['catch'](handleError(_0x197211,null));};exports[_0x3bb6('0x6a')]=function(_0x334b2d,_0x4a37cf,_0x1bce92){var _0x2ac268;return db[_0x3bb6('0x2a')]['find']({'where':{'id':_0x334b2d[_0x3bb6('0x45')]['id']},'include':[{'model':db[_0x3bb6('0x64')],'as':_0x3bb6('0x65')}]})[_0x3bb6('0x23')](handleEntityNotFound(_0x4a37cf,null))[_0x3bb6('0x23')](function(_0x199ec2){if(_0x199ec2){_0x2ac268=_0x199ec2;return db[_0x3bb6('0x58')][_0x3bb6('0x46')];}})[_0x3bb6('0x23')](function(_0x38295d){if(_0x38295d){var _0x7fd428={};var _0x8ccceb={};_0x8ccceb[_0x3bb6('0x2e')]=_[_0x3bb6('0x66')](_[_0x3bb6('0x30')](_0x38295d),_['map'](_0x2ac268[_0x3bb6('0x65')],function(_0x16a3a7){return util['format'](_0x3bb6('0x68'),_0x16a3a7['id']);}));_0x8ccceb[_0x3bb6('0x2f')]=_[_0x3bb6('0x30')](_0x334b2d[_0x3bb6('0x2f')]);_0x8ccceb[_0x3bb6('0x31')]=_[_0x3bb6('0x32')](_0x8ccceb['model'],_0x8ccceb[_0x3bb6('0x2f')]);_0x7fd428[_0x3bb6('0x33')]=_['intersection'](_0x8ccceb[_0x3bb6('0x2e')],qs[_0x3bb6('0x34')](_0x334b2d[_0x3bb6('0x2f')][_0x3bb6('0x34')]));_0x7fd428[_0x3bb6('0x33')]=_0x7fd428[_0x3bb6('0x33')][_0x3bb6('0x35')]?_0x7fd428[_0x3bb6('0x33')]:_0x8ccceb[_0x3bb6('0x2e')];if(!_0x334b2d[_0x3bb6('0x2f')][_0x3bb6('0x36')](_0x3bb6('0x37'))){_0x7fd428['limit']=qs['limit'](_0x334b2d[_0x3bb6('0x2f')][_0x3bb6('0x1d')]);_0x7fd428[_0x3bb6('0x38')]=qs['offset'](_0x334b2d['query'][_0x3bb6('0x38')]);}_0x7fd428['order']=qs[_0x3bb6('0x3a')](_0x334b2d['query']['sort']);_0x7fd428[_0x3bb6('0x3d')]=qs[_0x3bb6('0x31')](_[_0x3bb6('0x3b')](_0x334b2d[_0x3bb6('0x2f')],_0x8ccceb[_0x3bb6('0x31')]));_0x7fd428[_0x3bb6('0x6b')]=!![];if(_0x334b2d[_0x3bb6('0x2f')][_0x3bb6('0x3c')]){_0x7fd428[_0x3bb6('0x3d')]=_['merge'](_0x7fd428[_0x3bb6('0x3d')],{'$or':_['map'](_0x7fd428[_0x3bb6('0x33')],function(_0x391f68){var _0xa65dc9={};_0xa65dc9[_0x391f68]={'$like':'%'+_0x334b2d['query']['filter']+'%'};return _0xa65dc9;})});}_0x7fd428=_[_0x3bb6('0x3f')]({},_0x7fd428,_0x334b2d[_0x3bb6('0x40')]);return _0x2ac268['getContacts'](_0x7fd428);}})['then'](function(_0x43e807){if(!_[_0x3bb6('0x6c')](_0x43e807)){var _0x5bfe3d=toCsv(_0x43e807);var _0x498257=Date['now']();fs[_0x3bb6('0x6d')](util[_0x3bb6('0x67')](_0x3bb6('0x6e'),_0x2ac268['id'],_0x498257),_0x5bfe3d);_0x4a37cf['setHeader'](_0x3bb6('0x6f'),'attachment;\x20filename='+util['format'](_0x3bb6('0x70'),_0x2ac268['id'],_0x498257));_0x4a37cf[_0x3bb6('0x71')](_0x3bb6('0x72'),_0x3bb6('0x73'));return _0x4a37cf[_0x3bb6('0x74')](util['format'](_0x3bb6('0x6e'),_0x2ac268['id'],_0x498257));}else{return _0x4a37cf[_0x3bb6('0x18')](0xcc);}})[_0x3bb6('0x43')](handleError(_0x4a37cf,null));};exports[_0x3bb6('0x75')]=function(_0x285d34,_0xf556e0,_0x14c447){var _0x4bfd29;delete _0x285d34['body']['id'];return db['CmList']['findOne']({'where':{'id':_0x285d34[_0x3bb6('0x45')]['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0xf556e0,null))[_0x3bb6('0x23')](function(_0x3b7911){if(_0x3b7911){return db['sequelize'][_0x3bb6('0x76')](function(_0x290a05){return db[_0x3bb6('0x64')][_0x3bb6('0x47')](_0x285d34['body'],{'transaction':_0x290a05})[_0x3bb6('0x23')](function(_0x2a11df){_0x4bfd29=_0x2a11df;return _0x3b7911[_0x3bb6('0x77')](_0x2a11df,{'transaction':_0x290a05});})[_0x3bb6('0x23')](function(){var _0x202716={'type':db[_0x3bb6('0x78')][_0x3bb6('0x79')],'transaction':_0x290a05};switch(_0x285d34[_0x3bb6('0x48')][_0x3bb6('0x2c')]){case'text':_0x202716['type']=db[_0x3bb6('0x78')][_0x3bb6('0x79')];break;case'number':_0x202716[_0x3bb6('0x2c')]=db['Sequelize'][_0x3bb6('0x7a')];break;case _0x3bb6('0x7b'):_0x202716[_0x3bb6('0x2c')]=db[_0x3bb6('0x78')][_0x3bb6('0x7c')];_0x202716[_0x3bb6('0x7d')]=![];break;default:}return db[_0x3bb6('0x7e')][_0x3bb6('0x7f')][_0x3bb6('0x80')](_0x3bb6('0x81'),util[_0x3bb6('0x67')](_0x3bb6('0x82'),_0x4bfd29['id']),_0x202716);})[_0x3bb6('0x23')](function(){return _0x4bfd29;});});}})[_0x3bb6('0x23')](respondWithResult(_0xf556e0,null))[_0x3bb6('0x43')](handleError(_0xf556e0,null));};exports['getCustomFields']=function(_0x49c082,_0x3621b7,_0x15860b){var _0x498701={};var _0x58b787={};var _0x3df710;var _0x5e1f42;return db[_0x3bb6('0x2a')][_0x3bb6('0x83')]({'where':{'id':_0x49c082[_0x3bb6('0x45')]['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0x3621b7,null))[_0x3bb6('0x23')](function(_0x261633){if(_0x261633){_0x3df710=_0x261633;_0x58b787[_0x3bb6('0x2e')]=_[_0x3bb6('0x30')](db[_0x3bb6('0x64')][_0x3bb6('0x46')]);_0x58b787[_0x3bb6('0x2f')]=_['keys'](_0x49c082[_0x3bb6('0x2f')]);_0x58b787['filters']=_[_0x3bb6('0x32')](_0x58b787[_0x3bb6('0x2e')],_0x58b787[_0x3bb6('0x2f')]);_0x498701[_0x3bb6('0x33')]=_[_0x3bb6('0x32')](_0x58b787[_0x3bb6('0x2e')],qs[_0x3bb6('0x34')](_0x49c082[_0x3bb6('0x2f')][_0x3bb6('0x34')]));_0x498701['attributes']=_0x498701[_0x3bb6('0x33')][_0x3bb6('0x35')]?_0x498701[_0x3bb6('0x33')]:_0x58b787[_0x3bb6('0x2e')];_0x498701[_0x3bb6('0x39')]=qs[_0x3bb6('0x3a')](_0x49c082[_0x3bb6('0x2f')][_0x3bb6('0x3a')]);_0x498701[_0x3bb6('0x3d')]=qs[_0x3bb6('0x31')](_[_0x3bb6('0x3b')](_0x49c082['query'],_0x58b787[_0x3bb6('0x31')]));_0x498701['where']=_['merge'](_0x498701[_0x3bb6('0x3d')],{'$or':[{'ListId':_0x261633['id']},{'ListId':null}]});if(_0x49c082['query'][_0x3bb6('0x3c')]){_0x498701[_0x3bb6('0x3d')]=_[_0x3bb6('0x3f')](_0x498701[_0x3bb6('0x3d')],{'$or':_[_0x3bb6('0x29')](_0x498701[_0x3bb6('0x33')],function(_0x32f5d4){var _0x26e096={};_0x26e096[_0x32f5d4]={'$like':'%'+_0x49c082[_0x3bb6('0x2f')][_0x3bb6('0x3c')]+'%'};return _0x26e096;})});}_0x498701=_[_0x3bb6('0x3f')]({},_0x498701,_0x49c082[_0x3bb6('0x40')]);return db[_0x3bb6('0x64')]['findAndCountAll'](_0x498701);}})[_0x3bb6('0x23')](respondWithResult(_0x3621b7,null))[_0x3bb6('0x43')](handleError(_0x3621b7,null));};exports[_0x3bb6('0x84')]=function(_0x39a57c,_0x4d2ad7,_0x58facc){return db[_0x3bb6('0x2a')][_0x3bb6('0x4f')]({'where':{'id':_0x39a57c['params']['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0x4d2ad7,null))['then'](function(_0x4835c9){if(_0x4835c9){return _0x4835c9[_0x3bb6('0x84')](_0x39a57c[_0x3bb6('0x48')][_0x3bb6('0x5f')],_['omit'](_0x39a57c[_0x3bb6('0x48')],[_0x3bb6('0x5f'),'id'])||{})[_0x3bb6('0x85')](function(_0x195dc2){for(var _0x24fb0a=0x0;_0x24fb0a<_0x39a57c[_0x3bb6('0x48')]['ids'][_0x3bb6('0x35')];_0x24fb0a+=0x1){socket[_0x3bb6('0x86')](_0x3bb6('0x87'),{'UserId':_0x39a57c[_0x3bb6('0x48')]['ids'][_0x24fb0a],'CmListId':_0x39a57c['params']['id']});}return _0x195dc2;});}})['then'](respondWithResult(_0x4d2ad7,null))[_0x3bb6('0x43')](handleError(_0x4d2ad7,null));};exports[_0x3bb6('0x88')]=function(_0x55ab71,_0xf6d2e7,_0xb88bf3){return db[_0x3bb6('0x2a')][_0x3bb6('0x4f')]({'where':{'id':_0x55ab71['params']['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0xf6d2e7,null))[_0x3bb6('0x23')](function(_0x46da74){if(_0x46da74){return _0x46da74[_0x3bb6('0x88')](_0x55ab71[_0x3bb6('0x2f')][_0x3bb6('0x5f')])[_0x3bb6('0x23')](function(){if(_['isArray'](_0x55ab71[_0x3bb6('0x2f')][_0x3bb6('0x5f')])){for(var _0x3af00b=0x0;_0x3af00b<_0x55ab71['query'][_0x3bb6('0x5f')][_0x3bb6('0x35')];_0x3af00b+=0x1){socket['emit'](_0x3bb6('0x89'),{'UserId':Number(_0x55ab71[_0x3bb6('0x2f')][_0x3bb6('0x5f')][_0x3af00b]),'CmListId':Number(_0x55ab71[_0x3bb6('0x45')]['id'])});}}else{socket['emit'](_0x3bb6('0x89'),{'UserId':Number(_0x55ab71[_0x3bb6('0x2f')][_0x3bb6('0x5f')]),'CmListId':Number(_0x55ab71[_0x3bb6('0x45')]['id'])});}});}})[_0x3bb6('0x23')](respondWithStatusCode(_0xf6d2e7,null))['catch'](handleError(_0xf6d2e7,null));};exports[_0x3bb6('0x8a')]=function(_0x757dc4,_0x287371,_0x2f5c35){var _0x1660ef={};var _0x393882={};var _0x4b8508;var _0x215f18;return db[_0x3bb6('0x2a')][_0x3bb6('0x83')]({'where':{'id':_0x757dc4[_0x3bb6('0x45')]['id']}})[_0x3bb6('0x23')](handleEntityNotFound(_0x287371,null))['then'](function(_0x1d4378){if(_0x1d4378){_0x4b8508=_0x1d4378;_0x393882['model']=_[_0x3bb6('0x30')](db[_0x3bb6('0x8b')][_0x3bb6('0x46')]);_0x393882[_0x3bb6('0x2f')]=_[_0x3bb6('0x30')](_0x757dc4['query']);_0x393882[_0x3bb6('0x31')]=_[_0x3bb6('0x32')](_0x393882[_0x3bb6('0x2e')],_0x393882[_0x3bb6('0x2f')]);_0x1660ef['attributes']=_[_0x3bb6('0x32')](_0x393882[_0x3bb6('0x2e')],qs['fields'](_0x757dc4[_0x3bb6('0x2f')][_0x3bb6('0x34')]));_0x1660ef[_0x3bb6('0x33')]=_0x1660ef[_0x3bb6('0x33')][_0x3bb6('0x35')]?_0x1660ef[_0x3bb6('0x33')]:_0x393882['model'];_0x1660ef['order']=qs[_0x3bb6('0x3a')](_0x757dc4[_0x3bb6('0x2f')]['sort']);_0x1660ef[_0x3bb6('0x3d')]=qs[_0x3bb6('0x31')](_['pick'](_0x757dc4[_0x3bb6('0x2f')],_0x393882[_0x3bb6('0x31')]));if(_0x757dc4['query']['filter']){_0x1660ef[_0x3bb6('0x3d')]=_[_0x3bb6('0x3f')](_0x1660ef[_0x3bb6('0x3d')],{'$or':_[_0x3bb6('0x29')](_0x1660ef['attributes'],function(_0x1a9ee8){var _0x15eb13={};_0x15eb13[_0x1a9ee8]={'$like':'%'+_0x757dc4['query'][_0x3bb6('0x3c')]+'%'};return _0x15eb13;})});}_0x1660ef=_[_0x3bb6('0x3f')]({},_0x1660ef,_0x757dc4['options']);return _0x4b8508[_0x3bb6('0x8a')](_0x1660ef);}})[_0x3bb6('0x23')](function(_0xdf1f99){if(_0xdf1f99){_0x215f18=_0xdf1f99['length'];if(!_0x757dc4[_0x3bb6('0x2f')][_0x3bb6('0x36')]('nolimit')){_0x1660ef[_0x3bb6('0x1d')]=qs[_0x3bb6('0x1d')](_0x757dc4[_0x3bb6('0x2f')][_0x3bb6('0x1d')]);_0x1660ef[_0x3bb6('0x38')]=qs[_0x3bb6('0x38')](_0x757dc4[_0x3bb6('0x2f')][_0x3bb6('0x38')]);}return _0x4b8508[_0x3bb6('0x8a')](_0x1660ef);}})[_0x3bb6('0x23')](function(_0x2f091c){if(_0x2f091c){return _0x2f091c?{'count':_0x215f18,'rows':_0x2f091c}:null;}})[_0x3bb6('0x23')](respondWithResult(_0x287371,null))[_0x3bb6('0x43')](handleError(_0x287371,null));};