Built motion from commit (unavailable).|2.5.8
[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 _0xa805=['../../mysqldb','sendStatus','status','end','offset','limit','Content-Range','json','apply','save','update','destroy','then','error','stack','name','send','index','map','MemberReport','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','findAll','catch','show','params','includeAll','include','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util'];(function(_0xea8947,_0x1b573d){var _0x2455e9=function(_0x18771e){while(--_0x18771e){_0xea8947['push'](_0xea8947['shift']());}};_0x2455e9(++_0x1b573d);}(_0xa805,0x11a));var _0x5a80=function(_0x3fecc1,_0x157ce8){_0x3fecc1=_0x3fecc1-0x0;var _0x581e35=_0xa805[_0x3fecc1];return _0x581e35;};'use strict';var pdf=require(_0x5a80('0x0'));var emlformat=require(_0x5a80('0x1'));var rimraf=require(_0x5a80('0x2'));var zipdir=require(_0x5a80('0x3'));var jsonpatch=require(_0x5a80('0x4'));var rp=require(_0x5a80('0x5'));var moment=require(_0x5a80('0x6'));var BPromise=require(_0x5a80('0x7'));var Mustache=require(_0x5a80('0x8'));var util=require(_0x5a80('0x9'));var path=require(_0x5a80('0xa'));var sox=require(_0x5a80('0xb'));var csv=require(_0x5a80('0xc'));var ejs=require(_0x5a80('0xd'));var fs=require('fs');var _=require('lodash');var squel=require(_0x5a80('0xe'));var crypto=require(_0x5a80('0xf'));var jsforce=require(_0x5a80('0x10'));var deskjs=require(_0x5a80('0x11'));var toCsv=require('to-csv');var querystring=require(_0x5a80('0x12'));var Papa=require(_0x5a80('0x13'));var Redis=require(_0x5a80('0x14'));var authService=require('../../components/auth/service');var qs=require(_0x5a80('0x15'));var as=require(_0x5a80('0x16'));var hardwareService=require(_0x5a80('0x17'));var logger=require('../../config/logger')(_0x5a80('0x18'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x5a80('0x19'));var db=require(_0x5a80('0x1a'))['db'];function respondWithStatusCode(_0x18af23,_0x19f4e6){_0x19f4e6=_0x19f4e6||0xcc;return function(_0x137341){if(_0x137341){return _0x18af23[_0x5a80('0x1b')](_0x19f4e6);}return _0x18af23[_0x5a80('0x1c')](_0x19f4e6)[_0x5a80('0x1d')]();};}function respondWithResult(_0x39062c,_0x46efc3){_0x46efc3=_0x46efc3||0xc8;return function(_0x28ffe4){if(_0x28ffe4){return _0x39062c[_0x5a80('0x1c')](_0x46efc3)['json'](_0x28ffe4);}};}function respondWithFilteredResult(_0x585530,_0x2c8391){return function(_0x2103c2){if(_0x2103c2){var _0x122f4f=_0x2103c2['count'],_0x2b86ca=_0x2c8391[_0x5a80('0x1e')],_0xf04301=_0x2c8391['offset']+_0x2c8391[_0x5a80('0x1f')],_0x4f6cdf;if(_0xf04301>=_0x122f4f){_0xf04301=_0x122f4f;_0x4f6cdf=0xc8;}else{_0x4f6cdf=0xce;}_0x585530[_0x5a80('0x1c')](_0x4f6cdf);return _0x585530['set'](_0x5a80('0x20'),_0x2b86ca+'-'+_0xf04301+'/'+_0x122f4f)[_0x5a80('0x21')](_0x2103c2);}return null;};}function patchUpdates(_0x209207){return function(_0x4625c5){try{jsonpatch[_0x5a80('0x22')](_0x4625c5,_0x209207,!![]);}catch(_0x364893){return BPromise['reject'](_0x364893);}return _0x4625c5[_0x5a80('0x23')]();};}function saveUpdates(_0x1128d0,_0x553adc){return function(_0x353485){if(_0x353485){return _0x353485[_0x5a80('0x24')](_0x1128d0)['then'](function(_0xc9c045){return _0xc9c045;});}return null;};}function removeEntity(_0x4ee575,_0x252f96){return function(_0x5c168a){if(_0x5c168a){return _0x5c168a[_0x5a80('0x25')]()[_0x5a80('0x26')](function(){_0x4ee575['status'](0xcc)[_0x5a80('0x1d')]();});}};}function handleEntityNotFound(_0x57d33c,_0x3550bd){return function(_0x287dab){if(!_0x287dab){_0x57d33c[_0x5a80('0x1b')](0x194);}return _0x287dab;};}function handleError(_0x10495c,_0x3443e4){_0x3443e4=_0x3443e4||0x1f4;return function(_0x38b45e){logger[_0x5a80('0x27')](_0x38b45e[_0x5a80('0x28')]);if(_0x38b45e[_0x5a80('0x29')]){delete _0x38b45e[_0x5a80('0x29')];}_0x10495c['status'](_0x3443e4)[_0x5a80('0x2a')](_0x38b45e);};}exports[_0x5a80('0x2b')]=function(_0x172d57,_0x4ff3ab){var _0x98386a={},_0x45a1b1={},_0x26f889={'count':0x0,'rows':[]};var _0x4fe30b=_[_0x5a80('0x2c')](db[_0x5a80('0x2d')][_0x5a80('0x2e')],function(_0x424c06){return{'name':_0x424c06[_0x5a80('0x2f')],'type':_0x424c06[_0x5a80('0x30')][_0x5a80('0x31')]};});_0x45a1b1[_0x5a80('0x32')]=_[_0x5a80('0x2c')](_0x4fe30b,_0x5a80('0x29'));_0x45a1b1[_0x5a80('0x33')]=_[_0x5a80('0x34')](_0x172d57[_0x5a80('0x33')]);_0x45a1b1['filters']=_[_0x5a80('0x35')](_0x45a1b1[_0x5a80('0x32')],_0x45a1b1[_0x5a80('0x33')]);_0x98386a[_0x5a80('0x36')]=_[_0x5a80('0x35')](_0x45a1b1['model'],qs['fields'](_0x172d57[_0x5a80('0x33')][_0x5a80('0x37')]));_0x98386a[_0x5a80('0x36')]=_0x98386a[_0x5a80('0x36')][_0x5a80('0x38')]?_0x98386a[_0x5a80('0x36')]:_0x45a1b1[_0x5a80('0x32')];if(!_0x172d57[_0x5a80('0x33')][_0x5a80('0x39')](_0x5a80('0x3a'))){_0x98386a['limit']=qs[_0x5a80('0x1f')](_0x172d57[_0x5a80('0x33')][_0x5a80('0x1f')]);_0x98386a['offset']=qs[_0x5a80('0x1e')](_0x172d57[_0x5a80('0x33')][_0x5a80('0x1e')]);}_0x98386a[_0x5a80('0x3b')]=qs[_0x5a80('0x3c')](_0x172d57['query'][_0x5a80('0x3c')]);_0x98386a[_0x5a80('0x3d')]=qs[_0x5a80('0x3e')](_['pick'](_0x172d57[_0x5a80('0x33')],_0x45a1b1[_0x5a80('0x3e')]),_0x4fe30b);if(_0x172d57[_0x5a80('0x33')][_0x5a80('0x3f')]){_0x98386a['where']=_[_0x5a80('0x40')](_0x98386a[_0x5a80('0x3d')],{'$or':_[_0x5a80('0x2c')](_0x4fe30b,function(_0x2805f8){if(_0x2805f8[_0x5a80('0x30')]!==_0x5a80('0x41')){var _0x23fc87={};_0x23fc87[_0x2805f8[_0x5a80('0x29')]]={'$like':'%'+_0x172d57['query'][_0x5a80('0x3f')]+'%'};return _0x23fc87;}})});}_0x98386a=_[_0x5a80('0x40')]({},_0x98386a,_0x172d57[_0x5a80('0x42')]);var _0xc49395={'where':_0x98386a[_0x5a80('0x3d')]};return db[_0x5a80('0x2d')]['count'](_0xc49395)[_0x5a80('0x26')](function(_0x1f1b4a){_0x26f889['count']=_0x1f1b4a;if(_0x172d57[_0x5a80('0x33')]['includeAll']){_0x98386a['include']=[{'all':!![]}];}return db[_0x5a80('0x2d')][_0x5a80('0x43')](_0x98386a);})[_0x5a80('0x26')](function(_0x203576){_0x26f889['rows']=_0x203576;return _0x26f889;})['then'](respondWithFilteredResult(_0x4ff3ab,_0x98386a))[_0x5a80('0x44')](handleError(_0x4ff3ab,null));};exports[_0x5a80('0x45')]=function(_0x4c79c3,_0x63bd9e){var _0xd2302f={'raw':!![],'where':{'id':_0x4c79c3[_0x5a80('0x46')]['id']}},_0x96dfa9={};_0x96dfa9['model']=_['keys'](db[_0x5a80('0x2d')][_0x5a80('0x2e')]);_0x96dfa9[_0x5a80('0x33')]=_[_0x5a80('0x34')](_0x4c79c3['query']);_0x96dfa9[_0x5a80('0x3e')]=_[_0x5a80('0x35')](_0x96dfa9['model'],_0x96dfa9[_0x5a80('0x33')]);_0xd2302f[_0x5a80('0x36')]=_[_0x5a80('0x35')](_0x96dfa9[_0x5a80('0x32')],qs[_0x5a80('0x37')](_0x4c79c3[_0x5a80('0x33')][_0x5a80('0x37')]));_0xd2302f['attributes']=_0xd2302f['attributes'][_0x5a80('0x38')]?_0xd2302f['attributes']:_0x96dfa9[_0x5a80('0x32')];if(_0x4c79c3[_0x5a80('0x33')][_0x5a80('0x47')]){_0xd2302f[_0x5a80('0x48')]=[{'all':!![]}];}_0xd2302f=_[_0x5a80('0x40')]({},_0xd2302f,_0x4c79c3[_0x5a80('0x42')]);return db['MemberReport'][_0x5a80('0x49')](_0xd2302f)[_0x5a80('0x26')](handleEntityNotFound(_0x63bd9e,null))[_0x5a80('0x26')](respondWithResult(_0x63bd9e,null))[_0x5a80('0x44')](handleError(_0x63bd9e,null));};exports[_0x5a80('0x4a')]=function(_0x1796cf,_0x3e58d5){return db['MemberReport'][_0x5a80('0x4a')](_0x1796cf[_0x5a80('0x4b')],{})[_0x5a80('0x26')](respondWithResult(_0x3e58d5,0xc9))['catch'](handleError(_0x3e58d5,null));};exports[_0x5a80('0x24')]=function(_0x5223f8,_0x1b523e){if(_0x5223f8['body']['id']){delete _0x5223f8[_0x5a80('0x4b')]['id'];}return db['MemberReport'][_0x5a80('0x49')]({'where':{'id':_0x5223f8[_0x5a80('0x46')]['id']}})[_0x5a80('0x26')](handleEntityNotFound(_0x1b523e,null))[_0x5a80('0x26')](saveUpdates(_0x5223f8['body'],null))[_0x5a80('0x26')](respondWithResult(_0x1b523e,null))[_0x5a80('0x44')](handleError(_0x1b523e,null));};exports[_0x5a80('0x25')]=function(_0x16e1d1,_0x114e2c){return db[_0x5a80('0x2d')][_0x5a80('0x49')]({'where':{'id':_0x16e1d1[_0x5a80('0x46')]['id']}})[_0x5a80('0x26')](handleEntityNotFound(_0x114e2c,null))[_0x5a80('0x26')](removeEntity(_0x114e2c,null))[_0x5a80('0x44')](handleError(_0x114e2c,null));};exports['describe']=function(_0x492532,_0x4d7422){return db['MemberReport'][_0x5a80('0x4c')]()[_0x5a80('0x26')](respondWithResult(_0x4d7422,null))[_0x5a80('0x44')](handleError(_0x4d7422,null));};