Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / squareReport / squareReport.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 _0xd011=['update','then','destroy','error','stack','name','index','map','SquareReport','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','find','catch','create','body','params','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save'];(function(_0xe8129c,_0x2fb03c){var _0x709fc5=function(_0xb8e0c6){while(--_0xb8e0c6){_0xe8129c['push'](_0xe8129c['shift']());}};_0x709fc5(++_0x2fb03c);}(_0xd011,0x1ae));var _0x1d01=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xd011[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x1d01('0x0'));var rimraf=require(_0x1d01('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x1d01('0x2'));var rp=require(_0x1d01('0x3'));var moment=require(_0x1d01('0x4'));var BPromise=require(_0x1d01('0x5'));var Mustache=require(_0x1d01('0x6'));var util=require('util');var path=require(_0x1d01('0x7'));var sox=require(_0x1d01('0x8'));var csv=require(_0x1d01('0x9'));var ejs=require(_0x1d01('0xa'));var fs=require('fs');var fs_extra=require(_0x1d01('0xb'));var _=require(_0x1d01('0xc'));var squel=require(_0x1d01('0xd'));var crypto=require(_0x1d01('0xe'));var jsforce=require(_0x1d01('0xf'));var deskjs=require('desk.js');var toCsv=require(_0x1d01('0x9'));var querystring=require('querystring');var Papa=require(_0x1d01('0x10'));var Redis=require(_0x1d01('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x1d01('0x12'));var as=require(_0x1d01('0x13'));var hardwareService=require(_0x1d01('0x14'));var logger=require(_0x1d01('0x15'))('api');var utils=require(_0x1d01('0x16'));var config=require(_0x1d01('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x1d01('0x18'))['db'];function respondWithStatusCode(_0x451ecc,_0x599a19){_0x599a19=_0x599a19||0xcc;return function(_0xaa92dc){if(_0xaa92dc){return _0x451ecc[_0x1d01('0x19')](_0x599a19);}return _0x451ecc[_0x1d01('0x1a')](_0x599a19)[_0x1d01('0x1b')]();};}function respondWithResult(_0xa09f62,_0x2ee47a){_0x2ee47a=_0x2ee47a||0xc8;return function(_0x2ddeed){if(_0x2ddeed){return _0xa09f62[_0x1d01('0x1a')](_0x2ee47a)[_0x1d01('0x1c')](_0x2ddeed);}};}function respondWithFilteredResult(_0x49066d,_0x433279){return function(_0x3e1ab0){if(_0x3e1ab0){var _0x3f5eb3=typeof _0x433279[_0x1d01('0x1d')]===_0x1d01('0x1e')&&typeof _0x433279[_0x1d01('0x1f')]===_0x1d01('0x1e');var _0x26e01e=_0x3e1ab0[_0x1d01('0x20')];var _0x45364d=_0x3f5eb3?0x0:_0x433279[_0x1d01('0x1d')];var _0x28da35=_0x3f5eb3?_0x3e1ab0[_0x1d01('0x20')]:_0x433279[_0x1d01('0x1d')]+_0x433279[_0x1d01('0x1f')];var _0x32dc8b;if(_0x28da35>=_0x26e01e){_0x28da35=_0x26e01e;_0x32dc8b=0xc8;}else{_0x32dc8b=0xce;}_0x49066d[_0x1d01('0x1a')](_0x32dc8b);return _0x49066d[_0x1d01('0x21')](_0x1d01('0x22'),_0x45364d+'-'+_0x28da35+'/'+_0x26e01e)[_0x1d01('0x1c')](_0x3e1ab0);}return null;};}function patchUpdates(_0xacaaab){return function(_0x5dd7b4){try{jsonpatch[_0x1d01('0x23')](_0x5dd7b4,_0xacaaab,!![]);}catch(_0x47e8d4){return BPromise[_0x1d01('0x24')](_0x47e8d4);}return _0x5dd7b4[_0x1d01('0x25')]();};}function saveUpdates(_0x565f75,_0x42104c){return function(_0x31f846){if(_0x31f846){return _0x31f846[_0x1d01('0x26')](_0x565f75)[_0x1d01('0x27')](function(_0x5358db){return _0x5358db;});}return null;};}function removeEntity(_0xa96e2e,_0x18618a){return function(_0x40ca30){if(_0x40ca30){return _0x40ca30[_0x1d01('0x28')]()['then'](function(){_0xa96e2e[_0x1d01('0x1a')](0xcc)[_0x1d01('0x1b')]();});}};}function handleEntityNotFound(_0x2f936a,_0x4683dd){return function(_0x4fe01e){if(!_0x4fe01e){_0x2f936a[_0x1d01('0x19')](0x194);}return _0x4fe01e;};}function handleError(_0x2aede0,_0x526345){_0x526345=_0x526345||0x1f4;return function(_0x2837cd){logger[_0x1d01('0x29')](_0x2837cd[_0x1d01('0x2a')]);if(_0x2837cd['name']){delete _0x2837cd[_0x1d01('0x2b')];}_0x2aede0[_0x1d01('0x1a')](_0x526345)['send'](_0x2837cd);};}exports[_0x1d01('0x2c')]=function(_0x13f76f,_0x49bfd9){var _0x2ac1b4={},_0x49e8aa={},_0x2fde1b={'count':0x0,'rows':[]};var _0x341e96=_[_0x1d01('0x2d')](db[_0x1d01('0x2e')][_0x1d01('0x2f')],function(_0x4ff685){return{'name':_0x4ff685[_0x1d01('0x30')],'type':_0x4ff685[_0x1d01('0x31')][_0x1d01('0x32')]};});_0x49e8aa[_0x1d01('0x33')]=_[_0x1d01('0x2d')](_0x341e96,_0x1d01('0x2b'));_0x49e8aa[_0x1d01('0x34')]=_[_0x1d01('0x35')](_0x13f76f['query']);_0x49e8aa['filters']=_['intersection'](_0x49e8aa[_0x1d01('0x33')],_0x49e8aa['query']);_0x2ac1b4['attributes']=_[_0x1d01('0x36')](_0x49e8aa[_0x1d01('0x33')],qs[_0x1d01('0x37')](_0x13f76f[_0x1d01('0x34')][_0x1d01('0x37')]));_0x2ac1b4[_0x1d01('0x38')]=_0x2ac1b4[_0x1d01('0x38')][_0x1d01('0x39')]?_0x2ac1b4['attributes']:_0x49e8aa[_0x1d01('0x33')];if(!_0x13f76f['query'][_0x1d01('0x3a')](_0x1d01('0x3b'))){_0x2ac1b4[_0x1d01('0x1f')]=qs[_0x1d01('0x1f')](_0x13f76f[_0x1d01('0x34')][_0x1d01('0x1f')]);_0x2ac1b4[_0x1d01('0x1d')]=qs[_0x1d01('0x1d')](_0x13f76f[_0x1d01('0x34')]['offset']);}_0x2ac1b4[_0x1d01('0x3c')]=qs[_0x1d01('0x3d')](_0x13f76f[_0x1d01('0x34')]['sort']);_0x2ac1b4[_0x1d01('0x3e')]=qs[_0x1d01('0x3f')](_['pick'](_0x13f76f[_0x1d01('0x34')],_0x49e8aa[_0x1d01('0x3f')]),_0x341e96);if(_0x13f76f['query'][_0x1d01('0x40')]){_0x2ac1b4[_0x1d01('0x3e')]=_[_0x1d01('0x41')](_0x2ac1b4[_0x1d01('0x3e')],{'$or':_[_0x1d01('0x2d')](_0x341e96,function(_0x50782a){if(_0x50782a[_0x1d01('0x31')]!==_0x1d01('0x42')){var _0x56459f={};_0x56459f[_0x50782a[_0x1d01('0x2b')]]={'$like':'%'+_0x13f76f[_0x1d01('0x34')][_0x1d01('0x40')]+'%'};return _0x56459f;}})});}_0x2ac1b4=_[_0x1d01('0x41')]({},_0x2ac1b4,_0x13f76f[_0x1d01('0x43')]);var _0x1e768e={'where':_0x2ac1b4[_0x1d01('0x3e')]};return db['SquareReport'][_0x1d01('0x20')](_0x1e768e)[_0x1d01('0x27')](function(_0x1f149e){_0x2fde1b[_0x1d01('0x20')]=_0x1f149e;if(_0x13f76f[_0x1d01('0x34')][_0x1d01('0x44')]){_0x2ac1b4[_0x1d01('0x45')]=[{'all':!![]}];}return db[_0x1d01('0x2e')][_0x1d01('0x46')](_0x2ac1b4);})[_0x1d01('0x27')](function(_0x1024ef){_0x2fde1b[_0x1d01('0x47')]=_0x1024ef;return _0x2fde1b;})[_0x1d01('0x27')](respondWithFilteredResult(_0x49bfd9,_0x2ac1b4))['catch'](handleError(_0x49bfd9,null));};exports[_0x1d01('0x48')]=function(_0xe7d45f,_0xafb524){var _0x584bc8={'raw':!![],'where':{'id':_0xe7d45f['params']['id']}},_0xf96958={};_0xf96958[_0x1d01('0x33')]=_[_0x1d01('0x35')](db['SquareReport'][_0x1d01('0x2f')]);_0xf96958['query']=_[_0x1d01('0x35')](_0xe7d45f['query']);_0xf96958[_0x1d01('0x3f')]=_[_0x1d01('0x36')](_0xf96958[_0x1d01('0x33')],_0xf96958[_0x1d01('0x34')]);_0x584bc8[_0x1d01('0x38')]=_['intersection'](_0xf96958[_0x1d01('0x33')],qs['fields'](_0xe7d45f[_0x1d01('0x34')][_0x1d01('0x37')]));_0x584bc8['attributes']=_0x584bc8[_0x1d01('0x38')]['length']?_0x584bc8[_0x1d01('0x38')]:_0xf96958['model'];if(_0xe7d45f[_0x1d01('0x34')][_0x1d01('0x44')]){_0x584bc8[_0x1d01('0x45')]=[{'all':!![]}];}_0x584bc8=_['merge']({},_0x584bc8,_0xe7d45f[_0x1d01('0x43')]);return db[_0x1d01('0x2e')][_0x1d01('0x49')](_0x584bc8)['then'](handleEntityNotFound(_0xafb524,null))[_0x1d01('0x27')](respondWithResult(_0xafb524,null))[_0x1d01('0x4a')](handleError(_0xafb524,null));};exports['create']=function(_0x3741c7,_0xdb7f90){return db[_0x1d01('0x2e')][_0x1d01('0x4b')](_0x3741c7[_0x1d01('0x4c')],{})[_0x1d01('0x27')](respondWithResult(_0xdb7f90,0xc9))[_0x1d01('0x4a')](handleError(_0xdb7f90,null));};exports[_0x1d01('0x26')]=function(_0x594de6,_0x32e9b6){if(_0x594de6['body']['id']){delete _0x594de6[_0x1d01('0x4c')]['id'];}return db[_0x1d01('0x2e')][_0x1d01('0x49')]({'where':{'id':_0x594de6[_0x1d01('0x4d')]['id']}})[_0x1d01('0x27')](handleEntityNotFound(_0x32e9b6,null))['then'](saveUpdates(_0x594de6[_0x1d01('0x4c')],null))[_0x1d01('0x27')](respondWithResult(_0x32e9b6,null))['catch'](handleError(_0x32e9b6,null));};exports[_0x1d01('0x28')]=function(_0x46368e,_0x1d0da5){return db['SquareReport']['find']({'where':{'id':_0x46368e[_0x1d01('0x4d')]['id']}})[_0x1d01('0x27')](handleEntityNotFound(_0x1d0da5,null))[_0x1d01('0x27')](removeEntity(_0x1d0da5,null))[_0x1d01('0x4a')](handleError(_0x1d0da5,null));};exports['describe']=function(_0x36478f,_0x416532){return db['SquareReport']['describe']()['then'](respondWithResult(_0x416532,null))['catch'](handleError(_0x416532,null));};