4d6098fe78483e971c28eb65ccc164d00b087372
[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 _0x8b89=['papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','json','count','offset','limit','set','apply','reject','update','then','error','stack','name','send','map','SquareDetailsReport','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','includeAll','include','catch','show','params','keys','rawAttributes','find','create','body','destroy','html-pdf','eml-format','zip-dir','request-promise','moment','util','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x8b89,0x107));var _0x98b8=function(_0x5e6a94,_0x126298){_0x5e6a94=_0x5e6a94-0x0;var _0x3304c6=_0x8b89[_0x5e6a94];return _0x3304c6;};'use strict';var pdf=require(_0x98b8('0x0'));var emlformat=require(_0x98b8('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x98b8('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x98b8('0x3'));var moment=require(_0x98b8('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x98b8('0x5'));var path=require('path');var sox=require(_0x98b8('0x6'));var csv=require(_0x98b8('0x7'));var ejs=require(_0x98b8('0x8'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x98b8('0x9'));var jsforce=require(_0x98b8('0xa'));var deskjs=require(_0x98b8('0xb'));var toCsv=require(_0x98b8('0x7'));var querystring=require(_0x98b8('0xc'));var Papa=require(_0x98b8('0xd'));var Redis=require(_0x98b8('0xe'));var authService=require(_0x98b8('0xf'));var qs=require(_0x98b8('0x10'));var as=require(_0x98b8('0x11'));var hardwareService=require(_0x98b8('0x12'));var logger=require(_0x98b8('0x13'))(_0x98b8('0x14'));var utils=require(_0x98b8('0x15'));var config=require('../../config/environment');var db=require(_0x98b8('0x16'))['db'];function respondWithStatusCode(_0x5d85f7,_0x3dd456){_0x3dd456=_0x3dd456||0xcc;return function(_0x367a52){if(_0x367a52){return _0x5d85f7[_0x98b8('0x17')](_0x3dd456);}return _0x5d85f7[_0x98b8('0x18')](_0x3dd456)['end']();};}function respondWithResult(_0xddf327,_0x3f24d3){_0x3f24d3=_0x3f24d3||0xc8;return function(_0x40047f){if(_0x40047f){return _0xddf327['status'](_0x3f24d3)[_0x98b8('0x19')](_0x40047f);}};}function respondWithFilteredResult(_0x525f07,_0x4fa35c){return function(_0x34b1d3){if(_0x34b1d3){var _0x163d62=_0x34b1d3[_0x98b8('0x1a')],_0x3b6399=_0x4fa35c['offset'],_0x325a91=_0x4fa35c[_0x98b8('0x1b')]+_0x4fa35c[_0x98b8('0x1c')],_0x57c518;if(_0x325a91>=_0x163d62){_0x325a91=_0x163d62;_0x57c518=0xc8;}else{_0x57c518=0xce;}_0x525f07[_0x98b8('0x18')](_0x57c518);return _0x525f07[_0x98b8('0x1d')]('Content-Range',_0x3b6399+'-'+_0x325a91+'/'+_0x163d62)[_0x98b8('0x19')](_0x34b1d3);}return null;};}function patchUpdates(_0xd8db10){return function(_0x340565){try{jsonpatch[_0x98b8('0x1e')](_0x340565,_0xd8db10,!![]);}catch(_0x302993){return BPromise[_0x98b8('0x1f')](_0x302993);}return _0x340565['save']();};}function saveUpdates(_0x59ac27,_0x2ecec0){return function(_0x4079e0){if(_0x4079e0){return _0x4079e0[_0x98b8('0x20')](_0x59ac27)[_0x98b8('0x21')](function(_0x3b544d){return _0x3b544d;});}return null;};}function removeEntity(_0x409825,_0x4787bb){return function(_0x137b76){if(_0x137b76){return _0x137b76['destroy']()['then'](function(){_0x409825[_0x98b8('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x38cfd0,_0xbde2ef){return function(_0x59c020){if(!_0x59c020){_0x38cfd0[_0x98b8('0x17')](0x194);}return _0x59c020;};}function handleError(_0x570021,_0xb566f7){_0xb566f7=_0xb566f7||0x1f4;return function(_0x5854e2){logger[_0x98b8('0x22')](_0x5854e2[_0x98b8('0x23')]);if(_0x5854e2[_0x98b8('0x24')]){delete _0x5854e2[_0x98b8('0x24')];}_0x570021[_0x98b8('0x18')](_0xb566f7)[_0x98b8('0x25')](_0x5854e2);};}exports['index']=function(_0x1f65d7,_0xa8d0c8){var _0x5091b7={},_0x1fd662={},_0x46013e={'count':0x0,'rows':[]};var _0x1f9a4d=_[_0x98b8('0x26')](db[_0x98b8('0x27')]['rawAttributes'],function(_0x4ac783){return{'name':_0x4ac783[_0x98b8('0x28')],'type':_0x4ac783[_0x98b8('0x29')][_0x98b8('0x2a')]};});_0x1fd662[_0x98b8('0x2b')]=_[_0x98b8('0x26')](_0x1f9a4d,_0x98b8('0x24'));_0x1fd662[_0x98b8('0x2c')]=_['keys'](_0x1f65d7[_0x98b8('0x2c')]);_0x1fd662[_0x98b8('0x2d')]=_[_0x98b8('0x2e')](_0x1fd662[_0x98b8('0x2b')],_0x1fd662['query']);_0x5091b7['attributes']=_['intersection'](_0x1fd662[_0x98b8('0x2b')],qs[_0x98b8('0x2f')](_0x1f65d7['query'][_0x98b8('0x2f')]));_0x5091b7[_0x98b8('0x30')]=_0x5091b7['attributes'][_0x98b8('0x31')]?_0x5091b7[_0x98b8('0x30')]:_0x1fd662[_0x98b8('0x2b')];if(!_0x1f65d7['query'][_0x98b8('0x32')](_0x98b8('0x33'))){_0x5091b7[_0x98b8('0x1c')]=qs[_0x98b8('0x1c')](_0x1f65d7[_0x98b8('0x2c')]['limit']);_0x5091b7[_0x98b8('0x1b')]=qs[_0x98b8('0x1b')](_0x1f65d7[_0x98b8('0x2c')][_0x98b8('0x1b')]);}_0x5091b7[_0x98b8('0x34')]=qs[_0x98b8('0x35')](_0x1f65d7[_0x98b8('0x2c')][_0x98b8('0x35')]);_0x5091b7[_0x98b8('0x36')]=qs[_0x98b8('0x2d')](_['pick'](_0x1f65d7[_0x98b8('0x2c')],_0x1fd662[_0x98b8('0x2d')]),_0x1f9a4d);if(_0x1f65d7['query'][_0x98b8('0x37')]){_0x5091b7[_0x98b8('0x36')]=_['merge'](_0x5091b7[_0x98b8('0x36')],{'$or':_[_0x98b8('0x26')](_0x1f9a4d,function(_0x526871){if(_0x526871[_0x98b8('0x29')]!=='VIRTUAL'){var _0x3fb98e={};_0x3fb98e[_0x526871[_0x98b8('0x24')]]={'$like':'%'+_0x1f65d7[_0x98b8('0x2c')][_0x98b8('0x37')]+'%'};return _0x3fb98e;}})});}_0x5091b7=_[_0x98b8('0x38')]({},_0x5091b7,_0x1f65d7[_0x98b8('0x39')]);var _0x5c4545={'where':_0x5091b7['where']};return db[_0x98b8('0x27')]['count'](_0x5c4545)[_0x98b8('0x21')](function(_0x1980c4){_0x46013e[_0x98b8('0x1a')]=_0x1980c4;if(_0x1f65d7[_0x98b8('0x2c')][_0x98b8('0x3a')]){_0x5091b7[_0x98b8('0x3b')]=[{'all':!![]}];}return db['SquareDetailsReport']['findAll'](_0x5091b7);})[_0x98b8('0x21')](function(_0x1293e){_0x46013e['rows']=_0x1293e;return _0x46013e;})[_0x98b8('0x21')](respondWithFilteredResult(_0xa8d0c8,_0x5091b7))[_0x98b8('0x3c')](handleError(_0xa8d0c8,null));};exports[_0x98b8('0x3d')]=function(_0x414f92,_0x14735c){var _0x560910={'raw':!![],'where':{'id':_0x414f92[_0x98b8('0x3e')]['id']}},_0x227edf={};_0x227edf['model']=_[_0x98b8('0x3f')](db[_0x98b8('0x27')][_0x98b8('0x40')]);_0x227edf[_0x98b8('0x2c')]=_[_0x98b8('0x3f')](_0x414f92[_0x98b8('0x2c')]);_0x227edf['filters']=_[_0x98b8('0x2e')](_0x227edf[_0x98b8('0x2b')],_0x227edf['query']);_0x560910[_0x98b8('0x30')]=_[_0x98b8('0x2e')](_0x227edf[_0x98b8('0x2b')],qs[_0x98b8('0x2f')](_0x414f92[_0x98b8('0x2c')][_0x98b8('0x2f')]));_0x560910[_0x98b8('0x30')]=_0x560910[_0x98b8('0x30')][_0x98b8('0x31')]?_0x560910[_0x98b8('0x30')]:_0x227edf['model'];if(_0x414f92[_0x98b8('0x2c')][_0x98b8('0x3a')]){_0x560910[_0x98b8('0x3b')]=[{'all':!![]}];}_0x560910=_[_0x98b8('0x38')]({},_0x560910,_0x414f92[_0x98b8('0x39')]);return db['SquareDetailsReport'][_0x98b8('0x41')](_0x560910)['then'](handleEntityNotFound(_0x14735c,null))[_0x98b8('0x21')](respondWithResult(_0x14735c,null))['catch'](handleError(_0x14735c,null));};exports[_0x98b8('0x42')]=function(_0x560837,_0x41678c){return db[_0x98b8('0x27')][_0x98b8('0x42')](_0x560837[_0x98b8('0x43')],{})[_0x98b8('0x21')](respondWithResult(_0x41678c,0xc9))['catch'](handleError(_0x41678c,null));};exports[_0x98b8('0x20')]=function(_0x48de65,_0x422dc7){if(_0x48de65['body']['id']){delete _0x48de65[_0x98b8('0x43')]['id'];}return db[_0x98b8('0x27')][_0x98b8('0x41')]({'where':{'id':_0x48de65[_0x98b8('0x3e')]['id']}})['then'](handleEntityNotFound(_0x422dc7,null))[_0x98b8('0x21')](saveUpdates(_0x48de65['body'],null))['then'](respondWithResult(_0x422dc7,null))[_0x98b8('0x3c')](handleError(_0x422dc7,null));};exports[_0x98b8('0x44')]=function(_0x417bd4,_0x545bab){return db[_0x98b8('0x27')]['find']({'where':{'id':_0x417bd4[_0x98b8('0x3e')]['id']}})[_0x98b8('0x21')](handleEntityNotFound(_0x545bab,null))[_0x98b8('0x21')](removeEntity(_0x545bab,null))[_0x98b8('0x3c')](handleError(_0x545bab,null));};exports['describe']=function(_0xa7c422,_0x363a91){return db[_0x98b8('0x27')]['describe']()[_0x98b8('0x21')](respondWithResult(_0x363a91,null))[_0x98b8('0x3c')](handleError(_0x363a91,null));};