Built motion from commit (unavailable).|2.5.23
[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 _0xdbb1=['status','json','offset','limit','set','Content-Range','reject','save','update','then','destroy','end','stack','name','send','index','map','SquareReport','fieldName','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','filter','type','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','merge','find','create','body','describe','html-pdf','fast-json-patch','bluebird','util','path','ejs','lodash','squel','crypto','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus'];(function(_0x592af3,_0x1f05db){var _0x2f0878=function(_0x570284){while(--_0x570284){_0x592af3['push'](_0x592af3['shift']());}};_0x2f0878(++_0x1f05db);}(_0xdbb1,0x105));var _0x1dbb=function(_0x474bc0,_0x26989c){_0x474bc0=_0x474bc0-0x0;var _0x4b24cf=_0xdbb1[_0x474bc0];return _0x4b24cf;};'use strict';var pdf=require(_0x1dbb('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x1dbb('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x1dbb('0x2'));var Mustache=require('mustache');var util=require(_0x1dbb('0x3'));var path=require(_0x1dbb('0x4'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x1dbb('0x5'));var fs=require('fs');var _=require(_0x1dbb('0x6'));var squel=require(_0x1dbb('0x7'));var crypto=require(_0x1dbb('0x8'));var jsforce=require('jsforce');var deskjs=require(_0x1dbb('0x9'));var toCsv=require(_0x1dbb('0xa'));var querystring=require('querystring');var Papa=require(_0x1dbb('0xb'));var Redis=require(_0x1dbb('0xc'));var authService=require(_0x1dbb('0xd'));var qs=require(_0x1dbb('0xe'));var as=require(_0x1dbb('0xf'));var hardwareService=require(_0x1dbb('0x10'));var logger=require(_0x1dbb('0x11'))(_0x1dbb('0x12'));var utils=require(_0x1dbb('0x13'));var config=require(_0x1dbb('0x14'));var licenseUtil=require(_0x1dbb('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x425fef,_0x28c292){_0x28c292=_0x28c292||0xcc;return function(_0x332380){if(_0x332380){return _0x425fef[_0x1dbb('0x16')](_0x28c292);}return _0x425fef['status'](_0x28c292)['end']();};}function respondWithResult(_0x1d87b9,_0x175864){_0x175864=_0x175864||0xc8;return function(_0xf5f7ed){if(_0xf5f7ed){return _0x1d87b9[_0x1dbb('0x17')](_0x175864)[_0x1dbb('0x18')](_0xf5f7ed);}};}function respondWithFilteredResult(_0x539721,_0x15dc51){return function(_0x188515){if(_0x188515){var _0x409bee=_0x188515['count'],_0x5e1dce=_0x15dc51[_0x1dbb('0x19')],_0x5b6e42=_0x15dc51[_0x1dbb('0x19')]+_0x15dc51[_0x1dbb('0x1a')],_0x363224;if(_0x5b6e42>=_0x409bee){_0x5b6e42=_0x409bee;_0x363224=0xc8;}else{_0x363224=0xce;}_0x539721[_0x1dbb('0x17')](_0x363224);return _0x539721[_0x1dbb('0x1b')](_0x1dbb('0x1c'),_0x5e1dce+'-'+_0x5b6e42+'/'+_0x409bee)[_0x1dbb('0x18')](_0x188515);}return null;};}function patchUpdates(_0x239082){return function(_0x58aa43){try{jsonpatch['apply'](_0x58aa43,_0x239082,!![]);}catch(_0x4802ba){return BPromise[_0x1dbb('0x1d')](_0x4802ba);}return _0x58aa43[_0x1dbb('0x1e')]();};}function saveUpdates(_0x570896,_0x21e48c){return function(_0x11fefd){if(_0x11fefd){return _0x11fefd[_0x1dbb('0x1f')](_0x570896)[_0x1dbb('0x20')](function(_0x33bf12){return _0x33bf12;});}return null;};}function removeEntity(_0x3ddd80,_0x330f45){return function(_0x4b206d){if(_0x4b206d){return _0x4b206d[_0x1dbb('0x21')]()[_0x1dbb('0x20')](function(){_0x3ddd80[_0x1dbb('0x17')](0xcc)[_0x1dbb('0x22')]();});}};}function handleEntityNotFound(_0x2c0993,_0x429253){return function(_0x1e1918){if(!_0x1e1918){_0x2c0993[_0x1dbb('0x16')](0x194);}return _0x1e1918;};}function handleError(_0x2945ec,_0xc33a9f){_0xc33a9f=_0xc33a9f||0x1f4;return function(_0x18f188){logger['error'](_0x18f188[_0x1dbb('0x23')]);if(_0x18f188['name']){delete _0x18f188[_0x1dbb('0x24')];}_0x2945ec['status'](_0xc33a9f)[_0x1dbb('0x25')](_0x18f188);};}exports[_0x1dbb('0x26')]=function(_0x346372,_0x3ece10){var _0x271ee5={},_0x47057d={},_0x5e5059={'count':0x0,'rows':[]};var _0x14fca1=_[_0x1dbb('0x27')](db[_0x1dbb('0x28')]['rawAttributes'],function(_0x5557ad){return{'name':_0x5557ad[_0x1dbb('0x29')],'type':_0x5557ad['type']['key']};});_0x47057d[_0x1dbb('0x2a')]=_[_0x1dbb('0x27')](_0x14fca1,_0x1dbb('0x24'));_0x47057d[_0x1dbb('0x2b')]=_[_0x1dbb('0x2c')](_0x346372[_0x1dbb('0x2b')]);_0x47057d[_0x1dbb('0x2d')]=_[_0x1dbb('0x2e')](_0x47057d[_0x1dbb('0x2a')],_0x47057d['query']);_0x271ee5['attributes']=_[_0x1dbb('0x2e')](_0x47057d[_0x1dbb('0x2a')],qs[_0x1dbb('0x2f')](_0x346372['query']['fields']));_0x271ee5[_0x1dbb('0x30')]=_0x271ee5[_0x1dbb('0x30')][_0x1dbb('0x31')]?_0x271ee5['attributes']:_0x47057d['model'];if(!_0x346372[_0x1dbb('0x2b')][_0x1dbb('0x32')]('nolimit')){_0x271ee5[_0x1dbb('0x1a')]=qs[_0x1dbb('0x1a')](_0x346372[_0x1dbb('0x2b')][_0x1dbb('0x1a')]);_0x271ee5['offset']=qs[_0x1dbb('0x19')](_0x346372[_0x1dbb('0x2b')][_0x1dbb('0x19')]);}_0x271ee5[_0x1dbb('0x33')]=qs[_0x1dbb('0x34')](_0x346372[_0x1dbb('0x2b')]['sort']);_0x271ee5[_0x1dbb('0x35')]=qs[_0x1dbb('0x2d')](_['pick'](_0x346372[_0x1dbb('0x2b')],_0x47057d[_0x1dbb('0x2d')]),_0x14fca1);if(_0x346372[_0x1dbb('0x2b')][_0x1dbb('0x36')]){_0x271ee5[_0x1dbb('0x35')]=_['merge'](_0x271ee5[_0x1dbb('0x35')],{'$or':_[_0x1dbb('0x27')](_0x14fca1,function(_0x58536e){if(_0x58536e[_0x1dbb('0x37')]!==_0x1dbb('0x38')){var _0x158177={};_0x158177[_0x58536e['name']]={'$like':'%'+_0x346372[_0x1dbb('0x2b')][_0x1dbb('0x36')]+'%'};return _0x158177;}})});}_0x271ee5=_['merge']({},_0x271ee5,_0x346372[_0x1dbb('0x39')]);var _0x41a81b={'where':_0x271ee5[_0x1dbb('0x35')]};return db[_0x1dbb('0x28')][_0x1dbb('0x3a')](_0x41a81b)[_0x1dbb('0x20')](function(_0xbce716){_0x5e5059[_0x1dbb('0x3a')]=_0xbce716;if(_0x346372[_0x1dbb('0x2b')][_0x1dbb('0x3b')]){_0x271ee5[_0x1dbb('0x3c')]=[{'all':!![]}];}return db[_0x1dbb('0x28')][_0x1dbb('0x3d')](_0x271ee5);})['then'](function(_0x1b94ab){_0x5e5059[_0x1dbb('0x3e')]=_0x1b94ab;return _0x5e5059;})[_0x1dbb('0x20')](respondWithFilteredResult(_0x3ece10,_0x271ee5))[_0x1dbb('0x3f')](handleError(_0x3ece10,null));};exports[_0x1dbb('0x40')]=function(_0x2cad14,_0x414609){var _0x23b461={'raw':!![],'where':{'id':_0x2cad14[_0x1dbb('0x41')]['id']}},_0x3f331f={};_0x3f331f[_0x1dbb('0x2a')]=_[_0x1dbb('0x2c')](db[_0x1dbb('0x28')]['rawAttributes']);_0x3f331f[_0x1dbb('0x2b')]=_[_0x1dbb('0x2c')](_0x2cad14[_0x1dbb('0x2b')]);_0x3f331f[_0x1dbb('0x2d')]=_['intersection'](_0x3f331f[_0x1dbb('0x2a')],_0x3f331f[_0x1dbb('0x2b')]);_0x23b461[_0x1dbb('0x30')]=_[_0x1dbb('0x2e')](_0x3f331f[_0x1dbb('0x2a')],qs[_0x1dbb('0x2f')](_0x2cad14[_0x1dbb('0x2b')][_0x1dbb('0x2f')]));_0x23b461['attributes']=_0x23b461[_0x1dbb('0x30')][_0x1dbb('0x31')]?_0x23b461[_0x1dbb('0x30')]:_0x3f331f[_0x1dbb('0x2a')];if(_0x2cad14[_0x1dbb('0x2b')][_0x1dbb('0x3b')]){_0x23b461['include']=[{'all':!![]}];}_0x23b461=_[_0x1dbb('0x42')]({},_0x23b461,_0x2cad14['options']);return db[_0x1dbb('0x28')][_0x1dbb('0x43')](_0x23b461)['then'](handleEntityNotFound(_0x414609,null))[_0x1dbb('0x20')](respondWithResult(_0x414609,null))[_0x1dbb('0x3f')](handleError(_0x414609,null));};exports[_0x1dbb('0x44')]=function(_0x13972d,_0x3c76b5){return db['SquareReport'][_0x1dbb('0x44')](_0x13972d[_0x1dbb('0x45')],{})[_0x1dbb('0x20')](respondWithResult(_0x3c76b5,0xc9))[_0x1dbb('0x3f')](handleError(_0x3c76b5,null));};exports[_0x1dbb('0x1f')]=function(_0x4a9295,_0x17e8e0){if(_0x4a9295['body']['id']){delete _0x4a9295['body']['id'];}return db[_0x1dbb('0x28')]['find']({'where':{'id':_0x4a9295[_0x1dbb('0x41')]['id']}})[_0x1dbb('0x20')](handleEntityNotFound(_0x17e8e0,null))[_0x1dbb('0x20')](saveUpdates(_0x4a9295[_0x1dbb('0x45')],null))[_0x1dbb('0x20')](respondWithResult(_0x17e8e0,null))[_0x1dbb('0x3f')](handleError(_0x17e8e0,null));};exports['destroy']=function(_0x16cf4f,_0x2b2d15){return db[_0x1dbb('0x28')][_0x1dbb('0x43')]({'where':{'id':_0x16cf4f[_0x1dbb('0x41')]['id']}})[_0x1dbb('0x20')](handleEntityNotFound(_0x2b2d15,null))['then'](removeEntity(_0x2b2d15,null))['catch'](handleError(_0x2b2d15,null));};exports[_0x1dbb('0x46')]=function(_0x5bf6dc,_0x3c4764){return db[_0x1dbb('0x28')][_0x1dbb('0x46')]()['then'](respondWithResult(_0x3c4764,null))[_0x1dbb('0x3f')](handleError(_0x3c4764,null));};