4d35cf1b55bc470c594070885641256ee1266adb
[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 _0x64f9=['mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','count','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','MemberReport','rawAttributes','fieldName','type','key','filters','query','attributes','intersection','model','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','catch','body','find','destroy','describe','rimraf','fast-json-patch','request-promise','moment','bluebird'];(function(_0x49767b,_0x445251){var _0x112dcb=function(_0x162499){while(--_0x162499){_0x49767b['push'](_0x49767b['shift']());}};_0x112dcb(++_0x445251);}(_0x64f9,0xa1));var _0x964f=function(_0x1aed80,_0x3ca6f6){_0x1aed80=_0x1aed80-0x0;var _0x43961e=_0x64f9[_0x1aed80];return _0x43961e;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x964f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x964f('0x1'));var rp=require(_0x964f('0x2'));var moment=require(_0x964f('0x3'));var BPromise=require(_0x964f('0x4'));var Mustache=require(_0x964f('0x5'));var util=require(_0x964f('0x6'));var path=require(_0x964f('0x7'));var sox=require(_0x964f('0x8'));var csv=require('to-csv');var ejs=require(_0x964f('0x9'));var fs=require('fs');var fs_extra=require(_0x964f('0xa'));var _=require(_0x964f('0xb'));var squel=require(_0x964f('0xc'));var crypto=require(_0x964f('0xd'));var jsforce=require(_0x964f('0xe'));var deskjs=require(_0x964f('0xf'));var toCsv=require(_0x964f('0x10'));var querystring=require(_0x964f('0x11'));var Papa=require(_0x964f('0x12'));var Redis=require('ioredis');var authService=require(_0x964f('0x13'));var qs=require(_0x964f('0x14'));var as=require(_0x964f('0x15'));var hardwareService=require(_0x964f('0x16'));var logger=require(_0x964f('0x17'))('api');var utils=require(_0x964f('0x18'));var config=require(_0x964f('0x19'));var licenseUtil=require(_0x964f('0x1a'));var db=require(_0x964f('0x1b'))['db'];function respondWithStatusCode(_0xec0142,_0x4ed1ae){_0x4ed1ae=_0x4ed1ae||0xcc;return function(_0x3c3601){if(_0x3c3601){return _0xec0142[_0x964f('0x1c')](_0x4ed1ae);}return _0xec0142['status'](_0x4ed1ae)[_0x964f('0x1d')]();};}function respondWithResult(_0x4d46a5,_0x153d62){_0x153d62=_0x153d62||0xc8;return function(_0x98106){if(_0x98106){return _0x4d46a5[_0x964f('0x1e')](_0x153d62)[_0x964f('0x1f')](_0x98106);}};}function respondWithFilteredResult(_0x6a5d78,_0x2c046f){return function(_0x2b4815){if(_0x2b4815){var _0x4ce98a=typeof _0x2c046f[_0x964f('0x20')]===_0x964f('0x21')&&typeof _0x2c046f['limit']==='undefined';var _0xe72464=_0x2b4815['count'];var _0x589ac9=_0x4ce98a?0x0:_0x2c046f[_0x964f('0x20')];var _0x3480b2=_0x4ce98a?_0x2b4815[_0x964f('0x22')]:_0x2c046f[_0x964f('0x20')]+_0x2c046f['limit'];var _0x4b70b2;if(_0x3480b2>=_0xe72464){_0x3480b2=_0xe72464;_0x4b70b2=0xc8;}else{_0x4b70b2=0xce;}_0x6a5d78['status'](_0x4b70b2);return _0x6a5d78[_0x964f('0x23')](_0x964f('0x24'),_0x589ac9+'-'+_0x3480b2+'/'+_0xe72464)['json'](_0x2b4815);}return null;};}function patchUpdates(_0x591d23){return function(_0x2b9f00){try{jsonpatch[_0x964f('0x25')](_0x2b9f00,_0x591d23,!![]);}catch(_0x202e76){return BPromise[_0x964f('0x26')](_0x202e76);}return _0x2b9f00[_0x964f('0x27')]();};}function saveUpdates(_0x14c2a9,_0x5a3ad5){return function(_0x4cd1bb){if(_0x4cd1bb){return _0x4cd1bb[_0x964f('0x28')](_0x14c2a9)[_0x964f('0x29')](function(_0x2d5d64){return _0x2d5d64;});}return null;};}function removeEntity(_0x48f850,_0x2b225f){return function(_0x5621d2){if(_0x5621d2){return _0x5621d2['destroy']()['then'](function(){_0x48f850[_0x964f('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x573108,_0x576465){return function(_0x5e2d5c){if(!_0x5e2d5c){_0x573108[_0x964f('0x1c')](0x194);}return _0x5e2d5c;};}function handleError(_0x3c0413,_0x2a37c3){_0x2a37c3=_0x2a37c3||0x1f4;return function(_0x43077f){logger[_0x964f('0x2a')](_0x43077f[_0x964f('0x2b')]);if(_0x43077f[_0x964f('0x2c')]){delete _0x43077f[_0x964f('0x2c')];}_0x3c0413[_0x964f('0x1e')](_0x2a37c3)[_0x964f('0x2d')](_0x43077f);};}exports[_0x964f('0x2e')]=function(_0x1853fe,_0x1dfa6e){var _0x9db21e={},_0x25d399={},_0x2dd5a1={'count':0x0,'rows':[]};var _0x5aecfd=_[_0x964f('0x2f')](db[_0x964f('0x30')][_0x964f('0x31')],function(_0x23399e){return{'name':_0x23399e[_0x964f('0x32')],'type':_0x23399e[_0x964f('0x33')][_0x964f('0x34')]};});_0x25d399['model']=_['map'](_0x5aecfd,_0x964f('0x2c'));_0x25d399['query']=_['keys'](_0x1853fe['query']);_0x25d399[_0x964f('0x35')]=_['intersection'](_0x25d399['model'],_0x25d399[_0x964f('0x36')]);_0x9db21e[_0x964f('0x37')]=_[_0x964f('0x38')](_0x25d399[_0x964f('0x39')],qs[_0x964f('0x3a')](_0x1853fe['query']['fields']));_0x9db21e[_0x964f('0x37')]=_0x9db21e[_0x964f('0x37')][_0x964f('0x3b')]?_0x9db21e[_0x964f('0x37')]:_0x25d399[_0x964f('0x39')];if(!_0x1853fe[_0x964f('0x36')][_0x964f('0x3c')](_0x964f('0x3d'))){_0x9db21e[_0x964f('0x3e')]=qs['limit'](_0x1853fe[_0x964f('0x36')][_0x964f('0x3e')]);_0x9db21e['offset']=qs[_0x964f('0x20')](_0x1853fe[_0x964f('0x36')][_0x964f('0x20')]);}_0x9db21e[_0x964f('0x3f')]=qs[_0x964f('0x40')](_0x1853fe[_0x964f('0x36')][_0x964f('0x40')]);_0x9db21e[_0x964f('0x41')]=qs[_0x964f('0x35')](_[_0x964f('0x42')](_0x1853fe[_0x964f('0x36')],_0x25d399['filters']),_0x5aecfd);if(_0x1853fe[_0x964f('0x36')][_0x964f('0x43')]){_0x9db21e[_0x964f('0x41')]=_[_0x964f('0x44')](_0x9db21e['where'],{'$or':_[_0x964f('0x2f')](_0x5aecfd,function(_0x51a94d){if(_0x51a94d[_0x964f('0x33')]!==_0x964f('0x45')){var _0x59aa3c={};_0x59aa3c[_0x51a94d['name']]={'$like':'%'+_0x1853fe[_0x964f('0x36')]['filter']+'%'};return _0x59aa3c;}})});}_0x9db21e=_[_0x964f('0x44')]({},_0x9db21e,_0x1853fe[_0x964f('0x46')]);var _0x41fe17={'where':_0x9db21e[_0x964f('0x41')]};return db[_0x964f('0x30')]['count'](_0x41fe17)[_0x964f('0x29')](function(_0x2451b4){_0x2dd5a1[_0x964f('0x22')]=_0x2451b4;if(_0x1853fe[_0x964f('0x36')][_0x964f('0x47')]){_0x9db21e[_0x964f('0x48')]=[{'all':!![]}];}return db[_0x964f('0x30')][_0x964f('0x49')](_0x9db21e);})[_0x964f('0x29')](function(_0x1f6095){_0x2dd5a1[_0x964f('0x4a')]=_0x1f6095;return _0x2dd5a1;})['then'](respondWithFilteredResult(_0x1dfa6e,_0x9db21e))['catch'](handleError(_0x1dfa6e,null));};exports[_0x964f('0x4b')]=function(_0x166613,_0x43a71b){var _0x4ad6e7={'raw':!![],'where':{'id':_0x166613[_0x964f('0x4c')]['id']}},_0x38f00e={};_0x38f00e[_0x964f('0x39')]=_[_0x964f('0x4d')](db[_0x964f('0x30')][_0x964f('0x31')]);_0x38f00e[_0x964f('0x36')]=_[_0x964f('0x4d')](_0x166613[_0x964f('0x36')]);_0x38f00e[_0x964f('0x35')]=_[_0x964f('0x38')](_0x38f00e[_0x964f('0x39')],_0x38f00e['query']);_0x4ad6e7[_0x964f('0x37')]=_['intersection'](_0x38f00e[_0x964f('0x39')],qs[_0x964f('0x3a')](_0x166613[_0x964f('0x36')][_0x964f('0x3a')]));_0x4ad6e7[_0x964f('0x37')]=_0x4ad6e7[_0x964f('0x37')][_0x964f('0x3b')]?_0x4ad6e7[_0x964f('0x37')]:_0x38f00e[_0x964f('0x39')];if(_0x166613[_0x964f('0x36')][_0x964f('0x47')]){_0x4ad6e7[_0x964f('0x48')]=[{'all':!![]}];}_0x4ad6e7=_[_0x964f('0x44')]({},_0x4ad6e7,_0x166613[_0x964f('0x46')]);return db[_0x964f('0x30')]['find'](_0x4ad6e7)['then'](handleEntityNotFound(_0x43a71b,null))[_0x964f('0x29')](respondWithResult(_0x43a71b,null))[_0x964f('0x4e')](handleError(_0x43a71b,null));};exports['create']=function(_0x43cd00,_0x130799){return db[_0x964f('0x30')]['create'](_0x43cd00[_0x964f('0x4f')],{})['then'](respondWithResult(_0x130799,0xc9))[_0x964f('0x4e')](handleError(_0x130799,null));};exports['update']=function(_0x4926c2,_0x5d73c2){if(_0x4926c2[_0x964f('0x4f')]['id']){delete _0x4926c2[_0x964f('0x4f')]['id'];}return db[_0x964f('0x30')][_0x964f('0x50')]({'where':{'id':_0x4926c2[_0x964f('0x4c')]['id']}})[_0x964f('0x29')](handleEntityNotFound(_0x5d73c2,null))[_0x964f('0x29')](saveUpdates(_0x4926c2[_0x964f('0x4f')],null))[_0x964f('0x29')](respondWithResult(_0x5d73c2,null))[_0x964f('0x4e')](handleError(_0x5d73c2,null));};exports[_0x964f('0x51')]=function(_0x5c2fa7,_0x6e1cf4){return db[_0x964f('0x30')]['find']({'where':{'id':_0x5c2fa7[_0x964f('0x4c')]['id']}})[_0x964f('0x29')](handleEntityNotFound(_0x6e1cf4,null))[_0x964f('0x29')](removeEntity(_0x6e1cf4,null))[_0x964f('0x4e')](handleError(_0x6e1cf4,null));};exports[_0x964f('0x52')]=function(_0xa11b02,_0x42142c){return db[_0x964f('0x30')]['describe']()['then'](respondWithResult(_0x42142c,null))[_0x964f('0x4e')](handleError(_0x42142c,null));};