Built motion from commit (unavailable).|2.3.4
[motion2.git] / server / api / squareReportDetail / squareReportDetail.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 _0xb4c2=['model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','map','type','key','VIRTUAL','field','options','count','include','rows','catch','show','params','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','end','offset','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','error','name','send','index','SquareDetailsReport','rawAttributes'];(function(_0x2689fe,_0x1299df){var _0x323f30=function(_0x1fe61a){while(--_0x1fe61a){_0x2689fe['push'](_0x2689fe['shift']());}};_0x323f30(++_0x1299df);}(_0xb4c2,0x19c));var _0x2b4c=function(_0xb053da,_0x36f6d6){_0xb053da=_0xb053da-0x0;var _0x31d38d=_0xb4c2[_0xb053da];return _0x31d38d;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x2b4c('0x0'));var rimraf=require(_0x2b4c('0x1'));var zipdir=require(_0x2b4c('0x2'));var jsonpatch=require(_0x2b4c('0x3'));var rp=require(_0x2b4c('0x4'));var moment=require(_0x2b4c('0x5'));var BPromise=require(_0x2b4c('0x6'));var Mustache=require(_0x2b4c('0x7'));var util=require(_0x2b4c('0x8'));var path=require(_0x2b4c('0x9'));var sox=require(_0x2b4c('0xa'));var csv=require('to-csv');var ejs=require(_0x2b4c('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x2b4c('0xc'));var crypto=require('crypto');var jsforce=require(_0x2b4c('0xd'));var deskjs=require(_0x2b4c('0xe'));var toCsv=require('to-csv');var querystring=require(_0x2b4c('0xf'));var Papa=require(_0x2b4c('0x10'));var authService=require(_0x2b4c('0x11'));var hardwareService=require(_0x2b4c('0x12'));var Redis=require('ioredis');var qs=require(_0x2b4c('0x13'));var logger=require(_0x2b4c('0x14'))(_0x2b4c('0x15'));var utils=require(_0x2b4c('0x16'));var config=require(_0x2b4c('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3313c6,_0x3f7cf2){_0x3f7cf2=_0x3f7cf2||0xcc;return function(_0x2650d0){if(_0x2650d0){return _0x3313c6[_0x2b4c('0x18')](_0x3f7cf2);}return _0x3313c6[_0x2b4c('0x19')](_0x3f7cf2)[_0x2b4c('0x1a')]();};}function respondWithResult(_0x432d1a,_0x2edd1b){_0x2edd1b=_0x2edd1b||0xc8;return function(_0x323ebe){if(_0x323ebe){return _0x432d1a[_0x2b4c('0x19')](_0x2edd1b)['json'](_0x323ebe);}};}function respondWithFilteredResult(_0x2b3ca8,_0x26dec6){return function(_0x38c517){if(_0x38c517){var _0x2f6fd5=_0x38c517['count'],_0x1e9508=_0x26dec6[_0x2b4c('0x1b')],_0x7fcee9=_0x26dec6[_0x2b4c('0x1b')]+_0x26dec6[_0x2b4c('0x1c')],_0x20fa31;if(_0x7fcee9>=_0x2f6fd5){_0x7fcee9=_0x2f6fd5;_0x20fa31=0xc8;}else{_0x20fa31=0xce;}_0x2b3ca8[_0x2b4c('0x19')](_0x20fa31);return _0x2b3ca8[_0x2b4c('0x1d')](_0x2b4c('0x1e'),_0x1e9508+'-'+_0x7fcee9+'/'+_0x2f6fd5)[_0x2b4c('0x1f')](_0x38c517);}return null;};}function patchUpdates(_0xf729c){return function(_0x1cd5a9){try{jsonpatch[_0x2b4c('0x20')](_0x1cd5a9,_0xf729c,!![]);}catch(_0x33fe96){return BPromise[_0x2b4c('0x21')](_0x33fe96);}return _0x1cd5a9[_0x2b4c('0x22')]();};}function saveUpdates(_0x1a154b,_0x42abec){return function(_0xb251){if(_0xb251){return _0xb251[_0x2b4c('0x23')](_0x1a154b)[_0x2b4c('0x24')](function(_0x16bbbc){return _0x16bbbc;});}return null;};}function removeEntity(_0x4472b4,_0x53781b){return function(_0x830d7c){if(_0x830d7c){return _0x830d7c[_0x2b4c('0x25')]()[_0x2b4c('0x24')](function(){_0x4472b4[_0x2b4c('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2e3a06,_0x417a85){return function(_0x5c437e){if(!_0x5c437e){_0x2e3a06[_0x2b4c('0x18')](0x194);}return _0x5c437e;};}function handleError(_0x586c55,_0x37f603){_0x37f603=_0x37f603||0x1f4;return function(_0x4aaac4){logger[_0x2b4c('0x26')](_0x4aaac4['stack']);if(_0x4aaac4['name']){delete _0x4aaac4[_0x2b4c('0x27')];}_0x586c55['status'](_0x37f603)[_0x2b4c('0x28')](_0x4aaac4);};}exports[_0x2b4c('0x29')]=function(_0x40b940,_0x1fe775){var _0x2286f1={},_0x4091ed={},_0x2a1db3={'count':0x0,'rows':[]};var _0x5ea19f=db[_0x2b4c('0x2a')][_0x2b4c('0x2b')];_0x4091ed[_0x2b4c('0x2c')]=_[_0x2b4c('0x2d')](_0x5ea19f);_0x4091ed[_0x2b4c('0x2e')]=_[_0x2b4c('0x2d')](_0x40b940[_0x2b4c('0x2e')]);_0x4091ed[_0x2b4c('0x2f')]=_[_0x2b4c('0x30')](_0x4091ed[_0x2b4c('0x2c')],_0x4091ed[_0x2b4c('0x2e')]);_0x2286f1[_0x2b4c('0x31')]=_[_0x2b4c('0x30')](_0x4091ed[_0x2b4c('0x2c')],qs['fields'](_0x40b940['query'][_0x2b4c('0x32')]));_0x2286f1[_0x2b4c('0x31')]=_0x2286f1['attributes'][_0x2b4c('0x33')]?_0x2286f1[_0x2b4c('0x31')]:_0x4091ed['model'];if(!_0x40b940['query'][_0x2b4c('0x34')](_0x2b4c('0x35'))){_0x2286f1[_0x2b4c('0x1c')]=qs[_0x2b4c('0x1c')](_0x40b940['query'][_0x2b4c('0x1c')]);_0x2286f1[_0x2b4c('0x1b')]=qs[_0x2b4c('0x1b')](_0x40b940[_0x2b4c('0x2e')][_0x2b4c('0x1b')]);}_0x2286f1[_0x2b4c('0x36')]=qs[_0x2b4c('0x37')](_0x40b940['query'][_0x2b4c('0x37')]);_0x2286f1[_0x2b4c('0x38')]=qs['filters'](_[_0x2b4c('0x39')](_0x40b940[_0x2b4c('0x2e')],_0x4091ed[_0x2b4c('0x2f')]));if(_0x40b940['query'][_0x2b4c('0x3a')]){_0x2286f1[_0x2b4c('0x38')]=_[_0x2b4c('0x3b')](_0x2286f1[_0x2b4c('0x38')],{'$or':_[_0x2b4c('0x3c')](_0x5ea19f,function(_0x234294){if(_0x234294[_0x2b4c('0x3d')][_0x2b4c('0x3e')]!==_0x2b4c('0x3f')){var _0x20e4f3={};_0x20e4f3[_0x234294[_0x2b4c('0x40')]]={'$like':'%'+_0x40b940[_0x2b4c('0x2e')]['filter']+'%'};return _0x20e4f3;}})});}_0x2286f1=_[_0x2b4c('0x3b')]({},_0x2286f1,_0x40b940[_0x2b4c('0x41')]);var _0x3826a7={'where':_0x2286f1[_0x2b4c('0x38')]};return db[_0x2b4c('0x2a')][_0x2b4c('0x42')](_0x3826a7)[_0x2b4c('0x24')](function(_0x1e917f){_0x2a1db3[_0x2b4c('0x42')]=_0x1e917f;if(_0x40b940['query']['includeAll']){_0x2286f1[_0x2b4c('0x43')]=[{'all':!![]}];}return db[_0x2b4c('0x2a')]['findAll'](_0x2286f1);})[_0x2b4c('0x24')](function(_0x51bb5f){_0x2a1db3[_0x2b4c('0x44')]=_0x51bb5f;return _0x2a1db3;})[_0x2b4c('0x24')](respondWithFilteredResult(_0x1fe775,_0x2286f1))[_0x2b4c('0x45')](handleError(_0x1fe775,null));};exports[_0x2b4c('0x46')]=function(_0x3f638f,_0x1a0e7a){var _0x5b4fa0={'raw':!![],'where':{'id':_0x3f638f[_0x2b4c('0x47')]['id']}},_0x397a24={};_0x397a24[_0x2b4c('0x2c')]=_[_0x2b4c('0x2d')](db['SquareDetailsReport'][_0x2b4c('0x2b')]);_0x397a24[_0x2b4c('0x2e')]=_['keys'](_0x3f638f['query']);_0x397a24['filters']=_['intersection'](_0x397a24[_0x2b4c('0x2c')],_0x397a24[_0x2b4c('0x2e')]);_0x5b4fa0[_0x2b4c('0x31')]=_['intersection'](_0x397a24[_0x2b4c('0x2c')],qs[_0x2b4c('0x32')](_0x3f638f[_0x2b4c('0x2e')]['fields']));_0x5b4fa0['attributes']=_0x5b4fa0[_0x2b4c('0x31')][_0x2b4c('0x33')]?_0x5b4fa0[_0x2b4c('0x31')]:_0x397a24[_0x2b4c('0x2c')];if(_0x3f638f[_0x2b4c('0x2e')]['includeAll']){_0x5b4fa0['include']=[{'all':!![]}];}_0x5b4fa0=_[_0x2b4c('0x3b')]({},_0x5b4fa0,_0x3f638f[_0x2b4c('0x41')]);return db[_0x2b4c('0x2a')][_0x2b4c('0x48')](_0x5b4fa0)[_0x2b4c('0x24')](handleEntityNotFound(_0x1a0e7a,null))[_0x2b4c('0x24')](respondWithResult(_0x1a0e7a,null))['catch'](handleError(_0x1a0e7a,null));};exports[_0x2b4c('0x49')]=function(_0xf77e07,_0xa03b0){return db[_0x2b4c('0x2a')][_0x2b4c('0x49')](_0xf77e07[_0x2b4c('0x4a')],{})[_0x2b4c('0x24')](respondWithResult(_0xa03b0,0xc9))[_0x2b4c('0x45')](handleError(_0xa03b0,null));};exports[_0x2b4c('0x23')]=function(_0x101108,_0x27eb40){if(_0x101108[_0x2b4c('0x4a')]['id']){delete _0x101108['body']['id'];}return db[_0x2b4c('0x2a')]['find']({'where':{'id':_0x101108['params']['id']}})[_0x2b4c('0x24')](handleEntityNotFound(_0x27eb40,null))[_0x2b4c('0x24')](saveUpdates(_0x101108['body'],null))[_0x2b4c('0x24')](respondWithResult(_0x27eb40,null))['catch'](handleError(_0x27eb40,null));};exports['destroy']=function(_0x38f932,_0x3d23a4){return db['SquareDetailsReport']['find']({'where':{'id':_0x38f932['params']['id']}})[_0x2b4c('0x24')](handleEntityNotFound(_0x3d23a4,null))['then'](removeEntity(_0x3d23a4,null))[_0x2b4c('0x45')](handleError(_0x3d23a4,null));};exports[_0x2b4c('0x4b')]=function(_0x428a92,_0x53d26e){return db[_0x2b4c('0x2a')]['describe']()[_0x2b4c('0x24')](respondWithResult(_0x53d26e,null))[_0x2b4c('0x45')](handleError(_0x53d26e,null));};