80de56b1612fcc1bcd37ceef5ccae976fc51ff7e
[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 _0x770f=['create','body','find','describe','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','end','status','json','count','offset','limit','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','index','map','MemberReport','fieldName','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filter','merge','type','VIRTUAL','options','where','includeAll','findAll','params','rawAttributes','catch'];(function(_0x2beeb6,_0x1b68c3){var _0x1c5e2d=function(_0x344aa1){while(--_0x344aa1){_0x2beeb6['push'](_0x2beeb6['shift']());}};_0x1c5e2d(++_0x1b68c3);}(_0x770f,0xdc));var _0xf770=function(_0x1ac5e1,_0x43a483){_0x1ac5e1=_0x1ac5e1-0x0;var _0x3ae80e=_0x770f[_0x1ac5e1];return _0x3ae80e;};'use strict';var pdf=require(_0xf770('0x0'));var emlformat=require(_0xf770('0x1'));var rimraf=require(_0xf770('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf770('0x3'));var rp=require(_0xf770('0x4'));var moment=require(_0xf770('0x5'));var BPromise=require(_0xf770('0x6'));var Mustache=require(_0xf770('0x7'));var util=require(_0xf770('0x8'));var path=require(_0xf770('0x9'));var sox=require(_0xf770('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf770('0xb'));var squel=require(_0xf770('0xc'));var crypto=require(_0xf770('0xd'));var jsforce=require(_0xf770('0xe'));var deskjs=require(_0xf770('0xf'));var toCsv=require('to-csv');var querystring=require(_0xf770('0x10'));var Papa=require('papaparse');var Redis=require(_0xf770('0x11'));var authService=require(_0xf770('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf770('0x13'));var logger=require(_0xf770('0x14'))('api');var utils=require(_0xf770('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf770('0x16'));var db=require(_0xf770('0x17'))['db'];function respondWithStatusCode(_0x1a1d70,_0xda2aab){_0xda2aab=_0xda2aab||0xcc;return function(_0x184ab0){if(_0x184ab0){return _0x1a1d70['sendStatus'](_0xda2aab);}return _0x1a1d70['status'](_0xda2aab)[_0xf770('0x18')]();};}function respondWithResult(_0x5ddf41,_0x208111){_0x208111=_0x208111||0xc8;return function(_0x3efc17){if(_0x3efc17){return _0x5ddf41[_0xf770('0x19')](_0x208111)[_0xf770('0x1a')](_0x3efc17);}};}function respondWithFilteredResult(_0x587d93,_0x2ce4b2){return function(_0x136e09){if(_0x136e09){var _0x227063=_0x136e09[_0xf770('0x1b')],_0x12182a=_0x2ce4b2[_0xf770('0x1c')],_0x569c23=_0x2ce4b2['offset']+_0x2ce4b2[_0xf770('0x1d')],_0x2c9298;if(_0x569c23>=_0x227063){_0x569c23=_0x227063;_0x2c9298=0xc8;}else{_0x2c9298=0xce;}_0x587d93[_0xf770('0x19')](_0x2c9298);return _0x587d93['set']('Content-Range',_0x12182a+'-'+_0x569c23+'/'+_0x227063)[_0xf770('0x1a')](_0x136e09);}return null;};}function patchUpdates(_0x436137){return function(_0x4ede0e){try{jsonpatch[_0xf770('0x1e')](_0x4ede0e,_0x436137,!![]);}catch(_0x2bdf51){return BPromise[_0xf770('0x1f')](_0x2bdf51);}return _0x4ede0e[_0xf770('0x20')]();};}function saveUpdates(_0x37e359,_0x3871fa){return function(_0x2b1d24){if(_0x2b1d24){return _0x2b1d24[_0xf770('0x21')](_0x37e359)[_0xf770('0x22')](function(_0x52e178){return _0x52e178;});}return null;};}function removeEntity(_0x3cc041,_0x4a7b39){return function(_0x172f0a){if(_0x172f0a){return _0x172f0a[_0xf770('0x23')]()['then'](function(){_0x3cc041[_0xf770('0x19')](0xcc)[_0xf770('0x18')]();});}};}function handleEntityNotFound(_0x1ca0b3,_0x4c3ea0){return function(_0x5a2535){if(!_0x5a2535){_0x1ca0b3[_0xf770('0x24')](0x194);}return _0x5a2535;};}function handleError(_0x76b42a,_0xdeb57c){_0xdeb57c=_0xdeb57c||0x1f4;return function(_0x4d9c7a){logger[_0xf770('0x25')](_0x4d9c7a[_0xf770('0x26')]);if(_0x4d9c7a[_0xf770('0x27')]){delete _0x4d9c7a[_0xf770('0x27')];}_0x76b42a[_0xf770('0x19')](_0xdeb57c)['send'](_0x4d9c7a);};}exports[_0xf770('0x28')]=function(_0x16624c,_0x2cbf5c){var _0x2f96ab={},_0x457157={},_0x5a83f3={'count':0x0,'rows':[]};var _0x1e4e9e=_[_0xf770('0x29')](db[_0xf770('0x2a')]['rawAttributes'],function(_0xcfce0c){return{'name':_0xcfce0c[_0xf770('0x2b')],'type':_0xcfce0c['type'][_0xf770('0x2c')]};});_0x457157['model']=_['map'](_0x1e4e9e,_0xf770('0x27'));_0x457157[_0xf770('0x2d')]=_[_0xf770('0x2e')](_0x16624c[_0xf770('0x2d')]);_0x457157[_0xf770('0x2f')]=_[_0xf770('0x30')](_0x457157[_0xf770('0x31')],_0x457157[_0xf770('0x2d')]);_0x2f96ab[_0xf770('0x32')]=_['intersection'](_0x457157[_0xf770('0x31')],qs[_0xf770('0x33')](_0x16624c[_0xf770('0x2d')]['fields']));_0x2f96ab[_0xf770('0x32')]=_0x2f96ab['attributes'][_0xf770('0x34')]?_0x2f96ab[_0xf770('0x32')]:_0x457157[_0xf770('0x31')];if(!_0x16624c[_0xf770('0x2d')][_0xf770('0x35')](_0xf770('0x36'))){_0x2f96ab[_0xf770('0x1d')]=qs[_0xf770('0x1d')](_0x16624c['query'][_0xf770('0x1d')]);_0x2f96ab[_0xf770('0x1c')]=qs[_0xf770('0x1c')](_0x16624c[_0xf770('0x2d')][_0xf770('0x1c')]);}_0x2f96ab[_0xf770('0x37')]=qs[_0xf770('0x38')](_0x16624c[_0xf770('0x2d')]['sort']);_0x2f96ab['where']=qs[_0xf770('0x2f')](_['pick'](_0x16624c[_0xf770('0x2d')],_0x457157['filters']),_0x1e4e9e);if(_0x16624c[_0xf770('0x2d')][_0xf770('0x39')]){_0x2f96ab['where']=_[_0xf770('0x3a')](_0x2f96ab['where'],{'$or':_[_0xf770('0x29')](_0x1e4e9e,function(_0xc8d870){if(_0xc8d870[_0xf770('0x3b')]!==_0xf770('0x3c')){var _0x491c26={};_0x491c26[_0xc8d870[_0xf770('0x27')]]={'$like':'%'+_0x16624c[_0xf770('0x2d')][_0xf770('0x39')]+'%'};return _0x491c26;}})});}_0x2f96ab=_[_0xf770('0x3a')]({},_0x2f96ab,_0x16624c[_0xf770('0x3d')]);var _0x2bc59f={'where':_0x2f96ab[_0xf770('0x3e')]};return db['MemberReport'][_0xf770('0x1b')](_0x2bc59f)['then'](function(_0x4ed6f5){_0x5a83f3[_0xf770('0x1b')]=_0x4ed6f5;if(_0x16624c['query'][_0xf770('0x3f')]){_0x2f96ab['include']=[{'all':!![]}];}return db[_0xf770('0x2a')][_0xf770('0x40')](_0x2f96ab);})[_0xf770('0x22')](function(_0x13bca9){_0x5a83f3['rows']=_0x13bca9;return _0x5a83f3;})[_0xf770('0x22')](respondWithFilteredResult(_0x2cbf5c,_0x2f96ab))['catch'](handleError(_0x2cbf5c,null));};exports['show']=function(_0x1240d9,_0x3a56cf){var _0x58934f={'raw':!![],'where':{'id':_0x1240d9[_0xf770('0x41')]['id']}},_0x5bcbd9={};_0x5bcbd9[_0xf770('0x31')]=_[_0xf770('0x2e')](db[_0xf770('0x2a')][_0xf770('0x42')]);_0x5bcbd9[_0xf770('0x2d')]=_[_0xf770('0x2e')](_0x1240d9[_0xf770('0x2d')]);_0x5bcbd9['filters']=_['intersection'](_0x5bcbd9[_0xf770('0x31')],_0x5bcbd9[_0xf770('0x2d')]);_0x58934f[_0xf770('0x32')]=_['intersection'](_0x5bcbd9[_0xf770('0x31')],qs[_0xf770('0x33')](_0x1240d9[_0xf770('0x2d')][_0xf770('0x33')]));_0x58934f[_0xf770('0x32')]=_0x58934f[_0xf770('0x32')][_0xf770('0x34')]?_0x58934f[_0xf770('0x32')]:_0x5bcbd9[_0xf770('0x31')];if(_0x1240d9[_0xf770('0x2d')]['includeAll']){_0x58934f['include']=[{'all':!![]}];}_0x58934f=_['merge']({},_0x58934f,_0x1240d9[_0xf770('0x3d')]);return db[_0xf770('0x2a')]['find'](_0x58934f)['then'](handleEntityNotFound(_0x3a56cf,null))['then'](respondWithResult(_0x3a56cf,null))[_0xf770('0x43')](handleError(_0x3a56cf,null));};exports['create']=function(_0x2c68af,_0x3357c8){return db[_0xf770('0x2a')][_0xf770('0x44')](_0x2c68af['body'],{})[_0xf770('0x22')](respondWithResult(_0x3357c8,0xc9))[_0xf770('0x43')](handleError(_0x3357c8,null));};exports[_0xf770('0x21')]=function(_0x28ac8f,_0x256262){if(_0x28ac8f[_0xf770('0x45')]['id']){delete _0x28ac8f['body']['id'];}return db[_0xf770('0x2a')][_0xf770('0x46')]({'where':{'id':_0x28ac8f['params']['id']}})[_0xf770('0x22')](handleEntityNotFound(_0x256262,null))['then'](saveUpdates(_0x28ac8f['body'],null))[_0xf770('0x22')](respondWithResult(_0x256262,null))[_0xf770('0x43')](handleError(_0x256262,null));};exports[_0xf770('0x23')]=function(_0x2bb91b,_0x12a724){return db['MemberReport'][_0xf770('0x46')]({'where':{'id':_0x2bb91b[_0xf770('0x41')]['id']}})['then'](handleEntityNotFound(_0x12a724,null))[_0xf770('0x22')](removeEntity(_0x12a724,null))['catch'](handleError(_0x12a724,null));};exports[_0xf770('0x47')]=function(_0x73e4a4,_0x5421c9){return db[_0xf770('0x2a')][_0xf770('0x47')]()[_0xf770('0x22')](respondWithResult(_0x5421c9,null))[_0xf770('0x43')](handleError(_0x5421c9,null));};