ae0b2de31be1992750f3fa07a776cdd1c6633162
[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 _0xafc6=['fast-json-patch','moment','bluebird','util','sox','to-csv','ejs','lodash','squel','crypto','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','sendStatus','status','end','json','count','offset','set','apply','reject','save','update','then','destroy','error','name','send','map','SquareReport','fieldName','type','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','limit','sort','where','pick','filters','filter','merge','include','findAll','rows','catch','show','params','includeAll','find','create','body','describe','eml-format','rimraf','zip-dir'];(function(_0x3fd1a6,_0x42b7eb){var _0x228b71=function(_0x20cfe1){while(--_0x20cfe1){_0x3fd1a6['push'](_0x3fd1a6['shift']());}};_0x228b71(++_0x42b7eb);}(_0xafc6,0xc0));var _0x6afc=function(_0x5627e1,_0x1b2dbf){_0x5627e1=_0x5627e1-0x0;var _0x2f013f=_0xafc6[_0x5627e1];return _0x2f013f;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x6afc('0x0'));var rimraf=require(_0x6afc('0x1'));var zipdir=require(_0x6afc('0x2'));var jsonpatch=require(_0x6afc('0x3'));var rp=require('request-promise');var moment=require(_0x6afc('0x4'));var BPromise=require(_0x6afc('0x5'));var Mustache=require('mustache');var util=require(_0x6afc('0x6'));var path=require('path');var sox=require(_0x6afc('0x7'));var csv=require(_0x6afc('0x8'));var ejs=require(_0x6afc('0x9'));var fs=require('fs');var _=require(_0x6afc('0xa'));var squel=require(_0x6afc('0xb'));var crypto=require(_0x6afc('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x6afc('0x8'));var querystring=require('querystring');var Papa=require(_0x6afc('0xd'));var Redis=require('ioredis');var authService=require(_0x6afc('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x6afc('0xf'));var hardwareService=require(_0x6afc('0x10'));var logger=require(_0x6afc('0x11'))('api');var utils=require(_0x6afc('0x12'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x592f0f,_0x4b39b6){_0x4b39b6=_0x4b39b6||0xcc;return function(_0x28d0af){if(_0x28d0af){return _0x592f0f[_0x6afc('0x13')](_0x4b39b6);}return _0x592f0f[_0x6afc('0x14')](_0x4b39b6)[_0x6afc('0x15')]();};}function respondWithResult(_0x1d78ee,_0x5bf3c1){_0x5bf3c1=_0x5bf3c1||0xc8;return function(_0x5cce3f){if(_0x5cce3f){return _0x1d78ee[_0x6afc('0x14')](_0x5bf3c1)[_0x6afc('0x16')](_0x5cce3f);}};}function respondWithFilteredResult(_0x329314,_0x324563){return function(_0x1f2d8f){if(_0x1f2d8f){var _0x29ea89=_0x1f2d8f[_0x6afc('0x17')],_0x4b76cf=_0x324563['offset'],_0x5a518d=_0x324563[_0x6afc('0x18')]+_0x324563['limit'],_0x46504b;if(_0x5a518d>=_0x29ea89){_0x5a518d=_0x29ea89;_0x46504b=0xc8;}else{_0x46504b=0xce;}_0x329314['status'](_0x46504b);return _0x329314[_0x6afc('0x19')]('Content-Range',_0x4b76cf+'-'+_0x5a518d+'/'+_0x29ea89)[_0x6afc('0x16')](_0x1f2d8f);}return null;};}function patchUpdates(_0xd41328){return function(_0x11dbe9){try{jsonpatch[_0x6afc('0x1a')](_0x11dbe9,_0xd41328,!![]);}catch(_0x468feb){return BPromise[_0x6afc('0x1b')](_0x468feb);}return _0x11dbe9[_0x6afc('0x1c')]();};}function saveUpdates(_0x490ed3,_0x32ae9f){return function(_0x3e7b47){if(_0x3e7b47){return _0x3e7b47[_0x6afc('0x1d')](_0x490ed3)[_0x6afc('0x1e')](function(_0x42cac6){return _0x42cac6;});}return null;};}function removeEntity(_0x37c17b,_0x16e2c6){return function(_0x5561a9){if(_0x5561a9){return _0x5561a9[_0x6afc('0x1f')]()[_0x6afc('0x1e')](function(){_0x37c17b[_0x6afc('0x14')](0xcc)[_0x6afc('0x15')]();});}};}function handleEntityNotFound(_0x33b054,_0x58269b){return function(_0x3bd3b6){if(!_0x3bd3b6){_0x33b054['sendStatus'](0x194);}return _0x3bd3b6;};}function handleError(_0x3444b9,_0x115c7a){_0x115c7a=_0x115c7a||0x1f4;return function(_0x238492){logger[_0x6afc('0x20')](_0x238492['stack']);if(_0x238492[_0x6afc('0x21')]){delete _0x238492[_0x6afc('0x21')];}_0x3444b9[_0x6afc('0x14')](_0x115c7a)[_0x6afc('0x22')](_0x238492);};}exports['index']=function(_0x30d75a,_0x38c8a7){var _0x481210={},_0x4cd231={},_0x1b3af7={'count':0x0,'rows':[]};var _0x18a663=_[_0x6afc('0x23')](db[_0x6afc('0x24')]['rawAttributes'],function(_0x339313){return{'name':_0x339313[_0x6afc('0x25')],'type':_0x339313[_0x6afc('0x26')]['key']};});_0x4cd231['model']=_[_0x6afc('0x23')](_0x18a663,'name');_0x4cd231[_0x6afc('0x27')]=_[_0x6afc('0x28')](_0x30d75a[_0x6afc('0x27')]);_0x4cd231['filters']=_[_0x6afc('0x29')](_0x4cd231[_0x6afc('0x2a')],_0x4cd231[_0x6afc('0x27')]);_0x481210[_0x6afc('0x2b')]=_[_0x6afc('0x29')](_0x4cd231[_0x6afc('0x2a')],qs[_0x6afc('0x2c')](_0x30d75a[_0x6afc('0x27')]['fields']));_0x481210['attributes']=_0x481210['attributes'][_0x6afc('0x2d')]?_0x481210[_0x6afc('0x2b')]:_0x4cd231[_0x6afc('0x2a')];if(!_0x30d75a['query'][_0x6afc('0x2e')]('nolimit')){_0x481210[_0x6afc('0x2f')]=qs[_0x6afc('0x2f')](_0x30d75a[_0x6afc('0x27')][_0x6afc('0x2f')]);_0x481210[_0x6afc('0x18')]=qs['offset'](_0x30d75a[_0x6afc('0x27')]['offset']);}_0x481210['order']=qs[_0x6afc('0x30')](_0x30d75a[_0x6afc('0x27')]['sort']);_0x481210[_0x6afc('0x31')]=qs['filters'](_[_0x6afc('0x32')](_0x30d75a[_0x6afc('0x27')],_0x4cd231[_0x6afc('0x33')]),_0x18a663);if(_0x30d75a['query'][_0x6afc('0x34')]){_0x481210[_0x6afc('0x31')]=_[_0x6afc('0x35')](_0x481210[_0x6afc('0x31')],{'$or':_[_0x6afc('0x23')](_0x18a663,function(_0x535f56){if(_0x535f56[_0x6afc('0x26')]!=='VIRTUAL'){var _0x138d25={};_0x138d25[_0x535f56['name']]={'$like':'%'+_0x30d75a[_0x6afc('0x27')]['filter']+'%'};return _0x138d25;}})});}_0x481210=_['merge']({},_0x481210,_0x30d75a['options']);var _0x232f09={'where':_0x481210[_0x6afc('0x31')]};return db[_0x6afc('0x24')]['count'](_0x232f09)[_0x6afc('0x1e')](function(_0x3b1be2){_0x1b3af7[_0x6afc('0x17')]=_0x3b1be2;if(_0x30d75a[_0x6afc('0x27')]['includeAll']){_0x481210[_0x6afc('0x36')]=[{'all':!![]}];}return db[_0x6afc('0x24')][_0x6afc('0x37')](_0x481210);})['then'](function(_0x13f0fe){_0x1b3af7[_0x6afc('0x38')]=_0x13f0fe;return _0x1b3af7;})['then'](respondWithFilteredResult(_0x38c8a7,_0x481210))[_0x6afc('0x39')](handleError(_0x38c8a7,null));};exports[_0x6afc('0x3a')]=function(_0x2108a8,_0x5b71dc){var _0x35e619={'raw':!![],'where':{'id':_0x2108a8[_0x6afc('0x3b')]['id']}},_0x4bbd62={};_0x4bbd62[_0x6afc('0x2a')]=_[_0x6afc('0x28')](db[_0x6afc('0x24')]['rawAttributes']);_0x4bbd62[_0x6afc('0x27')]=_[_0x6afc('0x28')](_0x2108a8['query']);_0x4bbd62[_0x6afc('0x33')]=_[_0x6afc('0x29')](_0x4bbd62[_0x6afc('0x2a')],_0x4bbd62[_0x6afc('0x27')]);_0x35e619['attributes']=_[_0x6afc('0x29')](_0x4bbd62[_0x6afc('0x2a')],qs[_0x6afc('0x2c')](_0x2108a8['query'][_0x6afc('0x2c')]));_0x35e619[_0x6afc('0x2b')]=_0x35e619[_0x6afc('0x2b')][_0x6afc('0x2d')]?_0x35e619[_0x6afc('0x2b')]:_0x4bbd62[_0x6afc('0x2a')];if(_0x2108a8[_0x6afc('0x27')][_0x6afc('0x3c')]){_0x35e619[_0x6afc('0x36')]=[{'all':!![]}];}_0x35e619=_[_0x6afc('0x35')]({},_0x35e619,_0x2108a8['options']);return db[_0x6afc('0x24')][_0x6afc('0x3d')](_0x35e619)[_0x6afc('0x1e')](handleEntityNotFound(_0x5b71dc,null))[_0x6afc('0x1e')](respondWithResult(_0x5b71dc,null))[_0x6afc('0x39')](handleError(_0x5b71dc,null));};exports[_0x6afc('0x3e')]=function(_0xca0c94,_0x4fd952){return db[_0x6afc('0x24')][_0x6afc('0x3e')](_0xca0c94[_0x6afc('0x3f')],{})[_0x6afc('0x1e')](respondWithResult(_0x4fd952,0xc9))[_0x6afc('0x39')](handleError(_0x4fd952,null));};exports[_0x6afc('0x1d')]=function(_0x4c90f4,_0x540863){if(_0x4c90f4[_0x6afc('0x3f')]['id']){delete _0x4c90f4[_0x6afc('0x3f')]['id'];}return db[_0x6afc('0x24')][_0x6afc('0x3d')]({'where':{'id':_0x4c90f4[_0x6afc('0x3b')]['id']}})[_0x6afc('0x1e')](handleEntityNotFound(_0x540863,null))[_0x6afc('0x1e')](saveUpdates(_0x4c90f4[_0x6afc('0x3f')],null))[_0x6afc('0x1e')](respondWithResult(_0x540863,null))['catch'](handleError(_0x540863,null));};exports[_0x6afc('0x1f')]=function(_0x3c9008,_0x18b7c9){return db['SquareReport'][_0x6afc('0x3d')]({'where':{'id':_0x3c9008[_0x6afc('0x3b')]['id']}})[_0x6afc('0x1e')](handleEntityNotFound(_0x18b7c9,null))[_0x6afc('0x1e')](removeEntity(_0x18b7c9,null))[_0x6afc('0x39')](handleError(_0x18b7c9,null));};exports[_0x6afc('0x40')]=function(_0x307410,_0x50d8dd){return db[_0x6afc('0x24')][_0x6afc('0x40')]()[_0x6afc('0x1e')](respondWithResult(_0x50d8dd,null))[_0x6afc('0x39')](handleError(_0x50d8dd,null));};