Built motion from commit 10af8726.|2.6.34
[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 _0x7f33=['keys','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','merge','map','VIRTUAL','filter','options','includeAll','include','rawAttributes','find','catch','create','body','params','describe','eml-format','fast-json-patch','request-promise','bluebird','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','reject','save','update','then','destroy','error','stack','name','send','SquareReport','fieldName','type','key','model'];(function(_0x43eee1,_0x5a020b){var _0x42e2b7=function(_0x466399){while(--_0x466399){_0x43eee1['push'](_0x43eee1['shift']());}};_0x42e2b7(++_0x5a020b);}(_0x7f33,0x188));var _0x37f3=function(_0x4b2f7f,_0x2cd623){_0x4b2f7f=_0x4b2f7f-0x0;var _0x19d04d=_0x7f33[_0x4b2f7f];return _0x19d04d;};'use strict';var emlformat=require(_0x37f3('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x37f3('0x1'));var rp=require(_0x37f3('0x2'));var moment=require('moment');var BPromise=require(_0x37f3('0x3'));var Mustache=require('mustache');var util=require(_0x37f3('0x4'));var path=require('path');var sox=require(_0x37f3('0x5'));var csv=require(_0x37f3('0x6'));var ejs=require(_0x37f3('0x7'));var fs=require('fs');var fs_extra=require(_0x37f3('0x8'));var _=require(_0x37f3('0x9'));var squel=require(_0x37f3('0xa'));var crypto=require(_0x37f3('0xb'));var jsforce=require(_0x37f3('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x37f3('0x6'));var querystring=require(_0x37f3('0xd'));var Papa=require('papaparse');var Redis=require(_0x37f3('0xe'));var authService=require(_0x37f3('0xf'));var qs=require(_0x37f3('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x37f3('0x11'));var logger=require(_0x37f3('0x12'))(_0x37f3('0x13'));var utils=require(_0x37f3('0x14'));var config=require(_0x37f3('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x37f3('0x16'))['db'];function respondWithStatusCode(_0x1359fe,_0x2d78aa){_0x2d78aa=_0x2d78aa||0xcc;return function(_0x1d147b){if(_0x1d147b){return _0x1359fe[_0x37f3('0x17')](_0x2d78aa);}return _0x1359fe[_0x37f3('0x18')](_0x2d78aa)[_0x37f3('0x19')]();};}function respondWithResult(_0x503edf,_0x53dc04){_0x53dc04=_0x53dc04||0xc8;return function(_0x1ad948){if(_0x1ad948){return _0x503edf[_0x37f3('0x18')](_0x53dc04)[_0x37f3('0x1a')](_0x1ad948);}};}function respondWithFilteredResult(_0x30eed1,_0x43bdb8){return function(_0x1a910b){if(_0x1a910b){var _0x84c6ad=typeof _0x43bdb8[_0x37f3('0x1b')]===_0x37f3('0x1c')&&typeof _0x43bdb8[_0x37f3('0x1d')]==='undefined';var _0x27193f=_0x1a910b['count'];var _0x20d4c8=_0x84c6ad?0x0:_0x43bdb8[_0x37f3('0x1b')];var _0x44b6d7=_0x84c6ad?_0x1a910b[_0x37f3('0x1e')]:_0x43bdb8[_0x37f3('0x1b')]+_0x43bdb8['limit'];var _0x2691aa;if(_0x44b6d7>=_0x27193f){_0x44b6d7=_0x27193f;_0x2691aa=0xc8;}else{_0x2691aa=0xce;}_0x30eed1[_0x37f3('0x18')](_0x2691aa);return _0x30eed1[_0x37f3('0x1f')]('Content-Range',_0x20d4c8+'-'+_0x44b6d7+'/'+_0x27193f)[_0x37f3('0x1a')](_0x1a910b);}return null;};}function patchUpdates(_0x368135){return function(_0x17ad60){try{jsonpatch['apply'](_0x17ad60,_0x368135,!![]);}catch(_0x4ae6bb){return BPromise[_0x37f3('0x20')](_0x4ae6bb);}return _0x17ad60[_0x37f3('0x21')]();};}function saveUpdates(_0x10f7c5,_0x4e8eb4){return function(_0x419de4){if(_0x419de4){return _0x419de4[_0x37f3('0x22')](_0x10f7c5)[_0x37f3('0x23')](function(_0xb9ec7c){return _0xb9ec7c;});}return null;};}function removeEntity(_0x29959c,_0x460c4c){return function(_0x455568){if(_0x455568){return _0x455568[_0x37f3('0x24')]()[_0x37f3('0x23')](function(){_0x29959c['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x143a52,_0xfa32b5){return function(_0x419bd7){if(!_0x419bd7){_0x143a52[_0x37f3('0x17')](0x194);}return _0x419bd7;};}function handleError(_0x2e8955,_0x36c96e){_0x36c96e=_0x36c96e||0x1f4;return function(_0x486020){logger[_0x37f3('0x25')](_0x486020[_0x37f3('0x26')]);if(_0x486020[_0x37f3('0x27')]){delete _0x486020[_0x37f3('0x27')];}_0x2e8955[_0x37f3('0x18')](_0x36c96e)[_0x37f3('0x28')](_0x486020);};}exports['index']=function(_0x340e02,_0x4940e1){var _0x1f7ff2={},_0x839a7={},_0x282e36={'count':0x0,'rows':[]};var _0x670cab=_['map'](db[_0x37f3('0x29')]['rawAttributes'],function(_0x36d2c6){return{'name':_0x36d2c6[_0x37f3('0x2a')],'type':_0x36d2c6[_0x37f3('0x2b')][_0x37f3('0x2c')]};});_0x839a7[_0x37f3('0x2d')]=_['map'](_0x670cab,_0x37f3('0x27'));_0x839a7['query']=_[_0x37f3('0x2e')](_0x340e02[_0x37f3('0x2f')]);_0x839a7['filters']=_['intersection'](_0x839a7[_0x37f3('0x2d')],_0x839a7[_0x37f3('0x2f')]);_0x1f7ff2[_0x37f3('0x30')]=_[_0x37f3('0x31')](_0x839a7[_0x37f3('0x2d')],qs[_0x37f3('0x32')](_0x340e02[_0x37f3('0x2f')]['fields']));_0x1f7ff2[_0x37f3('0x30')]=_0x1f7ff2[_0x37f3('0x30')][_0x37f3('0x33')]?_0x1f7ff2[_0x37f3('0x30')]:_0x839a7[_0x37f3('0x2d')];if(!_0x340e02[_0x37f3('0x2f')][_0x37f3('0x34')](_0x37f3('0x35'))){_0x1f7ff2['limit']=qs[_0x37f3('0x1d')](_0x340e02[_0x37f3('0x2f')][_0x37f3('0x1d')]);_0x1f7ff2[_0x37f3('0x1b')]=qs[_0x37f3('0x1b')](_0x340e02['query'][_0x37f3('0x1b')]);}_0x1f7ff2[_0x37f3('0x36')]=qs[_0x37f3('0x37')](_0x340e02['query'][_0x37f3('0x37')]);_0x1f7ff2[_0x37f3('0x38')]=qs[_0x37f3('0x39')](_[_0x37f3('0x3a')](_0x340e02[_0x37f3('0x2f')],_0x839a7[_0x37f3('0x39')]),_0x670cab);if(_0x340e02[_0x37f3('0x2f')]['filter']){_0x1f7ff2[_0x37f3('0x38')]=_[_0x37f3('0x3b')](_0x1f7ff2[_0x37f3('0x38')],{'$or':_[_0x37f3('0x3c')](_0x670cab,function(_0x50d501){if(_0x50d501[_0x37f3('0x2b')]!==_0x37f3('0x3d')){var _0x5a019b={};_0x5a019b[_0x50d501[_0x37f3('0x27')]]={'$like':'%'+_0x340e02[_0x37f3('0x2f')][_0x37f3('0x3e')]+'%'};return _0x5a019b;}})});}_0x1f7ff2=_['merge']({},_0x1f7ff2,_0x340e02[_0x37f3('0x3f')]);var _0x440d78={'where':_0x1f7ff2['where']};return db[_0x37f3('0x29')][_0x37f3('0x1e')](_0x440d78)[_0x37f3('0x23')](function(_0x48ead3){_0x282e36[_0x37f3('0x1e')]=_0x48ead3;if(_0x340e02[_0x37f3('0x2f')][_0x37f3('0x40')]){_0x1f7ff2[_0x37f3('0x41')]=[{'all':!![]}];}return db['SquareReport']['findAll'](_0x1f7ff2);})[_0x37f3('0x23')](function(_0x363eec){_0x282e36['rows']=_0x363eec;return _0x282e36;})[_0x37f3('0x23')](respondWithFilteredResult(_0x4940e1,_0x1f7ff2))['catch'](handleError(_0x4940e1,null));};exports['show']=function(_0x4cd52d,_0xb53d97){var _0x87c643={'raw':!![],'where':{'id':_0x4cd52d['params']['id']}},_0x227e41={};_0x227e41['model']=_['keys'](db['SquareReport'][_0x37f3('0x42')]);_0x227e41[_0x37f3('0x2f')]=_['keys'](_0x4cd52d[_0x37f3('0x2f')]);_0x227e41['filters']=_[_0x37f3('0x31')](_0x227e41[_0x37f3('0x2d')],_0x227e41[_0x37f3('0x2f')]);_0x87c643[_0x37f3('0x30')]=_[_0x37f3('0x31')](_0x227e41[_0x37f3('0x2d')],qs['fields'](_0x4cd52d[_0x37f3('0x2f')][_0x37f3('0x32')]));_0x87c643[_0x37f3('0x30')]=_0x87c643[_0x37f3('0x30')]['length']?_0x87c643[_0x37f3('0x30')]:_0x227e41[_0x37f3('0x2d')];if(_0x4cd52d['query'][_0x37f3('0x40')]){_0x87c643[_0x37f3('0x41')]=[{'all':!![]}];}_0x87c643=_[_0x37f3('0x3b')]({},_0x87c643,_0x4cd52d['options']);return db[_0x37f3('0x29')][_0x37f3('0x43')](_0x87c643)['then'](handleEntityNotFound(_0xb53d97,null))[_0x37f3('0x23')](respondWithResult(_0xb53d97,null))[_0x37f3('0x44')](handleError(_0xb53d97,null));};exports[_0x37f3('0x45')]=function(_0x3056c5,_0x5984c0){return db[_0x37f3('0x29')][_0x37f3('0x45')](_0x3056c5['body'],{})[_0x37f3('0x23')](respondWithResult(_0x5984c0,0xc9))['catch'](handleError(_0x5984c0,null));};exports[_0x37f3('0x22')]=function(_0x4eef83,_0x49928e){if(_0x4eef83['body']['id']){delete _0x4eef83['body']['id'];}return db[_0x37f3('0x29')][_0x37f3('0x43')]({'where':{'id':_0x4eef83['params']['id']}})[_0x37f3('0x23')](handleEntityNotFound(_0x49928e,null))[_0x37f3('0x23')](saveUpdates(_0x4eef83[_0x37f3('0x46')],null))[_0x37f3('0x23')](respondWithResult(_0x49928e,null))[_0x37f3('0x44')](handleError(_0x49928e,null));};exports[_0x37f3('0x24')]=function(_0x4e2cd8,_0x103b65){return db[_0x37f3('0x29')][_0x37f3('0x43')]({'where':{'id':_0x4e2cd8[_0x37f3('0x47')]['id']}})[_0x37f3('0x23')](handleEntityNotFound(_0x103b65,null))[_0x37f3('0x23')](removeEntity(_0x103b65,null))[_0x37f3('0x44')](handleError(_0x103b65,null));};exports[_0x37f3('0x48')]=function(_0x4aedfd,_0xb9eb63){return db[_0x37f3('0x29')]['describe']()[_0x37f3('0x23')](respondWithResult(_0xb9eb63,null))[_0x37f3('0x44')](handleError(_0xb9eb63,null));};