Built motion from commit (unavailable).|2.5.26
[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 _0x92f2=['mustache','path','ejs','fs-extra','lodash','squel','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','json','count','offset','limit','set','Content-Range','reject','save','update','then','destroy','end','error','stack','name','send','map','MemberReport','fieldName','type','key','model','query','keys','filters','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','findAll','rows','catch','show','rawAttributes','intersection','include','options','find','create','body','params','describe','eml-format','rimraf','request-promise','moment'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0x92f2,0x1b2));var _0x292f=function(_0xbca1b1,_0x33f0ce){_0xbca1b1=_0xbca1b1-0x0;var _0x4e1686=_0x92f2[_0xbca1b1];return _0x4e1686;};'use strict';var emlformat=require(_0x292f('0x0'));var rimraf=require(_0x292f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x292f('0x2'));var moment=require(_0x292f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x292f('0x4'));var util=require('util');var path=require(_0x292f('0x5'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x292f('0x6'));var fs=require('fs');var fs_extra=require(_0x292f('0x7'));var _=require(_0x292f('0x8'));var squel=require(_0x292f('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x292f('0xa'));var querystring=require(_0x292f('0xb'));var Papa=require(_0x292f('0xc'));var Redis=require(_0x292f('0xd'));var authService=require('../../components/auth/service');var qs=require(_0x292f('0xe'));var as=require(_0x292f('0xf'));var hardwareService=require(_0x292f('0x10'));var logger=require(_0x292f('0x11'))('api');var utils=require(_0x292f('0x12'));var config=require(_0x292f('0x13'));var licenseUtil=require(_0x292f('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2e833b,_0x55590d){_0x55590d=_0x55590d||0xcc;return function(_0x23345a){if(_0x23345a){return _0x2e833b[_0x292f('0x15')](_0x55590d);}return _0x2e833b[_0x292f('0x16')](_0x55590d)['end']();};}function respondWithResult(_0x3a12eb,_0x171879){_0x171879=_0x171879||0xc8;return function(_0x500614){if(_0x500614){return _0x3a12eb[_0x292f('0x16')](_0x171879)[_0x292f('0x17')](_0x500614);}};}function respondWithFilteredResult(_0x12db79,_0x396ced){return function(_0x42bfe7){if(_0x42bfe7){var _0x18e7fe=_0x42bfe7[_0x292f('0x18')],_0x254a50=_0x396ced[_0x292f('0x19')],_0x3e0fae=_0x396ced['offset']+_0x396ced[_0x292f('0x1a')],_0x4d7040;if(_0x3e0fae>=_0x18e7fe){_0x3e0fae=_0x18e7fe;_0x4d7040=0xc8;}else{_0x4d7040=0xce;}_0x12db79['status'](_0x4d7040);return _0x12db79[_0x292f('0x1b')](_0x292f('0x1c'),_0x254a50+'-'+_0x3e0fae+'/'+_0x18e7fe)[_0x292f('0x17')](_0x42bfe7);}return null;};}function patchUpdates(_0x927067){return function(_0x221be7){try{jsonpatch['apply'](_0x221be7,_0x927067,!![]);}catch(_0x3f24b1){return BPromise[_0x292f('0x1d')](_0x3f24b1);}return _0x221be7[_0x292f('0x1e')]();};}function saveUpdates(_0xcdd95d,_0x4442b){return function(_0x48d4c1){if(_0x48d4c1){return _0x48d4c1[_0x292f('0x1f')](_0xcdd95d)[_0x292f('0x20')](function(_0x568217){return _0x568217;});}return null;};}function removeEntity(_0x14f22b,_0x1c8abe){return function(_0x1b114a){if(_0x1b114a){return _0x1b114a[_0x292f('0x21')]()[_0x292f('0x20')](function(){_0x14f22b['status'](0xcc)[_0x292f('0x22')]();});}};}function handleEntityNotFound(_0x48b6c2,_0x586876){return function(_0x11555b){if(!_0x11555b){_0x48b6c2[_0x292f('0x15')](0x194);}return _0x11555b;};}function handleError(_0xff66d7,_0x493f76){_0x493f76=_0x493f76||0x1f4;return function(_0x228292){logger[_0x292f('0x23')](_0x228292[_0x292f('0x24')]);if(_0x228292['name']){delete _0x228292[_0x292f('0x25')];}_0xff66d7[_0x292f('0x16')](_0x493f76)[_0x292f('0x26')](_0x228292);};}exports['index']=function(_0xa30fee,_0x35d297){var _0xc6f2bc={},_0x22284e={},_0x3b51dc={'count':0x0,'rows':[]};var _0x25020a=_[_0x292f('0x27')](db[_0x292f('0x28')]['rawAttributes'],function(_0x33d1a9){return{'name':_0x33d1a9[_0x292f('0x29')],'type':_0x33d1a9[_0x292f('0x2a')][_0x292f('0x2b')]};});_0x22284e[_0x292f('0x2c')]=_[_0x292f('0x27')](_0x25020a,'name');_0x22284e[_0x292f('0x2d')]=_[_0x292f('0x2e')](_0xa30fee[_0x292f('0x2d')]);_0x22284e[_0x292f('0x2f')]=_['intersection'](_0x22284e[_0x292f('0x2c')],_0x22284e[_0x292f('0x2d')]);_0xc6f2bc['attributes']=_['intersection'](_0x22284e[_0x292f('0x2c')],qs[_0x292f('0x30')](_0xa30fee[_0x292f('0x2d')][_0x292f('0x30')]));_0xc6f2bc[_0x292f('0x31')]=_0xc6f2bc[_0x292f('0x31')][_0x292f('0x32')]?_0xc6f2bc[_0x292f('0x31')]:_0x22284e[_0x292f('0x2c')];if(!_0xa30fee[_0x292f('0x2d')][_0x292f('0x33')](_0x292f('0x34'))){_0xc6f2bc['limit']=qs[_0x292f('0x1a')](_0xa30fee[_0x292f('0x2d')][_0x292f('0x1a')]);_0xc6f2bc[_0x292f('0x19')]=qs[_0x292f('0x19')](_0xa30fee[_0x292f('0x2d')][_0x292f('0x19')]);}_0xc6f2bc[_0x292f('0x35')]=qs[_0x292f('0x36')](_0xa30fee[_0x292f('0x2d')][_0x292f('0x36')]);_0xc6f2bc[_0x292f('0x37')]=qs['filters'](_[_0x292f('0x38')](_0xa30fee[_0x292f('0x2d')],_0x22284e[_0x292f('0x2f')]),_0x25020a);if(_0xa30fee[_0x292f('0x2d')][_0x292f('0x39')]){_0xc6f2bc[_0x292f('0x37')]=_[_0x292f('0x3a')](_0xc6f2bc[_0x292f('0x37')],{'$or':_['map'](_0x25020a,function(_0x3dae73){if(_0x3dae73['type']!==_0x292f('0x3b')){var _0x3c9aca={};_0x3c9aca[_0x3dae73[_0x292f('0x25')]]={'$like':'%'+_0xa30fee[_0x292f('0x2d')][_0x292f('0x39')]+'%'};return _0x3c9aca;}})});}_0xc6f2bc=_[_0x292f('0x3a')]({},_0xc6f2bc,_0xa30fee['options']);var _0x530c9d={'where':_0xc6f2bc[_0x292f('0x37')]};return db['MemberReport'][_0x292f('0x18')](_0x530c9d)[_0x292f('0x20')](function(_0x231ee0){_0x3b51dc['count']=_0x231ee0;if(_0xa30fee[_0x292f('0x2d')]['includeAll']){_0xc6f2bc['include']=[{'all':!![]}];}return db[_0x292f('0x28')][_0x292f('0x3c')](_0xc6f2bc);})[_0x292f('0x20')](function(_0x4efc8c){_0x3b51dc[_0x292f('0x3d')]=_0x4efc8c;return _0x3b51dc;})[_0x292f('0x20')](respondWithFilteredResult(_0x35d297,_0xc6f2bc))[_0x292f('0x3e')](handleError(_0x35d297,null));};exports[_0x292f('0x3f')]=function(_0x3c4cfc,_0x1c03fe){var _0x1f1aaf={'raw':!![],'where':{'id':_0x3c4cfc['params']['id']}},_0x26166f={};_0x26166f[_0x292f('0x2c')]=_['keys'](db[_0x292f('0x28')][_0x292f('0x40')]);_0x26166f[_0x292f('0x2d')]=_[_0x292f('0x2e')](_0x3c4cfc[_0x292f('0x2d')]);_0x26166f[_0x292f('0x2f')]=_[_0x292f('0x41')](_0x26166f['model'],_0x26166f[_0x292f('0x2d')]);_0x1f1aaf[_0x292f('0x31')]=_[_0x292f('0x41')](_0x26166f[_0x292f('0x2c')],qs[_0x292f('0x30')](_0x3c4cfc[_0x292f('0x2d')][_0x292f('0x30')]));_0x1f1aaf[_0x292f('0x31')]=_0x1f1aaf['attributes'][_0x292f('0x32')]?_0x1f1aaf[_0x292f('0x31')]:_0x26166f['model'];if(_0x3c4cfc['query']['includeAll']){_0x1f1aaf[_0x292f('0x42')]=[{'all':!![]}];}_0x1f1aaf=_[_0x292f('0x3a')]({},_0x1f1aaf,_0x3c4cfc[_0x292f('0x43')]);return db[_0x292f('0x28')][_0x292f('0x44')](_0x1f1aaf)[_0x292f('0x20')](handleEntityNotFound(_0x1c03fe,null))['then'](respondWithResult(_0x1c03fe,null))[_0x292f('0x3e')](handleError(_0x1c03fe,null));};exports[_0x292f('0x45')]=function(_0xb907cf,_0x4c49dd){return db[_0x292f('0x28')]['create'](_0xb907cf[_0x292f('0x46')],{})[_0x292f('0x20')](respondWithResult(_0x4c49dd,0xc9))['catch'](handleError(_0x4c49dd,null));};exports[_0x292f('0x1f')]=function(_0x5b23b3,_0x4c08c2){if(_0x5b23b3['body']['id']){delete _0x5b23b3[_0x292f('0x46')]['id'];}return db[_0x292f('0x28')][_0x292f('0x44')]({'where':{'id':_0x5b23b3[_0x292f('0x47')]['id']}})['then'](handleEntityNotFound(_0x4c08c2,null))['then'](saveUpdates(_0x5b23b3[_0x292f('0x46')],null))[_0x292f('0x20')](respondWithResult(_0x4c08c2,null))[_0x292f('0x3e')](handleError(_0x4c08c2,null));};exports[_0x292f('0x21')]=function(_0x3194aa,_0x434332){return db[_0x292f('0x28')]['find']({'where':{'id':_0x3194aa['params']['id']}})[_0x292f('0x20')](handleEntityNotFound(_0x434332,null))[_0x292f('0x20')](removeEntity(_0x434332,null))['catch'](handleError(_0x434332,null));};exports['describe']=function(_0x65a0e4,_0x363081){return db[_0x292f('0x28')][_0x292f('0x48')]()['then'](respondWithResult(_0x363081,null))[_0x292f('0x3e')](handleError(_0x363081,null));};