3557942b38c8452748644021f8292af738475d50
[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 _0x0dd9=['papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','apply','reject','save','update','then','stack','name','send','index','map','SquareDetailsReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','rows','catch','params','find','create','body','destroy','describe','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring'];(function(_0x2913b5,_0x2387c0){var _0x2ca1cc=function(_0xc2045b){while(--_0xc2045b){_0x2913b5['push'](_0x2913b5['shift']());}};_0x2ca1cc(++_0x2387c0);}(_0x0dd9,0x84));var _0x90dd=function(_0x22a413,_0x86da8b){_0x22a413=_0x22a413-0x0;var _0x4d0ecb=_0x0dd9[_0x22a413];return _0x4d0ecb;};'use strict';var emlformat=require(_0x90dd('0x0'));var rimraf=require(_0x90dd('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x90dd('0x2'));var rp=require(_0x90dd('0x3'));var moment=require('moment');var BPromise=require(_0x90dd('0x4'));var Mustache=require(_0x90dd('0x5'));var util=require('util');var path=require(_0x90dd('0x6'));var sox=require(_0x90dd('0x7'));var csv=require(_0x90dd('0x8'));var ejs=require(_0x90dd('0x9'));var fs=require('fs');var fs_extra=require(_0x90dd('0xa'));var _=require(_0x90dd('0xb'));var squel=require(_0x90dd('0xc'));var crypto=require('crypto');var jsforce=require(_0x90dd('0xd'));var deskjs=require(_0x90dd('0xe'));var toCsv=require('to-csv');var querystring=require(_0x90dd('0xf'));var Papa=require(_0x90dd('0x10'));var Redis=require('ioredis');var authService=require(_0x90dd('0x11'));var qs=require(_0x90dd('0x12'));var as=require(_0x90dd('0x13'));var hardwareService=require(_0x90dd('0x14'));var logger=require(_0x90dd('0x15'))(_0x90dd('0x16'));var utils=require(_0x90dd('0x17'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x90dd('0x18'))['db'];function respondWithStatusCode(_0x24357e,_0x2514fb){_0x2514fb=_0x2514fb||0xcc;return function(_0x4b2eba){if(_0x4b2eba){return _0x24357e[_0x90dd('0x19')](_0x2514fb);}return _0x24357e[_0x90dd('0x1a')](_0x2514fb)[_0x90dd('0x1b')]();};}function respondWithResult(_0x20fe79,_0x422f33){_0x422f33=_0x422f33||0xc8;return function(_0x45509f){if(_0x45509f){return _0x20fe79[_0x90dd('0x1a')](_0x422f33)[_0x90dd('0x1c')](_0x45509f);}};}function respondWithFilteredResult(_0x890369,_0x335cc5){return function(_0x1ce609){if(_0x1ce609){var _0x4fd433=typeof _0x335cc5[_0x90dd('0x1d')]===_0x90dd('0x1e')&&typeof _0x335cc5[_0x90dd('0x1f')]===_0x90dd('0x1e');var _0x2be68b=_0x1ce609['count'];var _0x140e37=_0x4fd433?0x0:_0x335cc5[_0x90dd('0x1d')];var _0x331318=_0x4fd433?_0x1ce609[_0x90dd('0x20')]:_0x335cc5[_0x90dd('0x1d')]+_0x335cc5[_0x90dd('0x1f')];var _0x2c7692;if(_0x331318>=_0x2be68b){_0x331318=_0x2be68b;_0x2c7692=0xc8;}else{_0x2c7692=0xce;}_0x890369[_0x90dd('0x1a')](_0x2c7692);return _0x890369['set']('Content-Range',_0x140e37+'-'+_0x331318+'/'+_0x2be68b)['json'](_0x1ce609);}return null;};}function patchUpdates(_0x52ac20){return function(_0x3cfe8a){try{jsonpatch[_0x90dd('0x21')](_0x3cfe8a,_0x52ac20,!![]);}catch(_0x50fd7c){return BPromise[_0x90dd('0x22')](_0x50fd7c);}return _0x3cfe8a[_0x90dd('0x23')]();};}function saveUpdates(_0x195512,_0x23fe07){return function(_0x5d3771){if(_0x5d3771){return _0x5d3771[_0x90dd('0x24')](_0x195512)[_0x90dd('0x25')](function(_0x5f4653){return _0x5f4653;});}return null;};}function removeEntity(_0x5e55bf,_0x24327d){return function(_0xef5ee){if(_0xef5ee){return _0xef5ee['destroy']()[_0x90dd('0x25')](function(){_0x5e55bf[_0x90dd('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x14cb9c,_0x3c17db){return function(_0x40e110){if(!_0x40e110){_0x14cb9c[_0x90dd('0x19')](0x194);}return _0x40e110;};}function handleError(_0x335ea5,_0x43ae86){_0x43ae86=_0x43ae86||0x1f4;return function(_0x2e3a21){logger['error'](_0x2e3a21[_0x90dd('0x26')]);if(_0x2e3a21[_0x90dd('0x27')]){delete _0x2e3a21[_0x90dd('0x27')];}_0x335ea5[_0x90dd('0x1a')](_0x43ae86)[_0x90dd('0x28')](_0x2e3a21);};}exports[_0x90dd('0x29')]=function(_0x128e11,_0x5b7118){var _0x36e409={},_0xa8496a={},_0x58bac9={'count':0x0,'rows':[]};var _0x37c839=_[_0x90dd('0x2a')](db[_0x90dd('0x2b')][_0x90dd('0x2c')],function(_0x417c8f){return{'name':_0x417c8f[_0x90dd('0x2d')],'type':_0x417c8f[_0x90dd('0x2e')][_0x90dd('0x2f')]};});_0xa8496a[_0x90dd('0x30')]=_[_0x90dd('0x2a')](_0x37c839,_0x90dd('0x27'));_0xa8496a[_0x90dd('0x31')]=_[_0x90dd('0x32')](_0x128e11[_0x90dd('0x31')]);_0xa8496a[_0x90dd('0x33')]=_[_0x90dd('0x34')](_0xa8496a[_0x90dd('0x30')],_0xa8496a[_0x90dd('0x31')]);_0x36e409['attributes']=_['intersection'](_0xa8496a[_0x90dd('0x30')],qs[_0x90dd('0x35')](_0x128e11[_0x90dd('0x31')][_0x90dd('0x35')]));_0x36e409[_0x90dd('0x36')]=_0x36e409['attributes'][_0x90dd('0x37')]?_0x36e409[_0x90dd('0x36')]:_0xa8496a[_0x90dd('0x30')];if(!_0x128e11['query']['hasOwnProperty'](_0x90dd('0x38'))){_0x36e409[_0x90dd('0x1f')]=qs[_0x90dd('0x1f')](_0x128e11[_0x90dd('0x31')]['limit']);_0x36e409[_0x90dd('0x1d')]=qs[_0x90dd('0x1d')](_0x128e11[_0x90dd('0x31')][_0x90dd('0x1d')]);}_0x36e409[_0x90dd('0x39')]=qs[_0x90dd('0x3a')](_0x128e11[_0x90dd('0x31')]['sort']);_0x36e409[_0x90dd('0x3b')]=qs['filters'](_[_0x90dd('0x3c')](_0x128e11[_0x90dd('0x31')],_0xa8496a[_0x90dd('0x33')]),_0x37c839);if(_0x128e11[_0x90dd('0x31')][_0x90dd('0x3d')]){_0x36e409[_0x90dd('0x3b')]=_['merge'](_0x36e409[_0x90dd('0x3b')],{'$or':_['map'](_0x37c839,function(_0x535ab3){if(_0x535ab3[_0x90dd('0x2e')]!==_0x90dd('0x3e')){var _0x335e3b={};_0x335e3b[_0x535ab3['name']]={'$like':'%'+_0x128e11[_0x90dd('0x31')][_0x90dd('0x3d')]+'%'};return _0x335e3b;}})});}_0x36e409=_[_0x90dd('0x3f')]({},_0x36e409,_0x128e11[_0x90dd('0x40')]);var _0x2bfbda={'where':_0x36e409[_0x90dd('0x3b')]};return db[_0x90dd('0x2b')][_0x90dd('0x20')](_0x2bfbda)['then'](function(_0x53bd17){_0x58bac9[_0x90dd('0x20')]=_0x53bd17;if(_0x128e11['query'][_0x90dd('0x41')]){_0x36e409['include']=[{'all':!![]}];}return db['SquareDetailsReport']['findAll'](_0x36e409);})[_0x90dd('0x25')](function(_0x3b7bd0){_0x58bac9[_0x90dd('0x42')]=_0x3b7bd0;return _0x58bac9;})['then'](respondWithFilteredResult(_0x5b7118,_0x36e409))[_0x90dd('0x43')](handleError(_0x5b7118,null));};exports['show']=function(_0x28eb90,_0x3abc5c){var _0x5f21c6={'raw':!![],'where':{'id':_0x28eb90[_0x90dd('0x44')]['id']}},_0x141b85={};_0x141b85['model']=_['keys'](db[_0x90dd('0x2b')]['rawAttributes']);_0x141b85[_0x90dd('0x31')]=_[_0x90dd('0x32')](_0x28eb90[_0x90dd('0x31')]);_0x141b85[_0x90dd('0x33')]=_[_0x90dd('0x34')](_0x141b85['model'],_0x141b85[_0x90dd('0x31')]);_0x5f21c6[_0x90dd('0x36')]=_['intersection'](_0x141b85['model'],qs[_0x90dd('0x35')](_0x28eb90[_0x90dd('0x31')][_0x90dd('0x35')]));_0x5f21c6[_0x90dd('0x36')]=_0x5f21c6[_0x90dd('0x36')][_0x90dd('0x37')]?_0x5f21c6[_0x90dd('0x36')]:_0x141b85[_0x90dd('0x30')];if(_0x28eb90[_0x90dd('0x31')][_0x90dd('0x41')]){_0x5f21c6['include']=[{'all':!![]}];}_0x5f21c6=_['merge']({},_0x5f21c6,_0x28eb90[_0x90dd('0x40')]);return db[_0x90dd('0x2b')][_0x90dd('0x45')](_0x5f21c6)[_0x90dd('0x25')](handleEntityNotFound(_0x3abc5c,null))[_0x90dd('0x25')](respondWithResult(_0x3abc5c,null))['catch'](handleError(_0x3abc5c,null));};exports[_0x90dd('0x46')]=function(_0x41825a,_0x7ca784){return db[_0x90dd('0x2b')][_0x90dd('0x46')](_0x41825a['body'],{})[_0x90dd('0x25')](respondWithResult(_0x7ca784,0xc9))[_0x90dd('0x43')](handleError(_0x7ca784,null));};exports['update']=function(_0x8c0a6a,_0x395d2c){if(_0x8c0a6a[_0x90dd('0x47')]['id']){delete _0x8c0a6a[_0x90dd('0x47')]['id'];}return db[_0x90dd('0x2b')][_0x90dd('0x45')]({'where':{'id':_0x8c0a6a[_0x90dd('0x44')]['id']}})['then'](handleEntityNotFound(_0x395d2c,null))[_0x90dd('0x25')](saveUpdates(_0x8c0a6a['body'],null))['then'](respondWithResult(_0x395d2c,null))[_0x90dd('0x43')](handleError(_0x395d2c,null));};exports[_0x90dd('0x48')]=function(_0x2fba76,_0xaab39d){return db[_0x90dd('0x2b')][_0x90dd('0x45')]({'where':{'id':_0x2fba76[_0x90dd('0x44')]['id']}})[_0x90dd('0x25')](handleEntityNotFound(_0xaab39d,null))[_0x90dd('0x25')](removeEntity(_0xaab39d,null))['catch'](handleError(_0xaab39d,null));};exports[_0x90dd('0x49')]=function(_0xc30378,_0x5945f6){return db[_0x90dd('0x2b')]['describe']()[_0x90dd('0x25')](respondWithResult(_0x5945f6,null))[_0x90dd('0x43')](handleError(_0x5945f6,null));};