72622881be89cc2df8ca58e5ce9d8f769750e088
[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 _0x626f=['destroy','then','error','stack','name','send','index','map','AnalyticFieldReport','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','limit','sort','pick','filters','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','options','find','create','body','bulkCreate','ids','addFields','AnalyticCustomReport','sequelize','CustomReportId','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','set','Content-Range','apply','reject','save','update'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x626f,0x7f));var _0xf626=function(_0x294d78,_0x3fb7b6){_0x294d78=_0x294d78-0x0;var _0x179271=_0x626f[_0x294d78];return _0x179271;};'use strict';var pdf=require(_0xf626('0x0'));var emlformat=require(_0xf626('0x1'));var rimraf=require(_0xf626('0x2'));var zipdir=require(_0xf626('0x3'));var jsonpatch=require(_0xf626('0x4'));var rp=require(_0xf626('0x5'));var moment=require('moment');var BPromise=require(_0xf626('0x6'));var Mustache=require(_0xf626('0x7'));var util=require(_0xf626('0x8'));var path=require('path');var sox=require(_0xf626('0x9'));var csv=require(_0xf626('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xf626('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xf626('0xc'));var deskjs=require(_0xf626('0xd'));var toCsv=require('to-csv');var querystring=require(_0xf626('0xe'));var Papa=require(_0xf626('0xf'));var Redis=require(_0xf626('0x10'));var authService=require(_0xf626('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xf626('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf626('0x13'))(_0xf626('0x14'));var utils=require('../../config/utils');var config=require(_0xf626('0x15'));var licenseUtil=require(_0xf626('0x16'));var db=require(_0xf626('0x17'))['db'];function respondWithStatusCode(_0x1fb7b1,_0x104dba){_0x104dba=_0x104dba||0xcc;return function(_0x44b85f){if(_0x44b85f){return _0x1fb7b1[_0xf626('0x18')](_0x104dba);}return _0x1fb7b1[_0xf626('0x19')](_0x104dba)[_0xf626('0x1a')]();};}function respondWithResult(_0x3e4ac1,_0x2d4bd9){_0x2d4bd9=_0x2d4bd9||0xc8;return function(_0x303084){if(_0x303084){return _0x3e4ac1[_0xf626('0x19')](_0x2d4bd9)['json'](_0x303084);}};}function respondWithFilteredResult(_0x56638,_0x37f8c1){return function(_0x3134d5){if(_0x3134d5){var _0x439308=_0x3134d5[_0xf626('0x1b')],_0x2a942b=_0x37f8c1[_0xf626('0x1c')],_0x3e6280=_0x37f8c1['offset']+_0x37f8c1['limit'],_0x494b61;if(_0x3e6280>=_0x439308){_0x3e6280=_0x439308;_0x494b61=0xc8;}else{_0x494b61=0xce;}_0x56638[_0xf626('0x19')](_0x494b61);return _0x56638[_0xf626('0x1d')](_0xf626('0x1e'),_0x2a942b+'-'+_0x3e6280+'/'+_0x439308)['json'](_0x3134d5);}return null;};}function patchUpdates(_0x1543da){return function(_0x1680b3){try{jsonpatch[_0xf626('0x1f')](_0x1680b3,_0x1543da,!![]);}catch(_0x5224c2){return BPromise[_0xf626('0x20')](_0x5224c2);}return _0x1680b3[_0xf626('0x21')]();};}function saveUpdates(_0xa344a5,_0x822c71){return function(_0xabfbef){if(_0xabfbef){return _0xabfbef[_0xf626('0x22')](_0xa344a5)['then'](function(_0x5be5ad){return _0x5be5ad;});}return null;};}function removeEntity(_0x29ab23,_0xad5ae0){return function(_0x32b67e){if(_0x32b67e){return _0x32b67e[_0xf626('0x23')]()[_0xf626('0x24')](function(){_0x29ab23[_0xf626('0x19')](0xcc)[_0xf626('0x1a')]();});}};}function handleEntityNotFound(_0x118574,_0x1112e5){return function(_0x8c8ba6){if(!_0x8c8ba6){_0x118574[_0xf626('0x18')](0x194);}return _0x8c8ba6;};}function handleError(_0x52e830,_0x3510be){_0x3510be=_0x3510be||0x1f4;return function(_0x5de3d1){logger[_0xf626('0x25')](_0x5de3d1[_0xf626('0x26')]);if(_0x5de3d1['name']){delete _0x5de3d1[_0xf626('0x27')];}_0x52e830[_0xf626('0x19')](_0x3510be)[_0xf626('0x28')](_0x5de3d1);};}exports[_0xf626('0x29')]=function(_0x4a1d02,_0x324cf7){var _0x423bf4={},_0x4f04f3={},_0x548c24={'count':0x0,'rows':[]};var _0x2682a3=_[_0xf626('0x2a')](db[_0xf626('0x2b')][_0xf626('0x2c')],function(_0x2f13c8){return{'name':_0x2f13c8[_0xf626('0x2d')],'type':_0x2f13c8[_0xf626('0x2e')][_0xf626('0x2f')]};});_0x4f04f3[_0xf626('0x30')]=_[_0xf626('0x2a')](_0x2682a3,'name');_0x4f04f3[_0xf626('0x31')]=_[_0xf626('0x32')](_0x4a1d02[_0xf626('0x31')]);_0x4f04f3['filters']=_[_0xf626('0x33')](_0x4f04f3[_0xf626('0x30')],_0x4f04f3[_0xf626('0x31')]);_0x423bf4[_0xf626('0x34')]=_[_0xf626('0x33')](_0x4f04f3['model'],qs['fields'](_0x4a1d02[_0xf626('0x31')][_0xf626('0x35')]));_0x423bf4[_0xf626('0x34')]=_0x423bf4[_0xf626('0x34')][_0xf626('0x36')]?_0x423bf4[_0xf626('0x34')]:_0x4f04f3[_0xf626('0x30')];if(!_0x4a1d02['query'][_0xf626('0x37')]('nolimit')){_0x423bf4['limit']=qs[_0xf626('0x38')](_0x4a1d02[_0xf626('0x31')][_0xf626('0x38')]);_0x423bf4[_0xf626('0x1c')]=qs[_0xf626('0x1c')](_0x4a1d02[_0xf626('0x31')][_0xf626('0x1c')]);}_0x423bf4['order']=qs['sort'](_0x4a1d02[_0xf626('0x31')][_0xf626('0x39')]);_0x423bf4['where']=qs['filters'](_[_0xf626('0x3a')](_0x4a1d02[_0xf626('0x31')],_0x4f04f3[_0xf626('0x3b')]),_0x2682a3);if(_0x4a1d02[_0xf626('0x31')][_0xf626('0x3c')]){_0x423bf4[_0xf626('0x3d')]=_[_0xf626('0x3e')](_0x423bf4[_0xf626('0x3d')],{'$or':_[_0xf626('0x2a')](_0x2682a3,function(_0x536bf5){if(_0x536bf5[_0xf626('0x2e')]!==_0xf626('0x3f')){var _0x15e3bc={};_0x15e3bc[_0x536bf5[_0xf626('0x27')]]={'$like':'%'+_0x4a1d02['query'][_0xf626('0x3c')]+'%'};return _0x15e3bc;}})});}_0x423bf4=_[_0xf626('0x3e')]({},_0x423bf4,_0x4a1d02['options']);var _0xc80fcb={'where':_0x423bf4[_0xf626('0x3d')]};return db[_0xf626('0x2b')][_0xf626('0x1b')](_0xc80fcb)[_0xf626('0x24')](function(_0xec5383){_0x548c24[_0xf626('0x1b')]=_0xec5383;if(_0x4a1d02[_0xf626('0x31')][_0xf626('0x40')]){_0x423bf4[_0xf626('0x41')]=[{'all':!![]}];}return db[_0xf626('0x2b')][_0xf626('0x42')](_0x423bf4);})[_0xf626('0x24')](function(_0x348bc4){_0x548c24[_0xf626('0x43')]=_0x348bc4;return _0x548c24;})[_0xf626('0x24')](respondWithFilteredResult(_0x324cf7,_0x423bf4))[_0xf626('0x44')](handleError(_0x324cf7,null));};exports[_0xf626('0x45')]=function(_0x42e1ff,_0x553f89){var _0x4b209a={'raw':![],'where':{'id':_0x42e1ff[_0xf626('0x46')]['id']}},_0x55c520={};_0x55c520['model']=_['keys'](db[_0xf626('0x2b')][_0xf626('0x2c')]);_0x55c520['query']=_[_0xf626('0x32')](_0x42e1ff['query']);_0x55c520['filters']=_['intersection'](_0x55c520['model'],_0x55c520['query']);_0x4b209a[_0xf626('0x34')]=_[_0xf626('0x33')](_0x55c520[_0xf626('0x30')],qs[_0xf626('0x35')](_0x42e1ff[_0xf626('0x31')][_0xf626('0x35')]));_0x4b209a['attributes']=_0x4b209a[_0xf626('0x34')]['length']?_0x4b209a[_0xf626('0x34')]:_0x55c520[_0xf626('0x30')];if(_0x42e1ff[_0xf626('0x31')][_0xf626('0x40')]){_0x4b209a[_0xf626('0x41')]=[{'all':!![]}];}_0x4b209a=_['merge']({},_0x4b209a,_0x42e1ff[_0xf626('0x47')]);return db['AnalyticFieldReport'][_0xf626('0x48')](_0x4b209a)['then'](handleEntityNotFound(_0x553f89,null))['then'](respondWithResult(_0x553f89,null))[_0xf626('0x44')](handleError(_0x553f89,null));};exports[_0xf626('0x49')]=function(_0x35c38c,_0x276e1a){return db['AnalyticFieldReport'][_0xf626('0x49')](_0x35c38c[_0xf626('0x4a')],{})['then'](respondWithResult(_0x276e1a,0xc9))['catch'](handleError(_0x276e1a,null));};exports[_0xf626('0x4b')]=function(_0x810d18,_0x399915){return db['AnalyticFieldReport']['bulkCreate'](_0x810d18[_0xf626('0x4a')],{'raw':![],'individualHooks':!![]})[_0xf626('0x24')](respondWithResult(_0x399915,0xc9))[_0xf626('0x44')](handleError(_0x399915,null));};exports[_0xf626('0x22')]=function(_0x7b1aac,_0x574b80){if(_0x7b1aac[_0xf626('0x4a')]['id']){delete _0x7b1aac[_0xf626('0x4a')]['id'];}return db['AnalyticFieldReport']['find']({'where':{'id':_0x7b1aac[_0xf626('0x46')]['id']}})[_0xf626('0x24')](handleEntityNotFound(_0x574b80,null))[_0xf626('0x24')](saveUpdates(_0x7b1aac[_0xf626('0x4a')],null))[_0xf626('0x24')](respondWithResult(_0x574b80,null))[_0xf626('0x44')](handleError(_0x574b80,null));};exports[_0xf626('0x23')]=function(_0x340c39,_0x62c4c5){return db[_0xf626('0x2b')]['find']({'where':{'id':_0x340c39['params']['id']}})['then'](handleEntityNotFound(_0x62c4c5,null))['then'](removeEntity(_0x62c4c5,null))[_0xf626('0x44')](handleError(_0x62c4c5,null));};exports['bulkDestroy']=function(_0x4a3acc,_0x2f85f2){return db['AnalyticFieldReport']['destroy']({'where':{'id':_0x4a3acc[_0xf626('0x31')][_0xf626('0x4c')]||[]},'raw':![],'individualHooks':!![]})[_0xf626('0x24')](respondWithResult(_0x2f85f2,0xcc))[_0xf626('0x44')](handleError(_0x2f85f2,null));};exports[_0xf626('0x4d')]=function(_0xa73414,_0x159c1b,_0xb338c9){return db[_0xf626('0x4e')]['findOne']({'where':{'id':_0xa73414[_0xf626('0x46')]['id']}})['then'](handleEntityNotFound(_0x159c1b,null))[_0xf626('0x24')](function(_0x4e207a){if(_0x4e207a){return db[_0xf626('0x4f')]['transaction'](function(_0x1eb98c){return db[_0xf626('0x2b')][_0xf626('0x23')]({'where':{'CustomReportId':_0xa73414[_0xf626('0x46')]['id']},'transaction':_0x1eb98c})[_0xf626('0x24')](function(_0x44e9e3){var _0x2b6847=_['map'](_0xa73414[_0xf626('0x4a')],function(_0x470e89){delete _0x470e89['id'];_0x470e89[_0xf626('0x50')]=_0xa73414[_0xf626('0x46')]['id'];return _0x470e89;});return db[_0xf626('0x2b')][_0xf626('0x4b')](_0x2b6847,{'transaction':_0x1eb98c});});})[_0xf626('0x24')](function(){return db[_0xf626('0x2b')][_0xf626('0x42')]({'where':{'CustomReportId':_0xa73414[_0xf626('0x46')]['id']}});});}})['then'](respondWithResult(_0x159c1b,null))[_0xf626('0x44')](handleError(_0x159c1b,null));};