9db25a8b81abe24bd521b3949dc5311dc4938f5a
[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 _0x0f61=['apply','reject','update','then','destroy','error','stack','name','SquareDetailsReport','rawAttributes','fieldName','key','model','map','query','filters','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','type','VIRTUAL','include','rows','show','params','keys','intersection','merge','create','catch','body','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','ejs','fs-extra','lodash','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range'];(function(_0x171c5f,_0x11d2af){var _0x1c5cda=function(_0x51e968){while(--_0x51e968){_0x171c5f['push'](_0x171c5f['shift']());}};_0x1c5cda(++_0x11d2af);}(_0x0f61,0x105));var _0x10f6=function(_0x57de15,_0x1e302f){_0x57de15=_0x57de15-0x0;var _0x374994=_0x0f61[_0x57de15];return _0x374994;};'use strict';var emlformat=require(_0x10f6('0x0'));var rimraf=require(_0x10f6('0x1'));var zipdir=require(_0x10f6('0x2'));var jsonpatch=require(_0x10f6('0x3'));var rp=require(_0x10f6('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x10f6('0x5'));var util=require(_0x10f6('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x10f6('0x7'));var fs=require('fs');var fs_extra=require(_0x10f6('0x8'));var _=require(_0x10f6('0x9'));var squel=require('squel');var crypto=require(_0x10f6('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x10f6('0xb'));var toCsv=require(_0x10f6('0xc'));var querystring=require(_0x10f6('0xd'));var Papa=require(_0x10f6('0xe'));var Redis=require(_0x10f6('0xf'));var authService=require(_0x10f6('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x10f6('0x11'));var hardwareService=require(_0x10f6('0x12'));var logger=require(_0x10f6('0x13'))(_0x10f6('0x14'));var utils=require(_0x10f6('0x15'));var config=require(_0x10f6('0x16'));var licenseUtil=require(_0x10f6('0x17'));var db=require(_0x10f6('0x18'))['db'];function respondWithStatusCode(_0x371234,_0x1eacc2){_0x1eacc2=_0x1eacc2||0xcc;return function(_0x3cf60a){if(_0x3cf60a){return _0x371234[_0x10f6('0x19')](_0x1eacc2);}return _0x371234[_0x10f6('0x1a')](_0x1eacc2)[_0x10f6('0x1b')]();};}function respondWithResult(_0x50055f,_0x39f6cd){_0x39f6cd=_0x39f6cd||0xc8;return function(_0xf00c0f){if(_0xf00c0f){return _0x50055f[_0x10f6('0x1a')](_0x39f6cd)[_0x10f6('0x1c')](_0xf00c0f);}};}function respondWithFilteredResult(_0xdacef7,_0x3c2fe3){return function(_0x5f48c9){if(_0x5f48c9){var _0x1b5ab2=typeof _0x3c2fe3[_0x10f6('0x1d')]===_0x10f6('0x1e')&&typeof _0x3c2fe3[_0x10f6('0x1f')]==='undefined';var _0x365e72=_0x5f48c9['count'];var _0x173880=_0x1b5ab2?0x0:_0x3c2fe3['offset'];var _0x4b61bc=_0x1b5ab2?_0x5f48c9[_0x10f6('0x20')]:_0x3c2fe3[_0x10f6('0x1d')]+_0x3c2fe3[_0x10f6('0x1f')];var _0x115d85;if(_0x4b61bc>=_0x365e72){_0x4b61bc=_0x365e72;_0x115d85=0xc8;}else{_0x115d85=0xce;}_0xdacef7['status'](_0x115d85);return _0xdacef7[_0x10f6('0x21')](_0x10f6('0x22'),_0x173880+'-'+_0x4b61bc+'/'+_0x365e72)['json'](_0x5f48c9);}return null;};}function patchUpdates(_0x31891c){return function(_0xe8573){try{jsonpatch[_0x10f6('0x23')](_0xe8573,_0x31891c,!![]);}catch(_0x26d6b0){return BPromise[_0x10f6('0x24')](_0x26d6b0);}return _0xe8573['save']();};}function saveUpdates(_0x2fea30,_0x4209dd){return function(_0x238109){if(_0x238109){return _0x238109[_0x10f6('0x25')](_0x2fea30)[_0x10f6('0x26')](function(_0x1683f9){return _0x1683f9;});}return null;};}function removeEntity(_0x16d76c,_0x5468fc){return function(_0x6ff62c){if(_0x6ff62c){return _0x6ff62c[_0x10f6('0x27')]()[_0x10f6('0x26')](function(){_0x16d76c[_0x10f6('0x1a')](0xcc)[_0x10f6('0x1b')]();});}};}function handleEntityNotFound(_0x2af092,_0x510075){return function(_0x3bc775){if(!_0x3bc775){_0x2af092[_0x10f6('0x19')](0x194);}return _0x3bc775;};}function handleError(_0x48aa58,_0x588238){_0x588238=_0x588238||0x1f4;return function(_0x832e0c){logger[_0x10f6('0x28')](_0x832e0c[_0x10f6('0x29')]);if(_0x832e0c['name']){delete _0x832e0c[_0x10f6('0x2a')];}_0x48aa58[_0x10f6('0x1a')](_0x588238)['send'](_0x832e0c);};}exports['index']=function(_0xe44e12,_0x34c155){var _0x34a328={},_0xdd33a7={},_0x195fb3={'count':0x0,'rows':[]};var _0xae4535=_['map'](db[_0x10f6('0x2b')][_0x10f6('0x2c')],function(_0x2653e0){return{'name':_0x2653e0[_0x10f6('0x2d')],'type':_0x2653e0['type'][_0x10f6('0x2e')]};});_0xdd33a7[_0x10f6('0x2f')]=_[_0x10f6('0x30')](_0xae4535,'name');_0xdd33a7[_0x10f6('0x31')]=_['keys'](_0xe44e12[_0x10f6('0x31')]);_0xdd33a7[_0x10f6('0x32')]=_['intersection'](_0xdd33a7[_0x10f6('0x2f')],_0xdd33a7[_0x10f6('0x31')]);_0x34a328[_0x10f6('0x33')]=_['intersection'](_0xdd33a7[_0x10f6('0x2f')],qs[_0x10f6('0x34')](_0xe44e12[_0x10f6('0x31')][_0x10f6('0x34')]));_0x34a328['attributes']=_0x34a328[_0x10f6('0x33')][_0x10f6('0x35')]?_0x34a328[_0x10f6('0x33')]:_0xdd33a7['model'];if(!_0xe44e12[_0x10f6('0x31')][_0x10f6('0x36')]('nolimit')){_0x34a328[_0x10f6('0x1f')]=qs[_0x10f6('0x1f')](_0xe44e12[_0x10f6('0x31')]['limit']);_0x34a328['offset']=qs[_0x10f6('0x1d')](_0xe44e12[_0x10f6('0x31')]['offset']);}_0x34a328[_0x10f6('0x37')]=qs['sort'](_0xe44e12[_0x10f6('0x31')][_0x10f6('0x38')]);_0x34a328[_0x10f6('0x39')]=qs[_0x10f6('0x32')](_[_0x10f6('0x3a')](_0xe44e12[_0x10f6('0x31')],_0xdd33a7[_0x10f6('0x32')]),_0xae4535);if(_0xe44e12[_0x10f6('0x31')][_0x10f6('0x3b')]){_0x34a328[_0x10f6('0x39')]=_['merge'](_0x34a328[_0x10f6('0x39')],{'$or':_[_0x10f6('0x30')](_0xae4535,function(_0x27b22b){if(_0x27b22b[_0x10f6('0x3c')]!==_0x10f6('0x3d')){var _0x560336={};_0x560336[_0x27b22b['name']]={'$like':'%'+_0xe44e12[_0x10f6('0x31')][_0x10f6('0x3b')]+'%'};return _0x560336;}})});}_0x34a328=_['merge']({},_0x34a328,_0xe44e12['options']);var _0x3a906b={'where':_0x34a328['where']};return db[_0x10f6('0x2b')][_0x10f6('0x20')](_0x3a906b)['then'](function(_0xc659e){_0x195fb3[_0x10f6('0x20')]=_0xc659e;if(_0xe44e12[_0x10f6('0x31')]['includeAll']){_0x34a328[_0x10f6('0x3e')]=[{'all':!![]}];}return db[_0x10f6('0x2b')]['findAll'](_0x34a328);})['then'](function(_0x2e9df3){_0x195fb3[_0x10f6('0x3f')]=_0x2e9df3;return _0x195fb3;})[_0x10f6('0x26')](respondWithFilteredResult(_0x34c155,_0x34a328))['catch'](handleError(_0x34c155,null));};exports[_0x10f6('0x40')]=function(_0x295c68,_0xb26e7f){var _0x548b4d={'raw':!![],'where':{'id':_0x295c68[_0x10f6('0x41')]['id']}},_0x50a4e3={};_0x50a4e3[_0x10f6('0x2f')]=_[_0x10f6('0x42')](db[_0x10f6('0x2b')][_0x10f6('0x2c')]);_0x50a4e3[_0x10f6('0x31')]=_[_0x10f6('0x42')](_0x295c68[_0x10f6('0x31')]);_0x50a4e3['filters']=_[_0x10f6('0x43')](_0x50a4e3[_0x10f6('0x2f')],_0x50a4e3[_0x10f6('0x31')]);_0x548b4d[_0x10f6('0x33')]=_[_0x10f6('0x43')](_0x50a4e3[_0x10f6('0x2f')],qs['fields'](_0x295c68[_0x10f6('0x31')]['fields']));_0x548b4d[_0x10f6('0x33')]=_0x548b4d[_0x10f6('0x33')][_0x10f6('0x35')]?_0x548b4d[_0x10f6('0x33')]:_0x50a4e3['model'];if(_0x295c68['query']['includeAll']){_0x548b4d['include']=[{'all':!![]}];}_0x548b4d=_[_0x10f6('0x44')]({},_0x548b4d,_0x295c68['options']);return db[_0x10f6('0x2b')]['find'](_0x548b4d)[_0x10f6('0x26')](handleEntityNotFound(_0xb26e7f,null))[_0x10f6('0x26')](respondWithResult(_0xb26e7f,null))['catch'](handleError(_0xb26e7f,null));};exports[_0x10f6('0x45')]=function(_0x400810,_0x1bdb3b){return db[_0x10f6('0x2b')][_0x10f6('0x45')](_0x400810['body'],{})['then'](respondWithResult(_0x1bdb3b,0xc9))[_0x10f6('0x46')](handleError(_0x1bdb3b,null));};exports[_0x10f6('0x25')]=function(_0x2eb070,_0x52be17){if(_0x2eb070[_0x10f6('0x47')]['id']){delete _0x2eb070['body']['id'];}return db['SquareDetailsReport'][_0x10f6('0x48')]({'where':{'id':_0x2eb070[_0x10f6('0x41')]['id']}})[_0x10f6('0x26')](handleEntityNotFound(_0x52be17,null))[_0x10f6('0x26')](saveUpdates(_0x2eb070[_0x10f6('0x47')],null))[_0x10f6('0x26')](respondWithResult(_0x52be17,null))[_0x10f6('0x46')](handleError(_0x52be17,null));};exports['destroy']=function(_0x43b893,_0x507567){return db['SquareDetailsReport']['find']({'where':{'id':_0x43b893['params']['id']}})[_0x10f6('0x26')](handleEntityNotFound(_0x507567,null))['then'](removeEntity(_0x507567,null))[_0x10f6('0x46')](handleError(_0x507567,null));};exports[_0x10f6('0x49')]=function(_0x59f5d9,_0x4e3a29){return db[_0x10f6('0x2b')]['describe']()[_0x10f6('0x26')](respondWithResult(_0x4e3a29,null))[_0x10f6('0x46')](handleError(_0x4e3a29,null));};