0341880a8c6405d6050edb5b5be9f624c669a2c7
[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 _0xfbf9=['hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL','include','findAll','rows','catch','show','params','includeAll','options','find','create','body','describe','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','offset','limit','Content-Range','reject','save','update','then','destroy','error','stack','name','index','map','SquareReport','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length'];(function(_0x4e3656,_0x36b315){var _0x313a1a=function(_0x417421){while(--_0x417421){_0x4e3656['push'](_0x4e3656['shift']());}};_0x313a1a(++_0x36b315);}(_0xfbf9,0xa6));var _0x9fbf=function(_0x481c41,_0x48ba3c){_0x481c41=_0x481c41-0x0;var _0xf91fd=_0xfbf9[_0x481c41];return _0xf91fd;};'use strict';var pdf=require(_0x9fbf('0x0'));var emlformat=require(_0x9fbf('0x1'));var rimraf=require(_0x9fbf('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9fbf('0x3'));var rp=require(_0x9fbf('0x4'));var moment=require(_0x9fbf('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x9fbf('0x6'));var util=require(_0x9fbf('0x7'));var path=require(_0x9fbf('0x8'));var sox=require('sox');var csv=require(_0x9fbf('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x9fbf('0xa'));var squel=require('squel');var crypto=require(_0x9fbf('0xb'));var jsforce=require(_0x9fbf('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x9fbf('0x9'));var querystring=require('querystring');var Papa=require(_0x9fbf('0xd'));var Redis=require(_0x9fbf('0xe'));var authService=require(_0x9fbf('0xf'));var qs=require(_0x9fbf('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9fbf('0x11'));var logger=require('../../config/logger')(_0x9fbf('0x12'));var utils=require(_0x9fbf('0x13'));var config=require(_0x9fbf('0x14'));var db=require(_0x9fbf('0x15'))['db'];function respondWithStatusCode(_0xe56287,_0x32581a){_0x32581a=_0x32581a||0xcc;return function(_0x4ae5b1){if(_0x4ae5b1){return _0xe56287[_0x9fbf('0x16')](_0x32581a);}return _0xe56287['status'](_0x32581a)[_0x9fbf('0x17')]();};}function respondWithResult(_0x283245,_0x50d037){_0x50d037=_0x50d037||0xc8;return function(_0x3778e6){if(_0x3778e6){return _0x283245[_0x9fbf('0x18')](_0x50d037)[_0x9fbf('0x19')](_0x3778e6);}};}function respondWithFilteredResult(_0x27e72e,_0x5b874b){return function(_0x1b06f8){if(_0x1b06f8){var _0x45403e=_0x1b06f8[_0x9fbf('0x1a')],_0x5b5d5d=_0x5b874b[_0x9fbf('0x1b')],_0xc01db4=_0x5b874b[_0x9fbf('0x1b')]+_0x5b874b[_0x9fbf('0x1c')],_0x4679aa;if(_0xc01db4>=_0x45403e){_0xc01db4=_0x45403e;_0x4679aa=0xc8;}else{_0x4679aa=0xce;}_0x27e72e[_0x9fbf('0x18')](_0x4679aa);return _0x27e72e['set'](_0x9fbf('0x1d'),_0x5b5d5d+'-'+_0xc01db4+'/'+_0x45403e)[_0x9fbf('0x19')](_0x1b06f8);}return null;};}function patchUpdates(_0x5babc9){return function(_0x386872){try{jsonpatch['apply'](_0x386872,_0x5babc9,!![]);}catch(_0xffd4fc){return BPromise[_0x9fbf('0x1e')](_0xffd4fc);}return _0x386872[_0x9fbf('0x1f')]();};}function saveUpdates(_0x4df859,_0x4350a0){return function(_0x3fff29){if(_0x3fff29){return _0x3fff29[_0x9fbf('0x20')](_0x4df859)[_0x9fbf('0x21')](function(_0x12fe2e){return _0x12fe2e;});}return null;};}function removeEntity(_0x13df57,_0x4d604c){return function(_0x51af17){if(_0x51af17){return _0x51af17[_0x9fbf('0x22')]()[_0x9fbf('0x21')](function(){_0x13df57['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x1ac3d3,_0x571c58){return function(_0x68dbde){if(!_0x68dbde){_0x1ac3d3['sendStatus'](0x194);}return _0x68dbde;};}function handleError(_0x168074,_0x225dfe){_0x225dfe=_0x225dfe||0x1f4;return function(_0x340411){logger[_0x9fbf('0x23')](_0x340411[_0x9fbf('0x24')]);if(_0x340411['name']){delete _0x340411[_0x9fbf('0x25')];}_0x168074[_0x9fbf('0x18')](_0x225dfe)['send'](_0x340411);};}exports[_0x9fbf('0x26')]=function(_0x5cbc9b,_0x29e62f){var _0x167f21={},_0x3a47ed={},_0x1bb3bb={'count':0x0,'rows':[]};var _0x200f75=_[_0x9fbf('0x27')](db[_0x9fbf('0x28')][_0x9fbf('0x29')],function(_0x163e85){return{'name':_0x163e85[_0x9fbf('0x2a')],'type':_0x163e85[_0x9fbf('0x2b')][_0x9fbf('0x2c')]};});_0x3a47ed[_0x9fbf('0x2d')]=_[_0x9fbf('0x27')](_0x200f75,_0x9fbf('0x25'));_0x3a47ed['query']=_[_0x9fbf('0x2e')](_0x5cbc9b[_0x9fbf('0x2f')]);_0x3a47ed[_0x9fbf('0x30')]=_[_0x9fbf('0x31')](_0x3a47ed[_0x9fbf('0x2d')],_0x3a47ed[_0x9fbf('0x2f')]);_0x167f21[_0x9fbf('0x32')]=_[_0x9fbf('0x31')](_0x3a47ed['model'],qs[_0x9fbf('0x33')](_0x5cbc9b[_0x9fbf('0x2f')][_0x9fbf('0x33')]));_0x167f21['attributes']=_0x167f21[_0x9fbf('0x32')][_0x9fbf('0x34')]?_0x167f21[_0x9fbf('0x32')]:_0x3a47ed['model'];if(!_0x5cbc9b['query'][_0x9fbf('0x35')](_0x9fbf('0x36'))){_0x167f21[_0x9fbf('0x1c')]=qs[_0x9fbf('0x1c')](_0x5cbc9b['query']['limit']);_0x167f21[_0x9fbf('0x1b')]=qs[_0x9fbf('0x1b')](_0x5cbc9b['query']['offset']);}_0x167f21['order']=qs[_0x9fbf('0x37')](_0x5cbc9b[_0x9fbf('0x2f')][_0x9fbf('0x37')]);_0x167f21['where']=qs['filters'](_[_0x9fbf('0x38')](_0x5cbc9b[_0x9fbf('0x2f')],_0x3a47ed[_0x9fbf('0x30')]),_0x200f75);if(_0x5cbc9b[_0x9fbf('0x2f')][_0x9fbf('0x39')]){_0x167f21[_0x9fbf('0x3a')]=_[_0x9fbf('0x3b')](_0x167f21['where'],{'$or':_[_0x9fbf('0x27')](_0x200f75,function(_0x24c7f5){if(_0x24c7f5[_0x9fbf('0x2b')]!==_0x9fbf('0x3c')){var _0x458759={};_0x458759[_0x24c7f5[_0x9fbf('0x25')]]={'$like':'%'+_0x5cbc9b[_0x9fbf('0x2f')][_0x9fbf('0x39')]+'%'};return _0x458759;}})});}_0x167f21=_[_0x9fbf('0x3b')]({},_0x167f21,_0x5cbc9b['options']);var _0x50c75c={'where':_0x167f21['where']};return db[_0x9fbf('0x28')][_0x9fbf('0x1a')](_0x50c75c)['then'](function(_0x20ce32){_0x1bb3bb[_0x9fbf('0x1a')]=_0x20ce32;if(_0x5cbc9b[_0x9fbf('0x2f')]['includeAll']){_0x167f21[_0x9fbf('0x3d')]=[{'all':!![]}];}return db['SquareReport'][_0x9fbf('0x3e')](_0x167f21);})['then'](function(_0x3ef002){_0x1bb3bb[_0x9fbf('0x3f')]=_0x3ef002;return _0x1bb3bb;})[_0x9fbf('0x21')](respondWithFilteredResult(_0x29e62f,_0x167f21))[_0x9fbf('0x40')](handleError(_0x29e62f,null));};exports[_0x9fbf('0x41')]=function(_0x478d36,_0x182102){var _0x193168={'raw':!![],'where':{'id':_0x478d36[_0x9fbf('0x42')]['id']}},_0x58f830={};_0x58f830[_0x9fbf('0x2d')]=_[_0x9fbf('0x2e')](db[_0x9fbf('0x28')][_0x9fbf('0x29')]);_0x58f830[_0x9fbf('0x2f')]=_[_0x9fbf('0x2e')](_0x478d36['query']);_0x58f830[_0x9fbf('0x30')]=_[_0x9fbf('0x31')](_0x58f830[_0x9fbf('0x2d')],_0x58f830[_0x9fbf('0x2f')]);_0x193168[_0x9fbf('0x32')]=_['intersection'](_0x58f830[_0x9fbf('0x2d')],qs[_0x9fbf('0x33')](_0x478d36[_0x9fbf('0x2f')][_0x9fbf('0x33')]));_0x193168[_0x9fbf('0x32')]=_0x193168[_0x9fbf('0x32')][_0x9fbf('0x34')]?_0x193168[_0x9fbf('0x32')]:_0x58f830[_0x9fbf('0x2d')];if(_0x478d36[_0x9fbf('0x2f')][_0x9fbf('0x43')]){_0x193168[_0x9fbf('0x3d')]=[{'all':!![]}];}_0x193168=_[_0x9fbf('0x3b')]({},_0x193168,_0x478d36[_0x9fbf('0x44')]);return db[_0x9fbf('0x28')][_0x9fbf('0x45')](_0x193168)[_0x9fbf('0x21')](handleEntityNotFound(_0x182102,null))[_0x9fbf('0x21')](respondWithResult(_0x182102,null))[_0x9fbf('0x40')](handleError(_0x182102,null));};exports[_0x9fbf('0x46')]=function(_0xf920ad,_0x335ab9){return db[_0x9fbf('0x28')][_0x9fbf('0x46')](_0xf920ad[_0x9fbf('0x47')],{})[_0x9fbf('0x21')](respondWithResult(_0x335ab9,0xc9))[_0x9fbf('0x40')](handleError(_0x335ab9,null));};exports['update']=function(_0x2b38dd,_0x3d3f92){if(_0x2b38dd[_0x9fbf('0x47')]['id']){delete _0x2b38dd[_0x9fbf('0x47')]['id'];}return db[_0x9fbf('0x28')][_0x9fbf('0x45')]({'where':{'id':_0x2b38dd['params']['id']}})[_0x9fbf('0x21')](handleEntityNotFound(_0x3d3f92,null))['then'](saveUpdates(_0x2b38dd[_0x9fbf('0x47')],null))[_0x9fbf('0x21')](respondWithResult(_0x3d3f92,null))['catch'](handleError(_0x3d3f92,null));};exports['destroy']=function(_0xb408a6,_0x202b89){return db[_0x9fbf('0x28')][_0x9fbf('0x45')]({'where':{'id':_0xb408a6[_0x9fbf('0x42')]['id']}})[_0x9fbf('0x21')](handleEntityNotFound(_0x202b89,null))[_0x9fbf('0x21')](removeEntity(_0x202b89,null))[_0x9fbf('0x40')](handleError(_0x202b89,null));};exports[_0x9fbf('0x48')]=function(_0x3993ae,_0x2f735e){return db[_0x9fbf('0x28')]['describe']()[_0x9fbf('0x21')](respondWithResult(_0x2f735e,null))[_0x9fbf('0x40')](handleError(_0x2f735e,null));};