f0e29b6acd87e54440e44a111ed8a1bd1b4394d4
[motion2.git] / server / api / analyticFieldReport / analyticFieldReport.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 _0x6f69=['catch','bulkCreate','bulkDestroy','ids','addFields','findOne','params','sequelize','transaction','CustomReportId','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','update','destroy','error','stack','name','index','map','AnalyticFieldReport','rawAttributes','fieldName','key','model','keys','filters','query','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','options','then','includeAll','include','findAll','rows','show','length','find','create','body'];(function(_0x5ea5b1,_0x1b0bb8){var _0x2c5608=function(_0x4865dc){while(--_0x4865dc){_0x5ea5b1['push'](_0x5ea5b1['shift']());}};_0x2c5608(++_0x1b0bb8);}(_0x6f69,0x103));var _0x96f6=function(_0x279ff5,_0xd86cc1){_0x279ff5=_0x279ff5-0x0;var _0xf95c06=_0x6f69[_0x279ff5];return _0xf95c06;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x96f6('0x0'));var zipdir=require(_0x96f6('0x1'));var jsonpatch=require(_0x96f6('0x2'));var rp=require(_0x96f6('0x3'));var moment=require(_0x96f6('0x4'));var BPromise=require(_0x96f6('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x96f6('0x6'));var sox=require(_0x96f6('0x7'));var csv=require(_0x96f6('0x8'));var ejs=require(_0x96f6('0x9'));var fs=require('fs');var fs_extra=require(_0x96f6('0xa'));var _=require(_0x96f6('0xb'));var squel=require('squel');var crypto=require(_0x96f6('0xc'));var jsforce=require(_0x96f6('0xd'));var deskjs=require(_0x96f6('0xe'));var toCsv=require('to-csv');var querystring=require(_0x96f6('0xf'));var Papa=require(_0x96f6('0x10'));var Redis=require('ioredis');var authService=require(_0x96f6('0x11'));var qs=require(_0x96f6('0x12'));var as=require(_0x96f6('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x96f6('0x14'))(_0x96f6('0x15'));var utils=require(_0x96f6('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x96f6('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5d200e,_0x3b1c3b){_0x3b1c3b=_0x3b1c3b||0xcc;return function(_0x21dc40){if(_0x21dc40){return _0x5d200e[_0x96f6('0x18')](_0x3b1c3b);}return _0x5d200e[_0x96f6('0x19')](_0x3b1c3b)[_0x96f6('0x1a')]();};}function respondWithResult(_0xc1ff84,_0x291a7c){_0x291a7c=_0x291a7c||0xc8;return function(_0x9b4168){if(_0x9b4168){return _0xc1ff84[_0x96f6('0x19')](_0x291a7c)[_0x96f6('0x1b')](_0x9b4168);}};}function respondWithFilteredResult(_0x53e58b,_0x467aac){return function(_0x4da8ca){if(_0x4da8ca){var _0x51cbfe=typeof _0x467aac[_0x96f6('0x1c')]===_0x96f6('0x1d')&&typeof _0x467aac[_0x96f6('0x1e')]===_0x96f6('0x1d');var _0x4bc07b=_0x4da8ca[_0x96f6('0x1f')];var _0x29645c=_0x51cbfe?0x0:_0x467aac[_0x96f6('0x1c')];var _0x304828=_0x51cbfe?_0x4da8ca[_0x96f6('0x1f')]:_0x467aac[_0x96f6('0x1c')]+_0x467aac[_0x96f6('0x1e')];var _0x420497;if(_0x304828>=_0x4bc07b){_0x304828=_0x4bc07b;_0x420497=0xc8;}else{_0x420497=0xce;}_0x53e58b[_0x96f6('0x19')](_0x420497);return _0x53e58b[_0x96f6('0x20')](_0x96f6('0x21'),_0x29645c+'-'+_0x304828+'/'+_0x4bc07b)['json'](_0x4da8ca);}return null;};}function patchUpdates(_0x21b916){return function(_0xa94eb4){try{jsonpatch[_0x96f6('0x22')](_0xa94eb4,_0x21b916,!![]);}catch(_0x26eed4){return BPromise['reject'](_0x26eed4);}return _0xa94eb4['save']();};}function saveUpdates(_0x340cad,_0x4916f6){return function(_0x2f93ea){if(_0x2f93ea){return _0x2f93ea[_0x96f6('0x23')](_0x340cad)['then'](function(_0x564e29){return _0x564e29;});}return null;};}function removeEntity(_0x58d28e,_0x441cf0){return function(_0xf8feaf){if(_0xf8feaf){return _0xf8feaf[_0x96f6('0x24')]()['then'](function(){_0x58d28e[_0x96f6('0x19')](0xcc)[_0x96f6('0x1a')]();});}};}function handleEntityNotFound(_0x5b6101,_0x192e5a){return function(_0xe3a420){if(!_0xe3a420){_0x5b6101[_0x96f6('0x18')](0x194);}return _0xe3a420;};}function handleError(_0x1b02d4,_0xf7786c){_0xf7786c=_0xf7786c||0x1f4;return function(_0x318af2){logger[_0x96f6('0x25')](_0x318af2[_0x96f6('0x26')]);if(_0x318af2[_0x96f6('0x27')]){delete _0x318af2['name'];}_0x1b02d4[_0x96f6('0x19')](_0xf7786c)['send'](_0x318af2);};}exports[_0x96f6('0x28')]=function(_0x4806c1,_0xb5ea66){var _0x7737e9={},_0x38b456={},_0x44aa22={'count':0x0,'rows':[]};var _0x1fe455=_[_0x96f6('0x29')](db[_0x96f6('0x2a')][_0x96f6('0x2b')],function(_0x3cee30){return{'name':_0x3cee30[_0x96f6('0x2c')],'type':_0x3cee30['type'][_0x96f6('0x2d')]};});_0x38b456[_0x96f6('0x2e')]=_[_0x96f6('0x29')](_0x1fe455,_0x96f6('0x27'));_0x38b456['query']=_[_0x96f6('0x2f')](_0x4806c1['query']);_0x38b456[_0x96f6('0x30')]=_['intersection'](_0x38b456[_0x96f6('0x2e')],_0x38b456[_0x96f6('0x31')]);_0x7737e9[_0x96f6('0x32')]=_[_0x96f6('0x33')](_0x38b456[_0x96f6('0x2e')],qs[_0x96f6('0x34')](_0x4806c1[_0x96f6('0x31')][_0x96f6('0x34')]));_0x7737e9[_0x96f6('0x32')]=_0x7737e9['attributes']['length']?_0x7737e9['attributes']:_0x38b456[_0x96f6('0x2e')];if(!_0x4806c1[_0x96f6('0x31')][_0x96f6('0x35')](_0x96f6('0x36'))){_0x7737e9['limit']=qs[_0x96f6('0x1e')](_0x4806c1[_0x96f6('0x31')][_0x96f6('0x1e')]);_0x7737e9[_0x96f6('0x1c')]=qs[_0x96f6('0x1c')](_0x4806c1[_0x96f6('0x31')][_0x96f6('0x1c')]);}_0x7737e9[_0x96f6('0x37')]=qs[_0x96f6('0x38')](_0x4806c1['query'][_0x96f6('0x38')]);_0x7737e9['where']=qs['filters'](_[_0x96f6('0x39')](_0x4806c1[_0x96f6('0x31')],_0x38b456[_0x96f6('0x30')]),_0x1fe455);if(_0x4806c1[_0x96f6('0x31')][_0x96f6('0x3a')]){_0x7737e9[_0x96f6('0x3b')]=_[_0x96f6('0x3c')](_0x7737e9['where'],{'$or':_[_0x96f6('0x29')](_0x1fe455,function(_0x17b885){if(_0x17b885[_0x96f6('0x3d')]!=='VIRTUAL'){var _0x26e40a={};_0x26e40a[_0x17b885[_0x96f6('0x27')]]={'$like':'%'+_0x4806c1[_0x96f6('0x31')][_0x96f6('0x3a')]+'%'};return _0x26e40a;}})});}_0x7737e9=_[_0x96f6('0x3c')]({},_0x7737e9,_0x4806c1[_0x96f6('0x3e')]);var _0x328dc9={'where':_0x7737e9[_0x96f6('0x3b')]};return db[_0x96f6('0x2a')]['count'](_0x328dc9)[_0x96f6('0x3f')](function(_0x497063){_0x44aa22['count']=_0x497063;if(_0x4806c1['query'][_0x96f6('0x40')]){_0x7737e9[_0x96f6('0x41')]=[{'all':!![]}];}return db[_0x96f6('0x2a')][_0x96f6('0x42')](_0x7737e9);})[_0x96f6('0x3f')](function(_0x4f5fec){_0x44aa22[_0x96f6('0x43')]=_0x4f5fec;return _0x44aa22;})['then'](respondWithFilteredResult(_0xb5ea66,_0x7737e9))['catch'](handleError(_0xb5ea66,null));};exports[_0x96f6('0x44')]=function(_0x2511a6,_0xe374d){var _0xc0319c={'raw':![],'where':{'id':_0x2511a6['params']['id']}},_0x5b59cd={};_0x5b59cd[_0x96f6('0x2e')]=_[_0x96f6('0x2f')](db['AnalyticFieldReport'][_0x96f6('0x2b')]);_0x5b59cd[_0x96f6('0x31')]=_['keys'](_0x2511a6[_0x96f6('0x31')]);_0x5b59cd[_0x96f6('0x30')]=_[_0x96f6('0x33')](_0x5b59cd['model'],_0x5b59cd[_0x96f6('0x31')]);_0xc0319c[_0x96f6('0x32')]=_[_0x96f6('0x33')](_0x5b59cd[_0x96f6('0x2e')],qs['fields'](_0x2511a6[_0x96f6('0x31')][_0x96f6('0x34')]));_0xc0319c['attributes']=_0xc0319c[_0x96f6('0x32')][_0x96f6('0x45')]?_0xc0319c[_0x96f6('0x32')]:_0x5b59cd[_0x96f6('0x2e')];if(_0x2511a6[_0x96f6('0x31')][_0x96f6('0x40')]){_0xc0319c[_0x96f6('0x41')]=[{'all':!![]}];}_0xc0319c=_[_0x96f6('0x3c')]({},_0xc0319c,_0x2511a6[_0x96f6('0x3e')]);return db[_0x96f6('0x2a')][_0x96f6('0x46')](_0xc0319c)[_0x96f6('0x3f')](handleEntityNotFound(_0xe374d,null))['then'](respondWithResult(_0xe374d,null))['catch'](handleError(_0xe374d,null));};exports['create']=function(_0x58b9ba,_0x5bfa81){return db[_0x96f6('0x2a')][_0x96f6('0x47')](_0x58b9ba[_0x96f6('0x48')],{})[_0x96f6('0x3f')](respondWithResult(_0x5bfa81,0xc9))[_0x96f6('0x49')](handleError(_0x5bfa81,null));};exports[_0x96f6('0x4a')]=function(_0x15b8a2,_0x3f1614){return db[_0x96f6('0x2a')][_0x96f6('0x4a')](_0x15b8a2['body'],{'raw':![],'individualHooks':!![]})[_0x96f6('0x3f')](respondWithResult(_0x3f1614,0xc9))[_0x96f6('0x49')](handleError(_0x3f1614,null));};exports[_0x96f6('0x23')]=function(_0x3eeec9,_0x2c7d71){if(_0x3eeec9[_0x96f6('0x48')]['id']){delete _0x3eeec9['body']['id'];}return db[_0x96f6('0x2a')][_0x96f6('0x46')]({'where':{'id':_0x3eeec9['params']['id']}})['then'](handleEntityNotFound(_0x2c7d71,null))[_0x96f6('0x3f')](saveUpdates(_0x3eeec9['body'],null))[_0x96f6('0x3f')](respondWithResult(_0x2c7d71,null))[_0x96f6('0x49')](handleError(_0x2c7d71,null));};exports[_0x96f6('0x24')]=function(_0x783e6b,_0xe1e474){return db[_0x96f6('0x2a')]['find']({'where':{'id':_0x783e6b['params']['id']}})[_0x96f6('0x3f')](handleEntityNotFound(_0xe1e474,null))[_0x96f6('0x3f')](removeEntity(_0xe1e474,null))['catch'](handleError(_0xe1e474,null));};exports[_0x96f6('0x4b')]=function(_0x2e2e70,_0x1a6bef){return db[_0x96f6('0x2a')]['destroy']({'where':{'id':_0x2e2e70[_0x96f6('0x31')][_0x96f6('0x4c')]||[]},'raw':![],'individualHooks':!![]})[_0x96f6('0x3f')](respondWithResult(_0x1a6bef,0xcc))[_0x96f6('0x49')](handleError(_0x1a6bef,null));};exports[_0x96f6('0x4d')]=function(_0x368f31,_0x30f073,_0x3d1a3c){return db['AnalyticCustomReport'][_0x96f6('0x4e')]({'where':{'id':_0x368f31[_0x96f6('0x4f')]['id']}})[_0x96f6('0x3f')](handleEntityNotFound(_0x30f073,null))[_0x96f6('0x3f')](function(_0x54278c){if(_0x54278c){return db[_0x96f6('0x50')][_0x96f6('0x51')](function(_0x3df32a){return db[_0x96f6('0x2a')][_0x96f6('0x24')]({'where':{'CustomReportId':_0x368f31[_0x96f6('0x4f')]['id']},'transaction':_0x3df32a})['then'](function(_0x463f62){var _0x265adb=_[_0x96f6('0x29')](_0x368f31['body'],function(_0xda8c82){delete _0xda8c82['id'];_0xda8c82[_0x96f6('0x52')]=_0x368f31[_0x96f6('0x4f')]['id'];return _0xda8c82;});return db[_0x96f6('0x2a')][_0x96f6('0x4a')](_0x265adb,{'transaction':_0x3df32a});});})['then'](function(){return db[_0x96f6('0x2a')]['findAll']({'where':{'CustomReportId':_0x368f31[_0x96f6('0x4f')]['id']}});});}})[_0x96f6('0x3f')](respondWithResult(_0x30f073,null))[_0x96f6('0x49')](handleError(_0x30f073,null));};