09797bce349ef4e74a78a480dc13adbe3053056e
[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 _0x09a0=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','limit','Content-Range','apply','reject','update','then','destroy','error','stack','name','index','map','SquareDetailsReport','rawAttributes','fieldName','type','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','keys','create','body','find','params','describe','html-pdf','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring'];(function(_0x2c5af1,_0x3e51f8){var _0x38d4da=function(_0xd66593){while(--_0xd66593){_0x2c5af1['push'](_0x2c5af1['shift']());}};_0x38d4da(++_0x3e51f8);}(_0x09a0,0x81));var _0x009a=function(_0x4fbaf9,_0x3b8190){_0x4fbaf9=_0x4fbaf9-0x0;var _0x1d89a0=_0x09a0[_0x4fbaf9];return _0x1d89a0;};'use strict';var pdf=require(_0x009a('0x0'));var emlformat=require(_0x009a('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x009a('0x2'));var rp=require(_0x009a('0x3'));var moment=require(_0x009a('0x4'));var BPromise=require(_0x009a('0x5'));var Mustache=require(_0x009a('0x6'));var util=require(_0x009a('0x7'));var path=require('path');var sox=require(_0x009a('0x8'));var csv=require(_0x009a('0x9'));var ejs=require(_0x009a('0xa'));var fs=require('fs');var _=require(_0x009a('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x009a('0xc'));var deskjs=require(_0x009a('0xd'));var toCsv=require(_0x009a('0x9'));var querystring=require(_0x009a('0xe'));var Papa=require('papaparse');var Redis=require(_0x009a('0xf'));var authService=require(_0x009a('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x009a('0x11'));var hardwareService=require(_0x009a('0x12'));var logger=require(_0x009a('0x13'))(_0x009a('0x14'));var utils=require('../../config/utils');var config=require(_0x009a('0x15'));var licenseUtil=require(_0x009a('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5d38ef,_0x44a011){_0x44a011=_0x44a011||0xcc;return function(_0x1ed23f){if(_0x1ed23f){return _0x5d38ef[_0x009a('0x17')](_0x44a011);}return _0x5d38ef[_0x009a('0x18')](_0x44a011)[_0x009a('0x19')]();};}function respondWithResult(_0x403040,_0x1601cb){_0x1601cb=_0x1601cb||0xc8;return function(_0x43ec96){if(_0x43ec96){return _0x403040[_0x009a('0x18')](_0x1601cb)[_0x009a('0x1a')](_0x43ec96);}};}function respondWithFilteredResult(_0x1b7080,_0x1c179b){return function(_0x413f95){if(_0x413f95){var _0x53b2c2=_0x413f95['count'],_0x5ca512=_0x1c179b[_0x009a('0x1b')],_0x3365ec=_0x1c179b[_0x009a('0x1b')]+_0x1c179b[_0x009a('0x1c')],_0x566821;if(_0x3365ec>=_0x53b2c2){_0x3365ec=_0x53b2c2;_0x566821=0xc8;}else{_0x566821=0xce;}_0x1b7080[_0x009a('0x18')](_0x566821);return _0x1b7080['set'](_0x009a('0x1d'),_0x5ca512+'-'+_0x3365ec+'/'+_0x53b2c2)[_0x009a('0x1a')](_0x413f95);}return null;};}function patchUpdates(_0x55f15f){return function(_0x53703e){try{jsonpatch[_0x009a('0x1e')](_0x53703e,_0x55f15f,!![]);}catch(_0x18be94){return BPromise[_0x009a('0x1f')](_0x18be94);}return _0x53703e['save']();};}function saveUpdates(_0x234879,_0x4798ae){return function(_0x4ee7e0){if(_0x4ee7e0){return _0x4ee7e0[_0x009a('0x20')](_0x234879)[_0x009a('0x21')](function(_0x2019be){return _0x2019be;});}return null;};}function removeEntity(_0xc5da7e,_0x2e4572){return function(_0x1d4063){if(_0x1d4063){return _0x1d4063[_0x009a('0x22')]()['then'](function(){_0xc5da7e['status'](0xcc)[_0x009a('0x19')]();});}};}function handleEntityNotFound(_0x32373e,_0x3435dc){return function(_0x232ac6){if(!_0x232ac6){_0x32373e[_0x009a('0x17')](0x194);}return _0x232ac6;};}function handleError(_0x44f84d,_0x5cb6ee){_0x5cb6ee=_0x5cb6ee||0x1f4;return function(_0x973d6){logger[_0x009a('0x23')](_0x973d6[_0x009a('0x24')]);if(_0x973d6[_0x009a('0x25')]){delete _0x973d6[_0x009a('0x25')];}_0x44f84d[_0x009a('0x18')](_0x5cb6ee)['send'](_0x973d6);};}exports[_0x009a('0x26')]=function(_0x279148,_0x38c823){var _0xd4e147={},_0x56b7bd={},_0x4a0989={'count':0x0,'rows':[]};var _0x345168=_[_0x009a('0x27')](db[_0x009a('0x28')][_0x009a('0x29')],function(_0x125c50){return{'name':_0x125c50[_0x009a('0x2a')],'type':_0x125c50[_0x009a('0x2b')]['key']};});_0x56b7bd[_0x009a('0x2c')]=_[_0x009a('0x27')](_0x345168,_0x009a('0x25'));_0x56b7bd['query']=_['keys'](_0x279148[_0x009a('0x2d')]);_0x56b7bd[_0x009a('0x2e')]=_[_0x009a('0x2f')](_0x56b7bd[_0x009a('0x2c')],_0x56b7bd[_0x009a('0x2d')]);_0xd4e147['attributes']=_[_0x009a('0x2f')](_0x56b7bd['model'],qs[_0x009a('0x30')](_0x279148[_0x009a('0x2d')][_0x009a('0x30')]));_0xd4e147[_0x009a('0x31')]=_0xd4e147['attributes'][_0x009a('0x32')]?_0xd4e147[_0x009a('0x31')]:_0x56b7bd[_0x009a('0x2c')];if(!_0x279148[_0x009a('0x2d')][_0x009a('0x33')](_0x009a('0x34'))){_0xd4e147[_0x009a('0x1c')]=qs['limit'](_0x279148[_0x009a('0x2d')][_0x009a('0x1c')]);_0xd4e147[_0x009a('0x1b')]=qs[_0x009a('0x1b')](_0x279148[_0x009a('0x2d')]['offset']);}_0xd4e147[_0x009a('0x35')]=qs[_0x009a('0x36')](_0x279148[_0x009a('0x2d')][_0x009a('0x36')]);_0xd4e147[_0x009a('0x37')]=qs[_0x009a('0x2e')](_['pick'](_0x279148[_0x009a('0x2d')],_0x56b7bd[_0x009a('0x2e')]),_0x345168);if(_0x279148[_0x009a('0x2d')]['filter']){_0xd4e147['where']=_[_0x009a('0x38')](_0xd4e147[_0x009a('0x37')],{'$or':_[_0x009a('0x27')](_0x345168,function(_0x310b84){if(_0x310b84['type']!==_0x009a('0x39')){var _0x20e165={};_0x20e165[_0x310b84[_0x009a('0x25')]]={'$like':'%'+_0x279148[_0x009a('0x2d')][_0x009a('0x3a')]+'%'};return _0x20e165;}})});}_0xd4e147=_['merge']({},_0xd4e147,_0x279148[_0x009a('0x3b')]);var _0x3e7a3b={'where':_0xd4e147[_0x009a('0x37')]};return db[_0x009a('0x28')]['count'](_0x3e7a3b)['then'](function(_0x3b16f5){_0x4a0989['count']=_0x3b16f5;if(_0x279148[_0x009a('0x2d')][_0x009a('0x3c')]){_0xd4e147[_0x009a('0x3d')]=[{'all':!![]}];}return db[_0x009a('0x28')][_0x009a('0x3e')](_0xd4e147);})[_0x009a('0x21')](function(_0x3d490f){_0x4a0989[_0x009a('0x3f')]=_0x3d490f;return _0x4a0989;})['then'](respondWithFilteredResult(_0x38c823,_0xd4e147))[_0x009a('0x40')](handleError(_0x38c823,null));};exports[_0x009a('0x41')]=function(_0x30a181,_0x224614){var _0x5ef5c9={'raw':!![],'where':{'id':_0x30a181['params']['id']}},_0x23cd3d={};_0x23cd3d[_0x009a('0x2c')]=_[_0x009a('0x42')](db['SquareDetailsReport'][_0x009a('0x29')]);_0x23cd3d[_0x009a('0x2d')]=_[_0x009a('0x42')](_0x30a181['query']);_0x23cd3d[_0x009a('0x2e')]=_[_0x009a('0x2f')](_0x23cd3d[_0x009a('0x2c')],_0x23cd3d['query']);_0x5ef5c9['attributes']=_[_0x009a('0x2f')](_0x23cd3d[_0x009a('0x2c')],qs[_0x009a('0x30')](_0x30a181[_0x009a('0x2d')][_0x009a('0x30')]));_0x5ef5c9[_0x009a('0x31')]=_0x5ef5c9[_0x009a('0x31')]['length']?_0x5ef5c9[_0x009a('0x31')]:_0x23cd3d[_0x009a('0x2c')];if(_0x30a181[_0x009a('0x2d')][_0x009a('0x3c')]){_0x5ef5c9[_0x009a('0x3d')]=[{'all':!![]}];}_0x5ef5c9=_[_0x009a('0x38')]({},_0x5ef5c9,_0x30a181[_0x009a('0x3b')]);return db[_0x009a('0x28')]['find'](_0x5ef5c9)[_0x009a('0x21')](handleEntityNotFound(_0x224614,null))[_0x009a('0x21')](respondWithResult(_0x224614,null))[_0x009a('0x40')](handleError(_0x224614,null));};exports[_0x009a('0x43')]=function(_0x1421db,_0x1843bd){return db['SquareDetailsReport']['create'](_0x1421db[_0x009a('0x44')],{})['then'](respondWithResult(_0x1843bd,0xc9))[_0x009a('0x40')](handleError(_0x1843bd,null));};exports['update']=function(_0x39132a,_0x36dcc2){if(_0x39132a[_0x009a('0x44')]['id']){delete _0x39132a[_0x009a('0x44')]['id'];}return db[_0x009a('0x28')][_0x009a('0x45')]({'where':{'id':_0x39132a[_0x009a('0x46')]['id']}})[_0x009a('0x21')](handleEntityNotFound(_0x36dcc2,null))['then'](saveUpdates(_0x39132a[_0x009a('0x44')],null))[_0x009a('0x21')](respondWithResult(_0x36dcc2,null))[_0x009a('0x40')](handleError(_0x36dcc2,null));};exports['destroy']=function(_0x1543eb,_0x38d72d){return db[_0x009a('0x28')][_0x009a('0x45')]({'where':{'id':_0x1543eb[_0x009a('0x46')]['id']}})['then'](handleEntityNotFound(_0x38d72d,null))[_0x009a('0x21')](removeEntity(_0x38d72d,null))[_0x009a('0x40')](handleError(_0x38d72d,null));};exports[_0x009a('0x47')]=function(_0x5cb8aa,_0x41d06d){return db['SquareDetailsReport'][_0x009a('0x47')]()['then'](respondWithResult(_0x41d06d,null))[_0x009a('0x40')](handleError(_0x41d06d,null));};