d73178bc86d910eac8adb4475d9e78596225bb49
[motion2.git] / server / api / memberReport / memberReport.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 _0x20f1=['save','update','destroy','then','error','stack','name','send','index','map','MemberReport','rawAttributes','fieldName','type','key','model','query','attributes','intersection','fields','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','catch','params','length','include','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','crypto','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','reject'];(function(_0xf68fcc,_0x131635){var _0x9633dc=function(_0x3ca814){while(--_0x3ca814){_0xf68fcc['push'](_0xf68fcc['shift']());}};_0x9633dc(++_0x131635);}(_0x20f1,0xb6));var _0x120f=function(_0x40f04d,_0x26bfb3){_0x40f04d=_0x40f04d-0x0;var _0x4063bc=_0x20f1[_0x40f04d];return _0x4063bc;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x120f('0x0'));var rimraf=require(_0x120f('0x1'));var zipdir=require(_0x120f('0x2'));var jsonpatch=require(_0x120f('0x3'));var rp=require(_0x120f('0x4'));var moment=require(_0x120f('0x5'));var BPromise=require(_0x120f('0x6'));var Mustache=require(_0x120f('0x7'));var util=require(_0x120f('0x8'));var path=require(_0x120f('0x9'));var sox=require(_0x120f('0xa'));var csv=require('to-csv');var ejs=require(_0x120f('0xb'));var fs=require('fs');var _=require(_0x120f('0xc'));var squel=require('squel');var crypto=require(_0x120f('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x120f('0xe'));var querystring=require(_0x120f('0xf'));var Papa=require(_0x120f('0x10'));var Redis=require(_0x120f('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x120f('0x12'));var as=require(_0x120f('0x13'));var hardwareService=require(_0x120f('0x14'));var logger=require(_0x120f('0x15'))('api');var utils=require('../../config/utils');var config=require(_0x120f('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x593bcf,_0x5cf896){_0x5cf896=_0x5cf896||0xcc;return function(_0x277118){if(_0x277118){return _0x593bcf[_0x120f('0x17')](_0x5cf896);}return _0x593bcf[_0x120f('0x18')](_0x5cf896)[_0x120f('0x19')]();};}function respondWithResult(_0x25c2c3,_0x33609e){_0x33609e=_0x33609e||0xc8;return function(_0x5654b2){if(_0x5654b2){return _0x25c2c3['status'](_0x33609e)['json'](_0x5654b2);}};}function respondWithFilteredResult(_0x3c52f8,_0x3318a7){return function(_0x5e9c21){if(_0x5e9c21){var _0x183fbc=_0x5e9c21[_0x120f('0x1a')],_0x4b70a2=_0x3318a7['offset'],_0x4c1f55=_0x3318a7[_0x120f('0x1b')]+_0x3318a7[_0x120f('0x1c')],_0xa00fea;if(_0x4c1f55>=_0x183fbc){_0x4c1f55=_0x183fbc;_0xa00fea=0xc8;}else{_0xa00fea=0xce;}_0x3c52f8[_0x120f('0x18')](_0xa00fea);return _0x3c52f8[_0x120f('0x1d')](_0x120f('0x1e'),_0x4b70a2+'-'+_0x4c1f55+'/'+_0x183fbc)[_0x120f('0x1f')](_0x5e9c21);}return null;};}function patchUpdates(_0x29a374){return function(_0x31a2e8){try{jsonpatch[_0x120f('0x20')](_0x31a2e8,_0x29a374,!![]);}catch(_0x421f5d){return BPromise[_0x120f('0x21')](_0x421f5d);}return _0x31a2e8[_0x120f('0x22')]();};}function saveUpdates(_0x37c02d,_0x467a5a){return function(_0x2b9e46){if(_0x2b9e46){return _0x2b9e46[_0x120f('0x23')](_0x37c02d)['then'](function(_0x51c966){return _0x51c966;});}return null;};}function removeEntity(_0x4c9ba8,_0x4228d2){return function(_0x2f3fc7){if(_0x2f3fc7){return _0x2f3fc7[_0x120f('0x24')]()[_0x120f('0x25')](function(){_0x4c9ba8[_0x120f('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0xba1999,_0x157f87){return function(_0x4e9d1d){if(!_0x4e9d1d){_0xba1999[_0x120f('0x17')](0x194);}return _0x4e9d1d;};}function handleError(_0x43e57d,_0x5cc14c){_0x5cc14c=_0x5cc14c||0x1f4;return function(_0x273b89){logger[_0x120f('0x26')](_0x273b89[_0x120f('0x27')]);if(_0x273b89[_0x120f('0x28')]){delete _0x273b89[_0x120f('0x28')];}_0x43e57d['status'](_0x5cc14c)[_0x120f('0x29')](_0x273b89);};}exports[_0x120f('0x2a')]=function(_0x34d1c4,_0x215e5a){var _0x679b7d={},_0x45e7cd={},_0xfe62e2={'count':0x0,'rows':[]};var _0xd213c4=_[_0x120f('0x2b')](db[_0x120f('0x2c')][_0x120f('0x2d')],function(_0x1a4127){return{'name':_0x1a4127[_0x120f('0x2e')],'type':_0x1a4127[_0x120f('0x2f')][_0x120f('0x30')]};});_0x45e7cd[_0x120f('0x31')]=_[_0x120f('0x2b')](_0xd213c4,_0x120f('0x28'));_0x45e7cd[_0x120f('0x32')]=_['keys'](_0x34d1c4[_0x120f('0x32')]);_0x45e7cd['filters']=_['intersection'](_0x45e7cd[_0x120f('0x31')],_0x45e7cd[_0x120f('0x32')]);_0x679b7d[_0x120f('0x33')]=_[_0x120f('0x34')](_0x45e7cd[_0x120f('0x31')],qs['fields'](_0x34d1c4[_0x120f('0x32')][_0x120f('0x35')]));_0x679b7d[_0x120f('0x33')]=_0x679b7d[_0x120f('0x33')]['length']?_0x679b7d['attributes']:_0x45e7cd[_0x120f('0x31')];if(!_0x34d1c4[_0x120f('0x32')]['hasOwnProperty'](_0x120f('0x36'))){_0x679b7d[_0x120f('0x1c')]=qs[_0x120f('0x1c')](_0x34d1c4[_0x120f('0x32')][_0x120f('0x1c')]);_0x679b7d[_0x120f('0x1b')]=qs[_0x120f('0x1b')](_0x34d1c4[_0x120f('0x32')][_0x120f('0x1b')]);}_0x679b7d[_0x120f('0x37')]=qs[_0x120f('0x38')](_0x34d1c4['query'][_0x120f('0x38')]);_0x679b7d[_0x120f('0x39')]=qs[_0x120f('0x3a')](_[_0x120f('0x3b')](_0x34d1c4[_0x120f('0x32')],_0x45e7cd[_0x120f('0x3a')]),_0xd213c4);if(_0x34d1c4[_0x120f('0x32')][_0x120f('0x3c')]){_0x679b7d[_0x120f('0x39')]=_[_0x120f('0x3d')](_0x679b7d[_0x120f('0x39')],{'$or':_[_0x120f('0x2b')](_0xd213c4,function(_0xc59e8f){if(_0xc59e8f[_0x120f('0x2f')]!==_0x120f('0x3e')){var _0x214729={};_0x214729[_0xc59e8f['name']]={'$like':'%'+_0x34d1c4['query']['filter']+'%'};return _0x214729;}})});}_0x679b7d=_['merge']({},_0x679b7d,_0x34d1c4['options']);var _0x4e4d2d={'where':_0x679b7d[_0x120f('0x39')]};return db[_0x120f('0x2c')][_0x120f('0x1a')](_0x4e4d2d)[_0x120f('0x25')](function(_0xf3e7e8){_0xfe62e2[_0x120f('0x1a')]=_0xf3e7e8;if(_0x34d1c4['query'][_0x120f('0x3f')]){_0x679b7d['include']=[{'all':!![]}];}return db[_0x120f('0x2c')]['findAll'](_0x679b7d);})[_0x120f('0x25')](function(_0x6cb0fa){_0xfe62e2['rows']=_0x6cb0fa;return _0xfe62e2;})[_0x120f('0x25')](respondWithFilteredResult(_0x215e5a,_0x679b7d))[_0x120f('0x40')](handleError(_0x215e5a,null));};exports['show']=function(_0xc471aa,_0x32e807){var _0x5da4ee={'raw':!![],'where':{'id':_0xc471aa[_0x120f('0x41')]['id']}},_0x5aed01={};_0x5aed01['model']=_['keys'](db[_0x120f('0x2c')]['rawAttributes']);_0x5aed01[_0x120f('0x32')]=_['keys'](_0xc471aa[_0x120f('0x32')]);_0x5aed01['filters']=_[_0x120f('0x34')](_0x5aed01[_0x120f('0x31')],_0x5aed01['query']);_0x5da4ee[_0x120f('0x33')]=_[_0x120f('0x34')](_0x5aed01['model'],qs[_0x120f('0x35')](_0xc471aa[_0x120f('0x32')][_0x120f('0x35')]));_0x5da4ee['attributes']=_0x5da4ee['attributes'][_0x120f('0x42')]?_0x5da4ee[_0x120f('0x33')]:_0x5aed01[_0x120f('0x31')];if(_0xc471aa[_0x120f('0x32')][_0x120f('0x3f')]){_0x5da4ee[_0x120f('0x43')]=[{'all':!![]}];}_0x5da4ee=_[_0x120f('0x3d')]({},_0x5da4ee,_0xc471aa['options']);return db['MemberReport'][_0x120f('0x44')](_0x5da4ee)[_0x120f('0x25')](handleEntityNotFound(_0x32e807,null))[_0x120f('0x25')](respondWithResult(_0x32e807,null))[_0x120f('0x40')](handleError(_0x32e807,null));};exports[_0x120f('0x45')]=function(_0x13c63e,_0x57e4fb){return db[_0x120f('0x2c')][_0x120f('0x45')](_0x13c63e[_0x120f('0x46')],{})[_0x120f('0x25')](respondWithResult(_0x57e4fb,0xc9))[_0x120f('0x40')](handleError(_0x57e4fb,null));};exports[_0x120f('0x23')]=function(_0x5343f8,_0x58afe5){if(_0x5343f8[_0x120f('0x46')]['id']){delete _0x5343f8[_0x120f('0x46')]['id'];}return db['MemberReport'][_0x120f('0x44')]({'where':{'id':_0x5343f8[_0x120f('0x41')]['id']}})[_0x120f('0x25')](handleEntityNotFound(_0x58afe5,null))[_0x120f('0x25')](saveUpdates(_0x5343f8[_0x120f('0x46')],null))[_0x120f('0x25')](respondWithResult(_0x58afe5,null))[_0x120f('0x40')](handleError(_0x58afe5,null));};exports[_0x120f('0x24')]=function(_0x4eb117,_0x196061){return db[_0x120f('0x2c')][_0x120f('0x44')]({'where':{'id':_0x4eb117['params']['id']}})['then'](handleEntityNotFound(_0x196061,null))['then'](removeEntity(_0x196061,null))[_0x120f('0x40')](handleError(_0x196061,null));};exports[_0x120f('0x47')]=function(_0xcd3972,_0x42b0da){return db[_0x120f('0x2c')][_0x120f('0x47')]()[_0x120f('0x25')](respondWithResult(_0x42b0da,null))[_0x120f('0x40')](handleError(_0x42b0da,null));};