7f682516c5e2bc08507f8ceef140948f0e7f3d1e
[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 _0x7f05=['fields','hasOwnProperty','nolimit','order','sort','where','pick','merge','filter','options','SquareReport','include','findAll','show','params','keys','intersection','length','includeAll','find','catch','create','body','destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/license/util','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','filters','attributes'];(function(_0x42b21d,_0x58a3e7){var _0x590a15=function(_0x19b771){while(--_0x19b771){_0x42b21d['push'](_0x42b21d['shift']());}};_0x590a15(++_0x58a3e7);}(_0x7f05,0x195));var _0x57f0=function(_0x433fd4,_0x2f5fbc){_0x433fd4=_0x433fd4-0x0;var _0x2c5bcf=_0x7f05[_0x433fd4];return _0x2c5bcf;};'use strict';var emlformat=require(_0x57f0('0x0'));var rimraf=require(_0x57f0('0x1'));var zipdir=require(_0x57f0('0x2'));var jsonpatch=require(_0x57f0('0x3'));var rp=require('request-promise');var moment=require(_0x57f0('0x4'));var BPromise=require(_0x57f0('0x5'));var Mustache=require(_0x57f0('0x6'));var util=require(_0x57f0('0x7'));var path=require(_0x57f0('0x8'));var sox=require(_0x57f0('0x9'));var csv=require(_0x57f0('0xa'));var ejs=require(_0x57f0('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x57f0('0xc'));var squel=require(_0x57f0('0xd'));var crypto=require('crypto');var jsforce=require(_0x57f0('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x57f0('0xa'));var querystring=require(_0x57f0('0xf'));var Papa=require(_0x57f0('0x10'));var Redis=require(_0x57f0('0x11'));var authService=require(_0x57f0('0x12'));var qs=require(_0x57f0('0x13'));var as=require(_0x57f0('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x57f0('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x57f0('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x11d889,_0x3cd14e){_0x3cd14e=_0x3cd14e||0xcc;return function(_0x20f5a1){if(_0x20f5a1){return _0x11d889['sendStatus'](_0x3cd14e);}return _0x11d889[_0x57f0('0x17')](_0x3cd14e)[_0x57f0('0x18')]();};}function respondWithResult(_0x498809,_0x42de45){_0x42de45=_0x42de45||0xc8;return function(_0xb5aba3){if(_0xb5aba3){return _0x498809[_0x57f0('0x17')](_0x42de45)['json'](_0xb5aba3);}};}function respondWithFilteredResult(_0x58b506,_0x52da1a){return function(_0x12718c){if(_0x12718c){var _0x21c8c4=typeof _0x52da1a[_0x57f0('0x19')]===_0x57f0('0x1a')&&typeof _0x52da1a[_0x57f0('0x1b')]===_0x57f0('0x1a');var _0x5d5a48=_0x12718c['count'];var _0x1e35af=_0x21c8c4?0x0:_0x52da1a[_0x57f0('0x19')];var _0x31d9da=_0x21c8c4?_0x12718c[_0x57f0('0x1c')]:_0x52da1a[_0x57f0('0x19')]+_0x52da1a['limit'];var _0x1514b8;if(_0x31d9da>=_0x5d5a48){_0x31d9da=_0x5d5a48;_0x1514b8=0xc8;}else{_0x1514b8=0xce;}_0x58b506['status'](_0x1514b8);return _0x58b506[_0x57f0('0x1d')](_0x57f0('0x1e'),_0x1e35af+'-'+_0x31d9da+'/'+_0x5d5a48)[_0x57f0('0x1f')](_0x12718c);}return null;};}function patchUpdates(_0x2aaf58){return function(_0x4df273){try{jsonpatch[_0x57f0('0x20')](_0x4df273,_0x2aaf58,!![]);}catch(_0x47a97c){return BPromise[_0x57f0('0x21')](_0x47a97c);}return _0x4df273[_0x57f0('0x22')]();};}function saveUpdates(_0x5d64f3,_0x4e390d){return function(_0x4cb52f){if(_0x4cb52f){return _0x4cb52f[_0x57f0('0x23')](_0x5d64f3)[_0x57f0('0x24')](function(_0x562f94){return _0x562f94;});}return null;};}function removeEntity(_0x4c5796,_0x5dc13f){return function(_0x18aeef){if(_0x18aeef){return _0x18aeef['destroy']()[_0x57f0('0x24')](function(){_0x4c5796[_0x57f0('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4010a9,_0x428a2b){return function(_0x2b98b6){if(!_0x2b98b6){_0x4010a9['sendStatus'](0x194);}return _0x2b98b6;};}function handleError(_0x1e0921,_0x49d446){_0x49d446=_0x49d446||0x1f4;return function(_0x520685){logger[_0x57f0('0x25')](_0x520685[_0x57f0('0x26')]);if(_0x520685[_0x57f0('0x27')]){delete _0x520685[_0x57f0('0x27')];}_0x1e0921[_0x57f0('0x17')](_0x49d446)[_0x57f0('0x28')](_0x520685);};}exports[_0x57f0('0x29')]=function(_0x50154d,_0x3a3ca1){var _0x3d81b1={},_0x4ff101={},_0x1eae7a={'count':0x0,'rows':[]};var _0x30f4f7=_[_0x57f0('0x2a')](db['SquareReport'][_0x57f0('0x2b')],function(_0x348fcd){return{'name':_0x348fcd[_0x57f0('0x2c')],'type':_0x348fcd[_0x57f0('0x2d')][_0x57f0('0x2e')]};});_0x4ff101[_0x57f0('0x2f')]=_['map'](_0x30f4f7,_0x57f0('0x27'));_0x4ff101[_0x57f0('0x30')]=_['keys'](_0x50154d['query']);_0x4ff101[_0x57f0('0x31')]=_['intersection'](_0x4ff101[_0x57f0('0x2f')],_0x4ff101['query']);_0x3d81b1[_0x57f0('0x32')]=_['intersection'](_0x4ff101[_0x57f0('0x2f')],qs[_0x57f0('0x33')](_0x50154d[_0x57f0('0x30')]['fields']));_0x3d81b1[_0x57f0('0x32')]=_0x3d81b1['attributes']['length']?_0x3d81b1[_0x57f0('0x32')]:_0x4ff101[_0x57f0('0x2f')];if(!_0x50154d[_0x57f0('0x30')][_0x57f0('0x34')](_0x57f0('0x35'))){_0x3d81b1[_0x57f0('0x1b')]=qs[_0x57f0('0x1b')](_0x50154d['query'][_0x57f0('0x1b')]);_0x3d81b1['offset']=qs[_0x57f0('0x19')](_0x50154d[_0x57f0('0x30')][_0x57f0('0x19')]);}_0x3d81b1[_0x57f0('0x36')]=qs[_0x57f0('0x37')](_0x50154d['query'][_0x57f0('0x37')]);_0x3d81b1[_0x57f0('0x38')]=qs['filters'](_[_0x57f0('0x39')](_0x50154d[_0x57f0('0x30')],_0x4ff101[_0x57f0('0x31')]),_0x30f4f7);if(_0x50154d[_0x57f0('0x30')]['filter']){_0x3d81b1['where']=_[_0x57f0('0x3a')](_0x3d81b1[_0x57f0('0x38')],{'$or':_[_0x57f0('0x2a')](_0x30f4f7,function(_0x9f08ef){if(_0x9f08ef[_0x57f0('0x2d')]!=='VIRTUAL'){var _0x589848={};_0x589848[_0x9f08ef[_0x57f0('0x27')]]={'$like':'%'+_0x50154d[_0x57f0('0x30')][_0x57f0('0x3b')]+'%'};return _0x589848;}})});}_0x3d81b1=_[_0x57f0('0x3a')]({},_0x3d81b1,_0x50154d[_0x57f0('0x3c')]);var _0xf1bcaa={'where':_0x3d81b1[_0x57f0('0x38')]};return db[_0x57f0('0x3d')][_0x57f0('0x1c')](_0xf1bcaa)[_0x57f0('0x24')](function(_0x59bf21){_0x1eae7a[_0x57f0('0x1c')]=_0x59bf21;if(_0x50154d['query']['includeAll']){_0x3d81b1[_0x57f0('0x3e')]=[{'all':!![]}];}return db['SquareReport'][_0x57f0('0x3f')](_0x3d81b1);})['then'](function(_0xe32cc1){_0x1eae7a['rows']=_0xe32cc1;return _0x1eae7a;})[_0x57f0('0x24')](respondWithFilteredResult(_0x3a3ca1,_0x3d81b1))['catch'](handleError(_0x3a3ca1,null));};exports[_0x57f0('0x40')]=function(_0x4e2ad8,_0x5266f5){var _0x2f08e2={'raw':!![],'where':{'id':_0x4e2ad8[_0x57f0('0x41')]['id']}},_0x2884a2={};_0x2884a2[_0x57f0('0x2f')]=_[_0x57f0('0x42')](db[_0x57f0('0x3d')][_0x57f0('0x2b')]);_0x2884a2[_0x57f0('0x30')]=_['keys'](_0x4e2ad8[_0x57f0('0x30')]);_0x2884a2['filters']=_[_0x57f0('0x43')](_0x2884a2[_0x57f0('0x2f')],_0x2884a2[_0x57f0('0x30')]);_0x2f08e2['attributes']=_[_0x57f0('0x43')](_0x2884a2[_0x57f0('0x2f')],qs[_0x57f0('0x33')](_0x4e2ad8[_0x57f0('0x30')][_0x57f0('0x33')]));_0x2f08e2[_0x57f0('0x32')]=_0x2f08e2[_0x57f0('0x32')][_0x57f0('0x44')]?_0x2f08e2[_0x57f0('0x32')]:_0x2884a2[_0x57f0('0x2f')];if(_0x4e2ad8[_0x57f0('0x30')][_0x57f0('0x45')]){_0x2f08e2[_0x57f0('0x3e')]=[{'all':!![]}];}_0x2f08e2=_['merge']({},_0x2f08e2,_0x4e2ad8[_0x57f0('0x3c')]);return db[_0x57f0('0x3d')][_0x57f0('0x46')](_0x2f08e2)['then'](handleEntityNotFound(_0x5266f5,null))[_0x57f0('0x24')](respondWithResult(_0x5266f5,null))[_0x57f0('0x47')](handleError(_0x5266f5,null));};exports['create']=function(_0x54ab1d,_0x841b75){return db[_0x57f0('0x3d')][_0x57f0('0x48')](_0x54ab1d[_0x57f0('0x49')],{})['then'](respondWithResult(_0x841b75,0xc9))['catch'](handleError(_0x841b75,null));};exports[_0x57f0('0x23')]=function(_0x3e6935,_0x2d84a0){if(_0x3e6935[_0x57f0('0x49')]['id']){delete _0x3e6935[_0x57f0('0x49')]['id'];}return db['SquareReport'][_0x57f0('0x46')]({'where':{'id':_0x3e6935[_0x57f0('0x41')]['id']}})[_0x57f0('0x24')](handleEntityNotFound(_0x2d84a0,null))['then'](saveUpdates(_0x3e6935[_0x57f0('0x49')],null))[_0x57f0('0x24')](respondWithResult(_0x2d84a0,null))[_0x57f0('0x47')](handleError(_0x2d84a0,null));};exports[_0x57f0('0x4a')]=function(_0x15ed93,_0xf2763b){return db[_0x57f0('0x3d')][_0x57f0('0x46')]({'where':{'id':_0x15ed93[_0x57f0('0x41')]['id']}})[_0x57f0('0x24')](handleEntityNotFound(_0xf2763b,null))[_0x57f0('0x24')](removeEntity(_0xf2763b,null))[_0x57f0('0x47')](handleError(_0xf2763b,null));};exports['describe']=function(_0x2eaef8,_0x4d1435){return db[_0x57f0('0x3d')][_0x57f0('0x4b')]()['then'](respondWithResult(_0x4d1435,null))[_0x57f0('0x47')](handleError(_0x4d1435,null));};