b1d4982160252e4112c0fa278107c65cec964f3a
[motion2.git] / server / api / squareReport / squareReport.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 _0xce8a=['json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','stack','name','send','index','map','SquareReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','length','find','create','body','params','describe','eml-format','rimraf','zip-dir','request-promise','mustache','util','path','fs-extra','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end'];(function(_0x18b2a3,_0x322f6c){var _0x1152f5=function(_0x5292c2){while(--_0x5292c2){_0x18b2a3['push'](_0x18b2a3['shift']());}};_0x1152f5(++_0x322f6c);}(_0xce8a,0x7f));var _0xace8=function(_0x166d5a,_0x49f250){_0x166d5a=_0x166d5a-0x0;var _0x126ef5=_0xce8a[_0x166d5a];return _0x126ef5;};'use strict';var emlformat=require(_0xace8('0x0'));var rimraf=require(_0xace8('0x1'));var zipdir=require(_0xace8('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xace8('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xace8('0x4'));var util=require(_0xace8('0x5'));var path=require(_0xace8('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xace8('0x7'));var _=require(_0xace8('0x8'));var squel=require(_0xace8('0x9'));var crypto=require(_0xace8('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xace8('0xb'));var toCsv=require(_0xace8('0xc'));var querystring=require(_0xace8('0xd'));var Papa=require(_0xace8('0xe'));var Redis=require(_0xace8('0xf'));var authService=require(_0xace8('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xace8('0x11'));var hardwareService=require(_0xace8('0x12'));var logger=require('../../config/logger')(_0xace8('0x13'));var utils=require(_0xace8('0x14'));var config=require(_0xace8('0x15'));var licenseUtil=require(_0xace8('0x16'));var db=require(_0xace8('0x17'))['db'];function respondWithStatusCode(_0x26d57d,_0x2ff0ca){_0x2ff0ca=_0x2ff0ca||0xcc;return function(_0xa08f05){if(_0xa08f05){return _0x26d57d[_0xace8('0x18')](_0x2ff0ca);}return _0x26d57d[_0xace8('0x19')](_0x2ff0ca)[_0xace8('0x1a')]();};}function respondWithResult(_0x248e1f,_0x3b664f){_0x3b664f=_0x3b664f||0xc8;return function(_0x77a4c1){if(_0x77a4c1){return _0x248e1f[_0xace8('0x19')](_0x3b664f)[_0xace8('0x1b')](_0x77a4c1);}};}function respondWithFilteredResult(_0x4aa796,_0x4c409b){return function(_0x5373a4){if(_0x5373a4){var _0x5e79c0=typeof _0x4c409b[_0xace8('0x1c')]===_0xace8('0x1d')&&typeof _0x4c409b[_0xace8('0x1e')]===_0xace8('0x1d');var _0x4383c2=_0x5373a4['count'];var _0x11344a=_0x5e79c0?0x0:_0x4c409b['offset'];var _0x3e4822=_0x5e79c0?_0x5373a4[_0xace8('0x1f')]:_0x4c409b[_0xace8('0x1c')]+_0x4c409b[_0xace8('0x1e')];var _0x5ce4d4;if(_0x3e4822>=_0x4383c2){_0x3e4822=_0x4383c2;_0x5ce4d4=0xc8;}else{_0x5ce4d4=0xce;}_0x4aa796[_0xace8('0x19')](_0x5ce4d4);return _0x4aa796[_0xace8('0x20')](_0xace8('0x21'),_0x11344a+'-'+_0x3e4822+'/'+_0x4383c2)[_0xace8('0x1b')](_0x5373a4);}return null;};}function patchUpdates(_0x19a976){return function(_0x6926f1){try{jsonpatch[_0xace8('0x22')](_0x6926f1,_0x19a976,!![]);}catch(_0x40e4ae){return BPromise[_0xace8('0x23')](_0x40e4ae);}return _0x6926f1['save']();};}function saveUpdates(_0x27ff3c,_0x4cbe2c){return function(_0x3bb395){if(_0x3bb395){return _0x3bb395[_0xace8('0x24')](_0x27ff3c)[_0xace8('0x25')](function(_0x47de0a){return _0x47de0a;});}return null;};}function removeEntity(_0x23d922,_0x572d7d){return function(_0x224e96){if(_0x224e96){return _0x224e96[_0xace8('0x26')]()[_0xace8('0x25')](function(){_0x23d922['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x55ec90,_0x21281c){return function(_0x4d7c78){if(!_0x4d7c78){_0x55ec90[_0xace8('0x18')](0x194);}return _0x4d7c78;};}function handleError(_0x59d8e9,_0x1d08e9){_0x1d08e9=_0x1d08e9||0x1f4;return function(_0xe3e83b){logger['error'](_0xe3e83b[_0xace8('0x27')]);if(_0xe3e83b[_0xace8('0x28')]){delete _0xe3e83b[_0xace8('0x28')];}_0x59d8e9[_0xace8('0x19')](_0x1d08e9)[_0xace8('0x29')](_0xe3e83b);};}exports[_0xace8('0x2a')]=function(_0x5095c8,_0x39a911){var _0x24d012={},_0x16dff8={},_0x3fbba6={'count':0x0,'rows':[]};var _0x4f46fc=_[_0xace8('0x2b')](db[_0xace8('0x2c')][_0xace8('0x2d')],function(_0xec040d){return{'name':_0xec040d[_0xace8('0x2e')],'type':_0xec040d[_0xace8('0x2f')][_0xace8('0x30')]};});_0x16dff8[_0xace8('0x31')]=_[_0xace8('0x2b')](_0x4f46fc,_0xace8('0x28'));_0x16dff8[_0xace8('0x32')]=_[_0xace8('0x33')](_0x5095c8[_0xace8('0x32')]);_0x16dff8[_0xace8('0x34')]=_[_0xace8('0x35')](_0x16dff8['model'],_0x16dff8['query']);_0x24d012[_0xace8('0x36')]=_[_0xace8('0x35')](_0x16dff8['model'],qs[_0xace8('0x37')](_0x5095c8[_0xace8('0x32')][_0xace8('0x37')]));_0x24d012[_0xace8('0x36')]=_0x24d012['attributes']['length']?_0x24d012['attributes']:_0x16dff8[_0xace8('0x31')];if(!_0x5095c8[_0xace8('0x32')][_0xace8('0x38')](_0xace8('0x39'))){_0x24d012[_0xace8('0x1e')]=qs[_0xace8('0x1e')](_0x5095c8[_0xace8('0x32')]['limit']);_0x24d012['offset']=qs[_0xace8('0x1c')](_0x5095c8[_0xace8('0x32')][_0xace8('0x1c')]);}_0x24d012[_0xace8('0x3a')]=qs[_0xace8('0x3b')](_0x5095c8[_0xace8('0x32')][_0xace8('0x3b')]);_0x24d012[_0xace8('0x3c')]=qs['filters'](_['pick'](_0x5095c8[_0xace8('0x32')],_0x16dff8[_0xace8('0x34')]),_0x4f46fc);if(_0x5095c8[_0xace8('0x32')][_0xace8('0x3d')]){_0x24d012['where']=_[_0xace8('0x3e')](_0x24d012[_0xace8('0x3c')],{'$or':_['map'](_0x4f46fc,function(_0x3bb65d){if(_0x3bb65d[_0xace8('0x2f')]!==_0xace8('0x3f')){var _0x55a2e4={};_0x55a2e4[_0x3bb65d[_0xace8('0x28')]]={'$like':'%'+_0x5095c8[_0xace8('0x32')][_0xace8('0x3d')]+'%'};return _0x55a2e4;}})});}_0x24d012=_[_0xace8('0x3e')]({},_0x24d012,_0x5095c8[_0xace8('0x40')]);var _0x4630bf={'where':_0x24d012[_0xace8('0x3c')]};return db[_0xace8('0x2c')][_0xace8('0x1f')](_0x4630bf)[_0xace8('0x25')](function(_0x51bb68){_0x3fbba6[_0xace8('0x1f')]=_0x51bb68;if(_0x5095c8[_0xace8('0x32')][_0xace8('0x41')]){_0x24d012[_0xace8('0x42')]=[{'all':!![]}];}return db[_0xace8('0x2c')][_0xace8('0x43')](_0x24d012);})[_0xace8('0x25')](function(_0x474922){_0x3fbba6[_0xace8('0x44')]=_0x474922;return _0x3fbba6;})['then'](respondWithFilteredResult(_0x39a911,_0x24d012))[_0xace8('0x45')](handleError(_0x39a911,null));};exports[_0xace8('0x46')]=function(_0x3f0bc4,_0x5d75eb){var _0x4b3e86={'raw':!![],'where':{'id':_0x3f0bc4['params']['id']}},_0x370532={};_0x370532['model']=_[_0xace8('0x33')](db[_0xace8('0x2c')][_0xace8('0x2d')]);_0x370532['query']=_[_0xace8('0x33')](_0x3f0bc4[_0xace8('0x32')]);_0x370532['filters']=_[_0xace8('0x35')](_0x370532[_0xace8('0x31')],_0x370532[_0xace8('0x32')]);_0x4b3e86[_0xace8('0x36')]=_['intersection'](_0x370532[_0xace8('0x31')],qs[_0xace8('0x37')](_0x3f0bc4[_0xace8('0x32')][_0xace8('0x37')]));_0x4b3e86[_0xace8('0x36')]=_0x4b3e86[_0xace8('0x36')][_0xace8('0x47')]?_0x4b3e86['attributes']:_0x370532[_0xace8('0x31')];if(_0x3f0bc4['query']['includeAll']){_0x4b3e86[_0xace8('0x42')]=[{'all':!![]}];}_0x4b3e86=_[_0xace8('0x3e')]({},_0x4b3e86,_0x3f0bc4['options']);return db[_0xace8('0x2c')][_0xace8('0x48')](_0x4b3e86)['then'](handleEntityNotFound(_0x5d75eb,null))[_0xace8('0x25')](respondWithResult(_0x5d75eb,null))[_0xace8('0x45')](handleError(_0x5d75eb,null));};exports[_0xace8('0x49')]=function(_0x50432c,_0x5b91d1){return db[_0xace8('0x2c')][_0xace8('0x49')](_0x50432c[_0xace8('0x4a')],{})[_0xace8('0x25')](respondWithResult(_0x5b91d1,0xc9))['catch'](handleError(_0x5b91d1,null));};exports[_0xace8('0x24')]=function(_0x1c5833,_0x34ab11){if(_0x1c5833[_0xace8('0x4a')]['id']){delete _0x1c5833[_0xace8('0x4a')]['id'];}return db['SquareReport']['find']({'where':{'id':_0x1c5833[_0xace8('0x4b')]['id']}})['then'](handleEntityNotFound(_0x34ab11,null))[_0xace8('0x25')](saveUpdates(_0x1c5833[_0xace8('0x4a')],null))[_0xace8('0x25')](respondWithResult(_0x34ab11,null))[_0xace8('0x45')](handleError(_0x34ab11,null));};exports[_0xace8('0x26')]=function(_0x3f50ec,_0x48ed3e){return db['SquareReport'][_0xace8('0x48')]({'where':{'id':_0x3f50ec['params']['id']}})[_0xace8('0x25')](handleEntityNotFound(_0x48ed3e,null))[_0xace8('0x25')](removeEntity(_0x48ed3e,null))[_0xace8('0x45')](handleError(_0x48ed3e,null));};exports[_0xace8('0x4c')]=function(_0x4a217a,_0x9c9993){return db[_0xace8('0x2c')][_0xace8('0x4c')]()[_0xace8('0x25')](respondWithResult(_0x9c9993,null))[_0xace8('0x45')](handleError(_0x9c9993,null));};