Built motion from commit (unavailable).|2.5.21
[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 _0xf37f=['../../mysqldb','sendStatus','status','end','count','offset','set','Content-Range','json','reject','save','update','then','destroy','error','name','send','map','MemberReport','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort','merge','filter','where','includeAll','include','findAll','catch','show','params','options','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','lodash','crypto','jsforce','desk.js','to-csv','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util'];(function(_0x3ac8e8,_0xa14c49){var _0x415a7c=function(_0x1973f5){while(--_0x1973f5){_0x3ac8e8['push'](_0x3ac8e8['shift']());}};_0x415a7c(++_0xa14c49);}(_0xf37f,0x79));var _0xff37=function(_0x1b1ce5,_0x508743){_0x1b1ce5=_0x1b1ce5-0x0;var _0x432ff6=_0xf37f[_0x1b1ce5];return _0x432ff6;};'use strict';var pdf=require(_0xff37('0x0'));var emlformat=require(_0xff37('0x1'));var rimraf=require(_0xff37('0x2'));var zipdir=require(_0xff37('0x3'));var jsonpatch=require(_0xff37('0x4'));var rp=require('request-promise');var moment=require(_0xff37('0x5'));var BPromise=require(_0xff37('0x6'));var Mustache=require(_0xff37('0x7'));var util=require(_0xff37('0x8'));var path=require('path');var sox=require(_0xff37('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xff37('0xa'));var squel=require('squel');var crypto=require(_0xff37('0xb'));var jsforce=require(_0xff37('0xc'));var deskjs=require(_0xff37('0xd'));var toCsv=require(_0xff37('0xe'));var querystring=require('querystring');var Papa=require(_0xff37('0xf'));var Redis=require('ioredis');var authService=require(_0xff37('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xff37('0x11'));var hardwareService=require(_0xff37('0x12'));var logger=require(_0xff37('0x13'))(_0xff37('0x14'));var utils=require(_0xff37('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xff37('0x16'));var db=require(_0xff37('0x17'))['db'];function respondWithStatusCode(_0x4dafeb,_0x53a526){_0x53a526=_0x53a526||0xcc;return function(_0x3d6a0d){if(_0x3d6a0d){return _0x4dafeb[_0xff37('0x18')](_0x53a526);}return _0x4dafeb[_0xff37('0x19')](_0x53a526)[_0xff37('0x1a')]();};}function respondWithResult(_0x525fe8,_0xf871fb){_0xf871fb=_0xf871fb||0xc8;return function(_0x5c47bd){if(_0x5c47bd){return _0x525fe8[_0xff37('0x19')](_0xf871fb)['json'](_0x5c47bd);}};}function respondWithFilteredResult(_0xb29132,_0x30f04f){return function(_0x390150){if(_0x390150){var _0x244dc5=_0x390150[_0xff37('0x1b')],_0x234af9=_0x30f04f[_0xff37('0x1c')],_0xb0af17=_0x30f04f[_0xff37('0x1c')]+_0x30f04f['limit'],_0x22077c;if(_0xb0af17>=_0x244dc5){_0xb0af17=_0x244dc5;_0x22077c=0xc8;}else{_0x22077c=0xce;}_0xb29132[_0xff37('0x19')](_0x22077c);return _0xb29132[_0xff37('0x1d')](_0xff37('0x1e'),_0x234af9+'-'+_0xb0af17+'/'+_0x244dc5)[_0xff37('0x1f')](_0x390150);}return null;};}function patchUpdates(_0x7a74fb){return function(_0xa84031){try{jsonpatch['apply'](_0xa84031,_0x7a74fb,!![]);}catch(_0x74af36){return BPromise[_0xff37('0x20')](_0x74af36);}return _0xa84031[_0xff37('0x21')]();};}function saveUpdates(_0x57877a,_0x2bf11d){return function(_0x3ef324){if(_0x3ef324){return _0x3ef324[_0xff37('0x22')](_0x57877a)[_0xff37('0x23')](function(_0x156bbb){return _0x156bbb;});}return null;};}function removeEntity(_0x362e46,_0x8dcc5){return function(_0x48a42a){if(_0x48a42a){return _0x48a42a[_0xff37('0x24')]()[_0xff37('0x23')](function(){_0x362e46[_0xff37('0x19')](0xcc)[_0xff37('0x1a')]();});}};}function handleEntityNotFound(_0x3e9271,_0x1d4bdd){return function(_0x2b3160){if(!_0x2b3160){_0x3e9271[_0xff37('0x18')](0x194);}return _0x2b3160;};}function handleError(_0x2878b0,_0x43d12f){_0x43d12f=_0x43d12f||0x1f4;return function(_0x42dd4c){logger[_0xff37('0x25')](_0x42dd4c['stack']);if(_0x42dd4c[_0xff37('0x26')]){delete _0x42dd4c[_0xff37('0x26')];}_0x2878b0['status'](_0x43d12f)[_0xff37('0x27')](_0x42dd4c);};}exports['index']=function(_0x595956,_0x4bb546){var _0x3f4029={},_0xa4f48a={},_0x3055a8={'count':0x0,'rows':[]};var _0x3e85bb=_[_0xff37('0x28')](db[_0xff37('0x29')][_0xff37('0x2a')],function(_0xcb1f18){return{'name':_0xcb1f18['fieldName'],'type':_0xcb1f18[_0xff37('0x2b')][_0xff37('0x2c')]};});_0xa4f48a[_0xff37('0x2d')]=_[_0xff37('0x28')](_0x3e85bb,_0xff37('0x26'));_0xa4f48a[_0xff37('0x2e')]=_[_0xff37('0x2f')](_0x595956[_0xff37('0x2e')]);_0xa4f48a[_0xff37('0x30')]=_[_0xff37('0x31')](_0xa4f48a[_0xff37('0x2d')],_0xa4f48a[_0xff37('0x2e')]);_0x3f4029['attributes']=_[_0xff37('0x31')](_0xa4f48a['model'],qs[_0xff37('0x32')](_0x595956[_0xff37('0x2e')][_0xff37('0x32')]));_0x3f4029[_0xff37('0x33')]=_0x3f4029['attributes'][_0xff37('0x34')]?_0x3f4029[_0xff37('0x33')]:_0xa4f48a[_0xff37('0x2d')];if(!_0x595956[_0xff37('0x2e')][_0xff37('0x35')](_0xff37('0x36'))){_0x3f4029[_0xff37('0x37')]=qs['limit'](_0x595956[_0xff37('0x2e')]['limit']);_0x3f4029[_0xff37('0x1c')]=qs[_0xff37('0x1c')](_0x595956[_0xff37('0x2e')][_0xff37('0x1c')]);}_0x3f4029[_0xff37('0x38')]=qs[_0xff37('0x39')](_0x595956[_0xff37('0x2e')][_0xff37('0x39')]);_0x3f4029['where']=qs['filters'](_['pick'](_0x595956[_0xff37('0x2e')],_0xa4f48a[_0xff37('0x30')]),_0x3e85bb);if(_0x595956[_0xff37('0x2e')]['filter']){_0x3f4029['where']=_[_0xff37('0x3a')](_0x3f4029['where'],{'$or':_[_0xff37('0x28')](_0x3e85bb,function(_0x462ecc){if(_0x462ecc[_0xff37('0x2b')]!=='VIRTUAL'){var _0x113ac9={};_0x113ac9[_0x462ecc[_0xff37('0x26')]]={'$like':'%'+_0x595956[_0xff37('0x2e')][_0xff37('0x3b')]+'%'};return _0x113ac9;}})});}_0x3f4029=_[_0xff37('0x3a')]({},_0x3f4029,_0x595956['options']);var _0x51435a={'where':_0x3f4029[_0xff37('0x3c')]};return db['MemberReport'][_0xff37('0x1b')](_0x51435a)[_0xff37('0x23')](function(_0x5d768e){_0x3055a8['count']=_0x5d768e;if(_0x595956[_0xff37('0x2e')][_0xff37('0x3d')]){_0x3f4029[_0xff37('0x3e')]=[{'all':!![]}];}return db[_0xff37('0x29')][_0xff37('0x3f')](_0x3f4029);})[_0xff37('0x23')](function(_0x5c2531){_0x3055a8['rows']=_0x5c2531;return _0x3055a8;})['then'](respondWithFilteredResult(_0x4bb546,_0x3f4029))[_0xff37('0x40')](handleError(_0x4bb546,null));};exports[_0xff37('0x41')]=function(_0x5e50b2,_0x56de6d){var _0x2ee961={'raw':!![],'where':{'id':_0x5e50b2[_0xff37('0x42')]['id']}},_0x3ce8b9={};_0x3ce8b9['model']=_[_0xff37('0x2f')](db[_0xff37('0x29')]['rawAttributes']);_0x3ce8b9[_0xff37('0x2e')]=_[_0xff37('0x2f')](_0x5e50b2['query']);_0x3ce8b9[_0xff37('0x30')]=_[_0xff37('0x31')](_0x3ce8b9[_0xff37('0x2d')],_0x3ce8b9['query']);_0x2ee961[_0xff37('0x33')]=_[_0xff37('0x31')](_0x3ce8b9[_0xff37('0x2d')],qs[_0xff37('0x32')](_0x5e50b2[_0xff37('0x2e')][_0xff37('0x32')]));_0x2ee961[_0xff37('0x33')]=_0x2ee961[_0xff37('0x33')][_0xff37('0x34')]?_0x2ee961[_0xff37('0x33')]:_0x3ce8b9[_0xff37('0x2d')];if(_0x5e50b2[_0xff37('0x2e')][_0xff37('0x3d')]){_0x2ee961[_0xff37('0x3e')]=[{'all':!![]}];}_0x2ee961=_[_0xff37('0x3a')]({},_0x2ee961,_0x5e50b2[_0xff37('0x43')]);return db[_0xff37('0x29')][_0xff37('0x44')](_0x2ee961)[_0xff37('0x23')](handleEntityNotFound(_0x56de6d,null))['then'](respondWithResult(_0x56de6d,null))[_0xff37('0x40')](handleError(_0x56de6d,null));};exports[_0xff37('0x45')]=function(_0x3a4ca8,_0x1d6b4e){return db[_0xff37('0x29')][_0xff37('0x45')](_0x3a4ca8['body'],{})['then'](respondWithResult(_0x1d6b4e,0xc9))[_0xff37('0x40')](handleError(_0x1d6b4e,null));};exports[_0xff37('0x22')]=function(_0x4ee986,_0x2ae47e){if(_0x4ee986[_0xff37('0x46')]['id']){delete _0x4ee986[_0xff37('0x46')]['id'];}return db['MemberReport'][_0xff37('0x44')]({'where':{'id':_0x4ee986[_0xff37('0x42')]['id']}})[_0xff37('0x23')](handleEntityNotFound(_0x2ae47e,null))[_0xff37('0x23')](saveUpdates(_0x4ee986[_0xff37('0x46')],null))[_0xff37('0x23')](respondWithResult(_0x2ae47e,null))[_0xff37('0x40')](handleError(_0x2ae47e,null));};exports[_0xff37('0x24')]=function(_0x555088,_0x1cfeec){return db[_0xff37('0x29')][_0xff37('0x44')]({'where':{'id':_0x555088[_0xff37('0x42')]['id']}})[_0xff37('0x23')](handleEntityNotFound(_0x1cfeec,null))[_0xff37('0x23')](removeEntity(_0x1cfeec,null))['catch'](handleError(_0x1cfeec,null));};exports[_0xff37('0x47')]=function(_0x4aea66,_0x3355cf){return db[_0xff37('0x29')][_0xff37('0x47')]()[_0xff37('0x23')](respondWithResult(_0x3355cf,null))['catch'](handleError(_0x3355cf,null));};