Built motion from commit fe909640.|2.6.8
[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 _0x1f36=['options','find','create','bulkCreate','body','params','bulkDestroy','ids','addFields','findOne','sequelize','transaction','findAll','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','status','offset','limit','undefined','count','Content-Range','json','save','update','then','destroy','error','stack','name','send','index','key','map','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','VIRTUAL','AnalyticFieldReport','includeAll','include','catch','show','rawAttributes'];(function(_0xbbff02,_0x3e239b){var _0x31abbf=function(_0x5754ce){while(--_0x5754ce){_0xbbff02['push'](_0xbbff02['shift']());}};_0x31abbf(++_0x3e239b);}(_0x1f36,0x1ed));var _0x61f3=function(_0x28e28b,_0x340c0f){_0x28e28b=_0x28e28b-0x0;var _0x40a4e1=_0x1f36[_0x28e28b];return _0x40a4e1;};'use strict';var emlformat=require(_0x61f3('0x0'));var rimraf=require(_0x61f3('0x1'));var zipdir=require(_0x61f3('0x2'));var jsonpatch=require(_0x61f3('0x3'));var rp=require('request-promise');var moment=require(_0x61f3('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x61f3('0x5'));var util=require(_0x61f3('0x6'));var path=require(_0x61f3('0x7'));var sox=require(_0x61f3('0x8'));var csv=require(_0x61f3('0x9'));var ejs=require(_0x61f3('0xa'));var fs=require('fs');var fs_extra=require(_0x61f3('0xb'));var _=require('lodash');var squel=require(_0x61f3('0xc'));var crypto=require(_0x61f3('0xd'));var jsforce=require(_0x61f3('0xe'));var deskjs=require(_0x61f3('0xf'));var toCsv=require(_0x61f3('0x9'));var querystring=require(_0x61f3('0x10'));var Papa=require(_0x61f3('0x11'));var Redis=require('ioredis');var authService=require(_0x61f3('0x12'));var qs=require(_0x61f3('0x13'));var as=require(_0x61f3('0x14'));var hardwareService=require(_0x61f3('0x15'));var logger=require(_0x61f3('0x16'))('api');var utils=require(_0x61f3('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x61f3('0x18'));var db=require(_0x61f3('0x19'))['db'];function respondWithStatusCode(_0x5c50a1,_0x2d70e0){_0x2d70e0=_0x2d70e0||0xcc;return function(_0x2eacb1){if(_0x2eacb1){return _0x5c50a1['sendStatus'](_0x2d70e0);}return _0x5c50a1[_0x61f3('0x1a')](_0x2d70e0)['end']();};}function respondWithResult(_0x42c8b4,_0x41a09b){_0x41a09b=_0x41a09b||0xc8;return function(_0x4d3130){if(_0x4d3130){return _0x42c8b4[_0x61f3('0x1a')](_0x41a09b)['json'](_0x4d3130);}};}function respondWithFilteredResult(_0x1b74c4,_0x222d54){return function(_0x2212c3){if(_0x2212c3){var _0x55c02e=typeof _0x222d54[_0x61f3('0x1b')]==='undefined'&&typeof _0x222d54[_0x61f3('0x1c')]===_0x61f3('0x1d');var _0xf55071=_0x2212c3[_0x61f3('0x1e')];var _0x1d6fde=_0x55c02e?0x0:_0x222d54[_0x61f3('0x1b')];var _0x45e9ac=_0x55c02e?_0x2212c3[_0x61f3('0x1e')]:_0x222d54[_0x61f3('0x1b')]+_0x222d54[_0x61f3('0x1c')];var _0xb61897;if(_0x45e9ac>=_0xf55071){_0x45e9ac=_0xf55071;_0xb61897=0xc8;}else{_0xb61897=0xce;}_0x1b74c4['status'](_0xb61897);return _0x1b74c4['set'](_0x61f3('0x1f'),_0x1d6fde+'-'+_0x45e9ac+'/'+_0xf55071)[_0x61f3('0x20')](_0x2212c3);}return null;};}function patchUpdates(_0x1b3d73){return function(_0x34ca5d){try{jsonpatch['apply'](_0x34ca5d,_0x1b3d73,!![]);}catch(_0x233514){return BPromise['reject'](_0x233514);}return _0x34ca5d[_0x61f3('0x21')]();};}function saveUpdates(_0x548765,_0x5cc484){return function(_0x3395e9){if(_0x3395e9){return _0x3395e9[_0x61f3('0x22')](_0x548765)[_0x61f3('0x23')](function(_0x114621){return _0x114621;});}return null;};}function removeEntity(_0x4cc0b4,_0xb96730){return function(_0x4b0e73){if(_0x4b0e73){return _0x4b0e73[_0x61f3('0x24')]()[_0x61f3('0x23')](function(){_0x4cc0b4[_0x61f3('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1563b5,_0x2a1e32){return function(_0x27b13e){if(!_0x27b13e){_0x1563b5['sendStatus'](0x194);}return _0x27b13e;};}function handleError(_0x327cf9,_0x420b58){_0x420b58=_0x420b58||0x1f4;return function(_0x3ae86f){logger[_0x61f3('0x25')](_0x3ae86f[_0x61f3('0x26')]);if(_0x3ae86f[_0x61f3('0x27')]){delete _0x3ae86f['name'];}_0x327cf9['status'](_0x420b58)[_0x61f3('0x28')](_0x3ae86f);};}exports[_0x61f3('0x29')]=function(_0x2aa56,_0x1cb919){var _0x1d066a={},_0x129a27={},_0x2ce55c={'count':0x0,'rows':[]};var _0x7f0c52=_['map'](db['AnalyticFieldReport']['rawAttributes'],function(_0x297a44){return{'name':_0x297a44['fieldName'],'type':_0x297a44['type'][_0x61f3('0x2a')]};});_0x129a27['model']=_[_0x61f3('0x2b')](_0x7f0c52,'name');_0x129a27[_0x61f3('0x2c')]=_[_0x61f3('0x2d')](_0x2aa56[_0x61f3('0x2c')]);_0x129a27[_0x61f3('0x2e')]=_[_0x61f3('0x2f')](_0x129a27[_0x61f3('0x30')],_0x129a27['query']);_0x1d066a[_0x61f3('0x31')]=_[_0x61f3('0x2f')](_0x129a27[_0x61f3('0x30')],qs['fields'](_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x32')]));_0x1d066a[_0x61f3('0x31')]=_0x1d066a[_0x61f3('0x31')][_0x61f3('0x33')]?_0x1d066a[_0x61f3('0x31')]:_0x129a27['model'];if(!_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x34')](_0x61f3('0x35'))){_0x1d066a[_0x61f3('0x1c')]=qs[_0x61f3('0x1c')](_0x2aa56[_0x61f3('0x2c')]['limit']);_0x1d066a['offset']=qs[_0x61f3('0x1b')](_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x1b')]);}_0x1d066a[_0x61f3('0x36')]=qs['sort'](_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x37')]);_0x1d066a[_0x61f3('0x38')]=qs[_0x61f3('0x2e')](_['pick'](_0x2aa56[_0x61f3('0x2c')],_0x129a27['filters']),_0x7f0c52);if(_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x39')]){_0x1d066a['where']=_[_0x61f3('0x3a')](_0x1d066a[_0x61f3('0x38')],{'$or':_[_0x61f3('0x2b')](_0x7f0c52,function(_0x34ea53){if(_0x34ea53[_0x61f3('0x3b')]!==_0x61f3('0x3c')){var _0x31afa1={};_0x31afa1[_0x34ea53[_0x61f3('0x27')]]={'$like':'%'+_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x39')]+'%'};return _0x31afa1;}})});}_0x1d066a=_[_0x61f3('0x3a')]({},_0x1d066a,_0x2aa56['options']);var _0x49c79a={'where':_0x1d066a[_0x61f3('0x38')]};return db[_0x61f3('0x3d')][_0x61f3('0x1e')](_0x49c79a)[_0x61f3('0x23')](function(_0xd8c178){_0x2ce55c[_0x61f3('0x1e')]=_0xd8c178;if(_0x2aa56[_0x61f3('0x2c')][_0x61f3('0x3e')]){_0x1d066a[_0x61f3('0x3f')]=[{'all':!![]}];}return db[_0x61f3('0x3d')]['findAll'](_0x1d066a);})[_0x61f3('0x23')](function(_0x1197e8){_0x2ce55c['rows']=_0x1197e8;return _0x2ce55c;})['then'](respondWithFilteredResult(_0x1cb919,_0x1d066a))[_0x61f3('0x40')](handleError(_0x1cb919,null));};exports[_0x61f3('0x41')]=function(_0x4aeb7d,_0x3a6856){var _0x4010fd={'raw':![],'where':{'id':_0x4aeb7d['params']['id']}},_0x1c09a5={};_0x1c09a5['model']=_[_0x61f3('0x2d')](db[_0x61f3('0x3d')][_0x61f3('0x42')]);_0x1c09a5[_0x61f3('0x2c')]=_[_0x61f3('0x2d')](_0x4aeb7d[_0x61f3('0x2c')]);_0x1c09a5[_0x61f3('0x2e')]=_[_0x61f3('0x2f')](_0x1c09a5[_0x61f3('0x30')],_0x1c09a5[_0x61f3('0x2c')]);_0x4010fd[_0x61f3('0x31')]=_[_0x61f3('0x2f')](_0x1c09a5[_0x61f3('0x30')],qs['fields'](_0x4aeb7d[_0x61f3('0x2c')][_0x61f3('0x32')]));_0x4010fd[_0x61f3('0x31')]=_0x4010fd[_0x61f3('0x31')][_0x61f3('0x33')]?_0x4010fd[_0x61f3('0x31')]:_0x1c09a5[_0x61f3('0x30')];if(_0x4aeb7d[_0x61f3('0x2c')]['includeAll']){_0x4010fd[_0x61f3('0x3f')]=[{'all':!![]}];}_0x4010fd=_[_0x61f3('0x3a')]({},_0x4010fd,_0x4aeb7d[_0x61f3('0x43')]);return db['AnalyticFieldReport'][_0x61f3('0x44')](_0x4010fd)['then'](handleEntityNotFound(_0x3a6856,null))[_0x61f3('0x23')](respondWithResult(_0x3a6856,null))[_0x61f3('0x40')](handleError(_0x3a6856,null));};exports[_0x61f3('0x45')]=function(_0x6488d7,_0xb41ab8){return db[_0x61f3('0x3d')][_0x61f3('0x45')](_0x6488d7['body'],{})[_0x61f3('0x23')](respondWithResult(_0xb41ab8,0xc9))['catch'](handleError(_0xb41ab8,null));};exports[_0x61f3('0x46')]=function(_0x27767e,_0x3c182d){return db[_0x61f3('0x3d')][_0x61f3('0x46')](_0x27767e['body'],{'raw':![],'individualHooks':!![]})[_0x61f3('0x23')](respondWithResult(_0x3c182d,0xc9))[_0x61f3('0x40')](handleError(_0x3c182d,null));};exports['update']=function(_0x55bce2,_0x1c4563){if(_0x55bce2['body']['id']){delete _0x55bce2[_0x61f3('0x47')]['id'];}return db['AnalyticFieldReport'][_0x61f3('0x44')]({'where':{'id':_0x55bce2[_0x61f3('0x48')]['id']}})[_0x61f3('0x23')](handleEntityNotFound(_0x1c4563,null))['then'](saveUpdates(_0x55bce2[_0x61f3('0x47')],null))[_0x61f3('0x23')](respondWithResult(_0x1c4563,null))[_0x61f3('0x40')](handleError(_0x1c4563,null));};exports['destroy']=function(_0x593a7b,_0x4d1576){return db[_0x61f3('0x3d')][_0x61f3('0x44')]({'where':{'id':_0x593a7b[_0x61f3('0x48')]['id']}})[_0x61f3('0x23')](handleEntityNotFound(_0x4d1576,null))[_0x61f3('0x23')](removeEntity(_0x4d1576,null))[_0x61f3('0x40')](handleError(_0x4d1576,null));};exports[_0x61f3('0x49')]=function(_0x1ac3a5,_0x12e2d1){return db[_0x61f3('0x3d')]['destroy']({'where':{'id':_0x1ac3a5[_0x61f3('0x2c')][_0x61f3('0x4a')]||[]},'raw':![],'individualHooks':!![]})[_0x61f3('0x23')](respondWithResult(_0x12e2d1,0xcc))[_0x61f3('0x40')](handleError(_0x12e2d1,null));};exports[_0x61f3('0x4b')]=function(_0x2e54df,_0x54fd70,_0x52708e){return db['AnalyticCustomReport'][_0x61f3('0x4c')]({'where':{'id':_0x2e54df[_0x61f3('0x48')]['id']}})[_0x61f3('0x23')](handleEntityNotFound(_0x54fd70,null))[_0x61f3('0x23')](function(_0x5e7c1c){if(_0x5e7c1c){return db[_0x61f3('0x4d')][_0x61f3('0x4e')](function(_0x1890e4){return db[_0x61f3('0x3d')][_0x61f3('0x24')]({'where':{'CustomReportId':_0x2e54df[_0x61f3('0x48')]['id']},'transaction':_0x1890e4})[_0x61f3('0x23')](function(_0x2c970f){var _0x270815=_[_0x61f3('0x2b')](_0x2e54df[_0x61f3('0x47')],function(_0x2bf46d){delete _0x2bf46d['id'];_0x2bf46d['CustomReportId']=_0x2e54df[_0x61f3('0x48')]['id'];return _0x2bf46d;});return db[_0x61f3('0x3d')][_0x61f3('0x46')](_0x270815,{'transaction':_0x1890e4});});})[_0x61f3('0x23')](function(){return db[_0x61f3('0x3d')][_0x61f3('0x4f')]({'where':{'CustomReportId':_0x2e54df[_0x61f3('0x48')]['id']}});});}})[_0x61f3('0x23')](respondWithResult(_0x54fd70,null))[_0x61f3('0x40')](handleError(_0x54fd70,null));};