735dc8a6584bb4a6b45fa1b7745fc7ed750cc408
[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 _0xf655=['rawAttributes','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','findAll','rows','catch','params','keys','SquareReport','find','create','body','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','util','sox','ejs','fs-extra','squel','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','end','undefined','count','offset','Content-Range','json','apply','save','update','then','destroy','name','send','index','map'];(function(_0x497a5c,_0x308f8d){var _0x3cda24=function(_0x3eda44){while(--_0x3eda44){_0x497a5c['push'](_0x497a5c['shift']());}};_0x3cda24(++_0x308f8d);}(_0xf655,0x137));var _0x5f65=function(_0x5510f5,_0xfd5f3c){_0x5510f5=_0x5510f5-0x0;var _0x5cabb2=_0xf655[_0x5510f5];return _0x5cabb2;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5f65('0x0'));var zipdir=require(_0x5f65('0x1'));var jsonpatch=require(_0x5f65('0x2'));var rp=require(_0x5f65('0x3'));var moment=require(_0x5f65('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x5f65('0x5'));var path=require('path');var sox=require(_0x5f65('0x6'));var csv=require('to-csv');var ejs=require(_0x5f65('0x7'));var fs=require('fs');var fs_extra=require(_0x5f65('0x8'));var _=require('lodash');var squel=require(_0x5f65('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x5f65('0xa'));var toCsv=require(_0x5f65('0xb'));var querystring=require(_0x5f65('0xc'));var Papa=require(_0x5f65('0xd'));var Redis=require(_0x5f65('0xe'));var authService=require(_0x5f65('0xf'));var qs=require(_0x5f65('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5f65('0x11'));var logger=require(_0x5f65('0x12'))(_0x5f65('0x13'));var utils=require(_0x5f65('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x5f65('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3d39d2,_0x68afd1){_0x68afd1=_0x68afd1||0xcc;return function(_0x221587){if(_0x221587){return _0x3d39d2[_0x5f65('0x16')](_0x68afd1);}return _0x3d39d2[_0x5f65('0x17')](_0x68afd1)[_0x5f65('0x18')]();};}function respondWithResult(_0x52696a,_0x758467){_0x758467=_0x758467||0xc8;return function(_0x2752a3){if(_0x2752a3){return _0x52696a[_0x5f65('0x17')](_0x758467)['json'](_0x2752a3);}};}function respondWithFilteredResult(_0x3ba976,_0x581efa){return function(_0x1bdbe7){if(_0x1bdbe7){var _0x24d77a=typeof _0x581efa['offset']===_0x5f65('0x19')&&typeof _0x581efa['limit']===_0x5f65('0x19');var _0x39ec3d=_0x1bdbe7['count'];var _0x13b9b5=_0x24d77a?0x0:_0x581efa['offset'];var _0x552592=_0x24d77a?_0x1bdbe7[_0x5f65('0x1a')]:_0x581efa[_0x5f65('0x1b')]+_0x581efa['limit'];var _0x8ffed;if(_0x552592>=_0x39ec3d){_0x552592=_0x39ec3d;_0x8ffed=0xc8;}else{_0x8ffed=0xce;}_0x3ba976[_0x5f65('0x17')](_0x8ffed);return _0x3ba976['set'](_0x5f65('0x1c'),_0x13b9b5+'-'+_0x552592+'/'+_0x39ec3d)[_0x5f65('0x1d')](_0x1bdbe7);}return null;};}function patchUpdates(_0x1fb3f4){return function(_0x42ff17){try{jsonpatch[_0x5f65('0x1e')](_0x42ff17,_0x1fb3f4,!![]);}catch(_0x51900f){return BPromise['reject'](_0x51900f);}return _0x42ff17[_0x5f65('0x1f')]();};}function saveUpdates(_0x409287,_0x4584bc){return function(_0x337740){if(_0x337740){return _0x337740[_0x5f65('0x20')](_0x409287)[_0x5f65('0x21')](function(_0x21e3b9){return _0x21e3b9;});}return null;};}function removeEntity(_0x434ad3,_0x46bd0a){return function(_0x405024){if(_0x405024){return _0x405024[_0x5f65('0x22')]()[_0x5f65('0x21')](function(){_0x434ad3[_0x5f65('0x17')](0xcc)[_0x5f65('0x18')]();});}};}function handleEntityNotFound(_0x3eccc7,_0x450b9f){return function(_0x3a3689){if(!_0x3a3689){_0x3eccc7['sendStatus'](0x194);}return _0x3a3689;};}function handleError(_0x1adbea,_0x24e947){_0x24e947=_0x24e947||0x1f4;return function(_0x434f7e){logger['error'](_0x434f7e['stack']);if(_0x434f7e[_0x5f65('0x23')]){delete _0x434f7e[_0x5f65('0x23')];}_0x1adbea['status'](_0x24e947)[_0x5f65('0x24')](_0x434f7e);};}exports[_0x5f65('0x25')]=function(_0x121347,_0x573ddb){var _0x2f3c43={},_0x350fc8={},_0x52ed7a={'count':0x0,'rows':[]};var _0x3eb65f=_[_0x5f65('0x26')](db['SquareReport'][_0x5f65('0x27')],function(_0x2f7866){return{'name':_0x2f7866['fieldName'],'type':_0x2f7866[_0x5f65('0x28')][_0x5f65('0x29')]};});_0x350fc8[_0x5f65('0x2a')]=_[_0x5f65('0x26')](_0x3eb65f,'name');_0x350fc8[_0x5f65('0x2b')]=_['keys'](_0x121347[_0x5f65('0x2b')]);_0x350fc8[_0x5f65('0x2c')]=_[_0x5f65('0x2d')](_0x350fc8[_0x5f65('0x2a')],_0x350fc8['query']);_0x2f3c43[_0x5f65('0x2e')]=_[_0x5f65('0x2d')](_0x350fc8[_0x5f65('0x2a')],qs['fields'](_0x121347[_0x5f65('0x2b')][_0x5f65('0x2f')]));_0x2f3c43['attributes']=_0x2f3c43[_0x5f65('0x2e')][_0x5f65('0x30')]?_0x2f3c43['attributes']:_0x350fc8[_0x5f65('0x2a')];if(!_0x121347[_0x5f65('0x2b')][_0x5f65('0x31')]('nolimit')){_0x2f3c43[_0x5f65('0x32')]=qs['limit'](_0x121347[_0x5f65('0x2b')][_0x5f65('0x32')]);_0x2f3c43[_0x5f65('0x1b')]=qs['offset'](_0x121347['query'][_0x5f65('0x1b')]);}_0x2f3c43[_0x5f65('0x33')]=qs[_0x5f65('0x34')](_0x121347[_0x5f65('0x2b')]['sort']);_0x2f3c43[_0x5f65('0x35')]=qs[_0x5f65('0x2c')](_[_0x5f65('0x36')](_0x121347[_0x5f65('0x2b')],_0x350fc8['filters']),_0x3eb65f);if(_0x121347[_0x5f65('0x2b')][_0x5f65('0x37')]){_0x2f3c43[_0x5f65('0x35')]=_['merge'](_0x2f3c43[_0x5f65('0x35')],{'$or':_[_0x5f65('0x26')](_0x3eb65f,function(_0x53596f){if(_0x53596f[_0x5f65('0x28')]!==_0x5f65('0x38')){var _0x246304={};_0x246304[_0x53596f[_0x5f65('0x23')]]={'$like':'%'+_0x121347[_0x5f65('0x2b')][_0x5f65('0x37')]+'%'};return _0x246304;}})});}_0x2f3c43=_[_0x5f65('0x39')]({},_0x2f3c43,_0x121347[_0x5f65('0x3a')]);var _0x3bb3ea={'where':_0x2f3c43['where']};return db['SquareReport'][_0x5f65('0x1a')](_0x3bb3ea)[_0x5f65('0x21')](function(_0x434eba){_0x52ed7a[_0x5f65('0x1a')]=_0x434eba;if(_0x121347[_0x5f65('0x2b')][_0x5f65('0x3b')]){_0x2f3c43['include']=[{'all':!![]}];}return db['SquareReport'][_0x5f65('0x3c')](_0x2f3c43);})['then'](function(_0x4298b8){_0x52ed7a[_0x5f65('0x3d')]=_0x4298b8;return _0x52ed7a;})[_0x5f65('0x21')](respondWithFilteredResult(_0x573ddb,_0x2f3c43))[_0x5f65('0x3e')](handleError(_0x573ddb,null));};exports['show']=function(_0x42a32b,_0x45c87b){var _0x439728={'raw':!![],'where':{'id':_0x42a32b[_0x5f65('0x3f')]['id']}},_0x1565f3={};_0x1565f3['model']=_[_0x5f65('0x40')](db[_0x5f65('0x41')]['rawAttributes']);_0x1565f3['query']=_[_0x5f65('0x40')](_0x42a32b[_0x5f65('0x2b')]);_0x1565f3['filters']=_['intersection'](_0x1565f3[_0x5f65('0x2a')],_0x1565f3[_0x5f65('0x2b')]);_0x439728[_0x5f65('0x2e')]=_[_0x5f65('0x2d')](_0x1565f3[_0x5f65('0x2a')],qs[_0x5f65('0x2f')](_0x42a32b[_0x5f65('0x2b')][_0x5f65('0x2f')]));_0x439728['attributes']=_0x439728[_0x5f65('0x2e')][_0x5f65('0x30')]?_0x439728[_0x5f65('0x2e')]:_0x1565f3[_0x5f65('0x2a')];if(_0x42a32b[_0x5f65('0x2b')]['includeAll']){_0x439728['include']=[{'all':!![]}];}_0x439728=_[_0x5f65('0x39')]({},_0x439728,_0x42a32b[_0x5f65('0x3a')]);return db[_0x5f65('0x41')][_0x5f65('0x42')](_0x439728)[_0x5f65('0x21')](handleEntityNotFound(_0x45c87b,null))[_0x5f65('0x21')](respondWithResult(_0x45c87b,null))[_0x5f65('0x3e')](handleError(_0x45c87b,null));};exports['create']=function(_0x23b75d,_0x4405ca){return db[_0x5f65('0x41')][_0x5f65('0x43')](_0x23b75d[_0x5f65('0x44')],{})['then'](respondWithResult(_0x4405ca,0xc9))[_0x5f65('0x3e')](handleError(_0x4405ca,null));};exports[_0x5f65('0x20')]=function(_0x365ea9,_0xa4a07b){if(_0x365ea9[_0x5f65('0x44')]['id']){delete _0x365ea9[_0x5f65('0x44')]['id'];}return db['SquareReport'][_0x5f65('0x42')]({'where':{'id':_0x365ea9[_0x5f65('0x3f')]['id']}})[_0x5f65('0x21')](handleEntityNotFound(_0xa4a07b,null))[_0x5f65('0x21')](saveUpdates(_0x365ea9['body'],null))[_0x5f65('0x21')](respondWithResult(_0xa4a07b,null))[_0x5f65('0x3e')](handleError(_0xa4a07b,null));};exports['destroy']=function(_0x4cb555,_0x5f2151){return db[_0x5f65('0x41')][_0x5f65('0x42')]({'where':{'id':_0x4cb555[_0x5f65('0x3f')]['id']}})[_0x5f65('0x21')](handleEntityNotFound(_0x5f2151,null))[_0x5f65('0x21')](removeEntity(_0x5f2151,null))[_0x5f65('0x3e')](handleError(_0x5f2151,null));};exports[_0x5f65('0x45')]=function(_0x30f6e,_0x7de102){return db[_0x5f65('0x41')][_0x5f65('0x45')]()[_0x5f65('0x21')](respondWithResult(_0x7de102,null))[_0x5f65('0x3e')](handleError(_0x7de102,null));};