e7b0e607ecbb6eae4a5146489c173b5e9f49bc15
[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 _0x3c4b=['where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','fields','find','create','body','params','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','then','destroy','error','stack','send','SquareReport','rawAttributes','type','map','name','query','keys','filters','intersection','model','attributes','length','hasOwnProperty','nolimit','order','sort'];(function(_0x46451c,_0x88ddd){var _0x12dce4=function(_0x2e4087){while(--_0x2e4087){_0x46451c['push'](_0x46451c['shift']());}};_0x12dce4(++_0x88ddd);}(_0x3c4b,0xa0));var _0xb3c4=function(_0x297c6a,_0x1fca7a){_0x297c6a=_0x297c6a-0x0;var _0x4820ff=_0x3c4b[_0x297c6a];return _0x4820ff;};'use strict';var emlformat=require(_0xb3c4('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xb3c4('0x1'));var jsonpatch=require(_0xb3c4('0x2'));var rp=require(_0xb3c4('0x3'));var moment=require(_0xb3c4('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xb3c4('0x5'));var util=require(_0xb3c4('0x6'));var path=require(_0xb3c4('0x7'));var sox=require(_0xb3c4('0x8'));var csv=require(_0xb3c4('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xb3c4('0xa'));var crypto=require(_0xb3c4('0xb'));var jsforce=require(_0xb3c4('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xb3c4('0xd'));var Papa=require(_0xb3c4('0xe'));var Redis=require(_0xb3c4('0xf'));var authService=require(_0xb3c4('0x10'));var qs=require(_0xb3c4('0x11'));var as=require(_0xb3c4('0x12'));var hardwareService=require(_0xb3c4('0x13'));var logger=require('../../config/logger')(_0xb3c4('0x14'));var utils=require(_0xb3c4('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3d64ca,_0x26d381){_0x26d381=_0x26d381||0xcc;return function(_0x5e64c1){if(_0x5e64c1){return _0x3d64ca[_0xb3c4('0x16')](_0x26d381);}return _0x3d64ca[_0xb3c4('0x17')](_0x26d381)[_0xb3c4('0x18')]();};}function respondWithResult(_0x269b13,_0x25781f){_0x25781f=_0x25781f||0xc8;return function(_0x2b3e52){if(_0x2b3e52){return _0x269b13[_0xb3c4('0x17')](_0x25781f)[_0xb3c4('0x19')](_0x2b3e52);}};}function respondWithFilteredResult(_0x1c6158,_0x27b1de){return function(_0x4ebcfa){if(_0x4ebcfa){var _0x42e8fe=typeof _0x27b1de[_0xb3c4('0x1a')]==='undefined'&&typeof _0x27b1de[_0xb3c4('0x1b')]===_0xb3c4('0x1c');var _0x5aacad=_0x4ebcfa[_0xb3c4('0x1d')];var _0x596c6e=_0x42e8fe?0x0:_0x27b1de['offset'];var _0x17384c=_0x42e8fe?_0x4ebcfa[_0xb3c4('0x1d')]:_0x27b1de['offset']+_0x27b1de['limit'];var _0x171614;if(_0x17384c>=_0x5aacad){_0x17384c=_0x5aacad;_0x171614=0xc8;}else{_0x171614=0xce;}_0x1c6158[_0xb3c4('0x17')](_0x171614);return _0x1c6158[_0xb3c4('0x1e')](_0xb3c4('0x1f'),_0x596c6e+'-'+_0x17384c+'/'+_0x5aacad)['json'](_0x4ebcfa);}return null;};}function patchUpdates(_0x4f2a97){return function(_0x1cb94b){try{jsonpatch['apply'](_0x1cb94b,_0x4f2a97,!![]);}catch(_0x16dcb5){return BPromise[_0xb3c4('0x20')](_0x16dcb5);}return _0x1cb94b[_0xb3c4('0x21')]();};}function saveUpdates(_0x16d22f,_0x4151b7){return function(_0x53a5c8){if(_0x53a5c8){return _0x53a5c8[_0xb3c4('0x22')](_0x16d22f)[_0xb3c4('0x23')](function(_0x4ea8ad){return _0x4ea8ad;});}return null;};}function removeEntity(_0x519b2f,_0x44c7a3){return function(_0x2a979b){if(_0x2a979b){return _0x2a979b[_0xb3c4('0x24')]()[_0xb3c4('0x23')](function(){_0x519b2f[_0xb3c4('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4684c7,_0x1a23cb){return function(_0x59b972){if(!_0x59b972){_0x4684c7['sendStatus'](0x194);}return _0x59b972;};}function handleError(_0x1f15ea,_0x4bf87c){_0x4bf87c=_0x4bf87c||0x1f4;return function(_0x4bb87b){logger[_0xb3c4('0x25')](_0x4bb87b[_0xb3c4('0x26')]);if(_0x4bb87b['name']){delete _0x4bb87b['name'];}_0x1f15ea[_0xb3c4('0x17')](_0x4bf87c)[_0xb3c4('0x27')](_0x4bb87b);};}exports['index']=function(_0x418478,_0x11e724){var _0x255e66={},_0x36c446={},_0x3ee0a6={'count':0x0,'rows':[]};var _0x109435=_['map'](db[_0xb3c4('0x28')][_0xb3c4('0x29')],function(_0x107cc9){return{'name':_0x107cc9['fieldName'],'type':_0x107cc9[_0xb3c4('0x2a')]['key']};});_0x36c446['model']=_[_0xb3c4('0x2b')](_0x109435,_0xb3c4('0x2c'));_0x36c446[_0xb3c4('0x2d')]=_[_0xb3c4('0x2e')](_0x418478[_0xb3c4('0x2d')]);_0x36c446[_0xb3c4('0x2f')]=_[_0xb3c4('0x30')](_0x36c446[_0xb3c4('0x31')],_0x36c446[_0xb3c4('0x2d')]);_0x255e66['attributes']=_['intersection'](_0x36c446[_0xb3c4('0x31')],qs['fields'](_0x418478[_0xb3c4('0x2d')]['fields']));_0x255e66[_0xb3c4('0x32')]=_0x255e66[_0xb3c4('0x32')][_0xb3c4('0x33')]?_0x255e66['attributes']:_0x36c446['model'];if(!_0x418478['query'][_0xb3c4('0x34')](_0xb3c4('0x35'))){_0x255e66[_0xb3c4('0x1b')]=qs[_0xb3c4('0x1b')](_0x418478['query'][_0xb3c4('0x1b')]);_0x255e66[_0xb3c4('0x1a')]=qs[_0xb3c4('0x1a')](_0x418478[_0xb3c4('0x2d')][_0xb3c4('0x1a')]);}_0x255e66[_0xb3c4('0x36')]=qs[_0xb3c4('0x37')](_0x418478[_0xb3c4('0x2d')][_0xb3c4('0x37')]);_0x255e66[_0xb3c4('0x38')]=qs[_0xb3c4('0x2f')](_['pick'](_0x418478[_0xb3c4('0x2d')],_0x36c446[_0xb3c4('0x2f')]),_0x109435);if(_0x418478[_0xb3c4('0x2d')][_0xb3c4('0x39')]){_0x255e66[_0xb3c4('0x38')]=_[_0xb3c4('0x3a')](_0x255e66['where'],{'$or':_[_0xb3c4('0x2b')](_0x109435,function(_0x14d09f){if(_0x14d09f[_0xb3c4('0x2a')]!==_0xb3c4('0x3b')){var _0x294f23={};_0x294f23[_0x14d09f[_0xb3c4('0x2c')]]={'$like':'%'+_0x418478[_0xb3c4('0x2d')][_0xb3c4('0x39')]+'%'};return _0x294f23;}})});}_0x255e66=_[_0xb3c4('0x3a')]({},_0x255e66,_0x418478[_0xb3c4('0x3c')]);var _0x248371={'where':_0x255e66['where']};return db[_0xb3c4('0x28')][_0xb3c4('0x1d')](_0x248371)['then'](function(_0x3786d7){_0x3ee0a6[_0xb3c4('0x1d')]=_0x3786d7;if(_0x418478[_0xb3c4('0x2d')][_0xb3c4('0x3d')]){_0x255e66[_0xb3c4('0x3e')]=[{'all':!![]}];}return db[_0xb3c4('0x28')][_0xb3c4('0x3f')](_0x255e66);})[_0xb3c4('0x23')](function(_0x50d50b){_0x3ee0a6[_0xb3c4('0x40')]=_0x50d50b;return _0x3ee0a6;})[_0xb3c4('0x23')](respondWithFilteredResult(_0x11e724,_0x255e66))[_0xb3c4('0x41')](handleError(_0x11e724,null));};exports['show']=function(_0xf0a98a,_0x121720){var _0xac5448={'raw':!![],'where':{'id':_0xf0a98a['params']['id']}},_0x1c96e3={};_0x1c96e3[_0xb3c4('0x31')]=_[_0xb3c4('0x2e')](db['SquareReport']['rawAttributes']);_0x1c96e3['query']=_[_0xb3c4('0x2e')](_0xf0a98a[_0xb3c4('0x2d')]);_0x1c96e3[_0xb3c4('0x2f')]=_[_0xb3c4('0x30')](_0x1c96e3['model'],_0x1c96e3['query']);_0xac5448['attributes']=_[_0xb3c4('0x30')](_0x1c96e3['model'],qs[_0xb3c4('0x42')](_0xf0a98a[_0xb3c4('0x2d')][_0xb3c4('0x42')]));_0xac5448['attributes']=_0xac5448[_0xb3c4('0x32')]['length']?_0xac5448[_0xb3c4('0x32')]:_0x1c96e3[_0xb3c4('0x31')];if(_0xf0a98a[_0xb3c4('0x2d')][_0xb3c4('0x3d')]){_0xac5448['include']=[{'all':!![]}];}_0xac5448=_[_0xb3c4('0x3a')]({},_0xac5448,_0xf0a98a[_0xb3c4('0x3c')]);return db[_0xb3c4('0x28')][_0xb3c4('0x43')](_0xac5448)[_0xb3c4('0x23')](handleEntityNotFound(_0x121720,null))['then'](respondWithResult(_0x121720,null))[_0xb3c4('0x41')](handleError(_0x121720,null));};exports[_0xb3c4('0x44')]=function(_0xf4d961,_0x204a8b){return db[_0xb3c4('0x28')]['create'](_0xf4d961[_0xb3c4('0x45')],{})[_0xb3c4('0x23')](respondWithResult(_0x204a8b,0xc9))['catch'](handleError(_0x204a8b,null));};exports[_0xb3c4('0x22')]=function(_0x27f64f,_0x526def){if(_0x27f64f['body']['id']){delete _0x27f64f[_0xb3c4('0x45')]['id'];}return db[_0xb3c4('0x28')]['find']({'where':{'id':_0x27f64f[_0xb3c4('0x46')]['id']}})[_0xb3c4('0x23')](handleEntityNotFound(_0x526def,null))['then'](saveUpdates(_0x27f64f[_0xb3c4('0x45')],null))[_0xb3c4('0x23')](respondWithResult(_0x526def,null))[_0xb3c4('0x41')](handleError(_0x526def,null));};exports['destroy']=function(_0x24411e,_0x4f818f){return db[_0xb3c4('0x28')]['find']({'where':{'id':_0x24411e[_0xb3c4('0x46')]['id']}})[_0xb3c4('0x23')](handleEntityNotFound(_0x4f818f,null))[_0xb3c4('0x23')](removeEntity(_0x4f818f,null))[_0xb3c4('0x41')](handleError(_0x4f818f,null));};exports[_0xb3c4('0x47')]=function(_0x3a2b89,_0x4125d6){return db[_0xb3c4('0x28')]['describe']()[_0xb3c4('0x23')](respondWithResult(_0x4125d6,null))['catch'](handleError(_0x4125d6,null));};