2757fef1558e2ce3d902b099c4774f7fbd3e4941
[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 _0xf078=['request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','map','SquareReport','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','findAll','catch','include','find','create','body','params','describe','eml-format','rimraf','fast-json-patch'];(function(_0x53daa0,_0x1000a6){var _0x1231cb=function(_0xeb95a7){while(--_0xeb95a7){_0x53daa0['push'](_0x53daa0['shift']());}};_0x1231cb(++_0x1000a6);}(_0xf078,0x12d));var _0x8f07=function(_0x114aee,_0x2d56bb){_0x114aee=_0x114aee-0x0;var _0x2ac8b6=_0xf078[_0x114aee];return _0x2ac8b6;};'use strict';var emlformat=require(_0x8f07('0x0'));var rimraf=require(_0x8f07('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8f07('0x2'));var rp=require(_0x8f07('0x3'));var moment=require(_0x8f07('0x4'));var BPromise=require(_0x8f07('0x5'));var Mustache=require(_0x8f07('0x6'));var util=require(_0x8f07('0x7'));var path=require(_0x8f07('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x8f07('0x9'));var fs=require('fs');var fs_extra=require(_0x8f07('0xa'));var _=require(_0x8f07('0xb'));var squel=require('squel');var crypto=require(_0x8f07('0xc'));var jsforce=require(_0x8f07('0xd'));var deskjs=require(_0x8f07('0xe'));var toCsv=require(_0x8f07('0xf'));var querystring=require(_0x8f07('0x10'));var Papa=require(_0x8f07('0x11'));var Redis=require(_0x8f07('0x12'));var authService=require(_0x8f07('0x13'));var qs=require(_0x8f07('0x14'));var as=require(_0x8f07('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x8f07('0x16'));var utils=require(_0x8f07('0x17'));var config=require(_0x8f07('0x18'));var licenseUtil=require(_0x8f07('0x19'));var db=require(_0x8f07('0x1a'))['db'];function respondWithStatusCode(_0x506faa,_0x475754){_0x475754=_0x475754||0xcc;return function(_0x348d53){if(_0x348d53){return _0x506faa['sendStatus'](_0x475754);}return _0x506faa[_0x8f07('0x1b')](_0x475754)[_0x8f07('0x1c')]();};}function respondWithResult(_0x3f48ca,_0x2b15a5){_0x2b15a5=_0x2b15a5||0xc8;return function(_0x1d8e3d){if(_0x1d8e3d){return _0x3f48ca[_0x8f07('0x1b')](_0x2b15a5)['json'](_0x1d8e3d);}};}function respondWithFilteredResult(_0x5104cc,_0x25add9){return function(_0xc10502){if(_0xc10502){var _0x406878=typeof _0x25add9['offset']===_0x8f07('0x1d')&&typeof _0x25add9[_0x8f07('0x1e')]===_0x8f07('0x1d');var _0x5bdcae=_0xc10502[_0x8f07('0x1f')];var _0x4d7584=_0x406878?0x0:_0x25add9[_0x8f07('0x20')];var _0x5f227d=_0x406878?_0xc10502[_0x8f07('0x1f')]:_0x25add9[_0x8f07('0x20')]+_0x25add9['limit'];var _0x5f2326;if(_0x5f227d>=_0x5bdcae){_0x5f227d=_0x5bdcae;_0x5f2326=0xc8;}else{_0x5f2326=0xce;}_0x5104cc[_0x8f07('0x1b')](_0x5f2326);return _0x5104cc[_0x8f07('0x21')](_0x8f07('0x22'),_0x4d7584+'-'+_0x5f227d+'/'+_0x5bdcae)['json'](_0xc10502);}return null;};}function patchUpdates(_0x313b64){return function(_0x1c63c8){try{jsonpatch[_0x8f07('0x23')](_0x1c63c8,_0x313b64,!![]);}catch(_0x40c7bf){return BPromise[_0x8f07('0x24')](_0x40c7bf);}return _0x1c63c8[_0x8f07('0x25')]();};}function saveUpdates(_0x544784,_0x627d05){return function(_0x14fb35){if(_0x14fb35){return _0x14fb35[_0x8f07('0x26')](_0x544784)[_0x8f07('0x27')](function(_0xf000de){return _0xf000de;});}return null;};}function removeEntity(_0xe4a7b,_0x1b3aad){return function(_0x2ab0ca){if(_0x2ab0ca){return _0x2ab0ca[_0x8f07('0x28')]()[_0x8f07('0x27')](function(){_0xe4a7b[_0x8f07('0x1b')](0xcc)[_0x8f07('0x1c')]();});}};}function handleEntityNotFound(_0x6ff530,_0x449dcc){return function(_0x5992c6){if(!_0x5992c6){_0x6ff530['sendStatus'](0x194);}return _0x5992c6;};}function handleError(_0x3fa8dd,_0x22aed7){_0x22aed7=_0x22aed7||0x1f4;return function(_0x5fbe69){logger[_0x8f07('0x29')](_0x5fbe69[_0x8f07('0x2a')]);if(_0x5fbe69[_0x8f07('0x2b')]){delete _0x5fbe69[_0x8f07('0x2b')];}_0x3fa8dd[_0x8f07('0x1b')](_0x22aed7)[_0x8f07('0x2c')](_0x5fbe69);};}exports['index']=function(_0x6504d7,_0x48255f){var _0x16b9be={},_0x5c99ec={},_0x4db5b9={'count':0x0,'rows':[]};var _0x41a9df=_[_0x8f07('0x2d')](db[_0x8f07('0x2e')][_0x8f07('0x2f')],function(_0x4e58ee){return{'name':_0x4e58ee[_0x8f07('0x30')],'type':_0x4e58ee['type'][_0x8f07('0x31')]};});_0x5c99ec[_0x8f07('0x32')]=_[_0x8f07('0x2d')](_0x41a9df,'name');_0x5c99ec['query']=_[_0x8f07('0x33')](_0x6504d7[_0x8f07('0x34')]);_0x5c99ec[_0x8f07('0x35')]=_[_0x8f07('0x36')](_0x5c99ec[_0x8f07('0x32')],_0x5c99ec[_0x8f07('0x34')]);_0x16b9be[_0x8f07('0x37')]=_[_0x8f07('0x36')](_0x5c99ec[_0x8f07('0x32')],qs['fields'](_0x6504d7[_0x8f07('0x34')][_0x8f07('0x38')]));_0x16b9be['attributes']=_0x16b9be[_0x8f07('0x37')][_0x8f07('0x39')]?_0x16b9be[_0x8f07('0x37')]:_0x5c99ec['model'];if(!_0x6504d7[_0x8f07('0x34')][_0x8f07('0x3a')](_0x8f07('0x3b'))){_0x16b9be['limit']=qs[_0x8f07('0x1e')](_0x6504d7['query'][_0x8f07('0x1e')]);_0x16b9be[_0x8f07('0x20')]=qs[_0x8f07('0x20')](_0x6504d7[_0x8f07('0x34')][_0x8f07('0x20')]);}_0x16b9be[_0x8f07('0x3c')]=qs[_0x8f07('0x3d')](_0x6504d7['query']['sort']);_0x16b9be[_0x8f07('0x3e')]=qs[_0x8f07('0x35')](_[_0x8f07('0x3f')](_0x6504d7[_0x8f07('0x34')],_0x5c99ec['filters']),_0x41a9df);if(_0x6504d7[_0x8f07('0x34')][_0x8f07('0x40')]){_0x16b9be[_0x8f07('0x3e')]=_[_0x8f07('0x41')](_0x16b9be[_0x8f07('0x3e')],{'$or':_['map'](_0x41a9df,function(_0x16a580){if(_0x16a580['type']!=='VIRTUAL'){var _0x68c3ca={};_0x68c3ca[_0x16a580[_0x8f07('0x2b')]]={'$like':'%'+_0x6504d7['query'][_0x8f07('0x40')]+'%'};return _0x68c3ca;}})});}_0x16b9be=_[_0x8f07('0x41')]({},_0x16b9be,_0x6504d7[_0x8f07('0x42')]);var _0x52c790={'where':_0x16b9be[_0x8f07('0x3e')]};return db['SquareReport']['count'](_0x52c790)[_0x8f07('0x27')](function(_0x177af2){_0x4db5b9['count']=_0x177af2;if(_0x6504d7[_0x8f07('0x34')][_0x8f07('0x43')]){_0x16b9be['include']=[{'all':!![]}];}return db[_0x8f07('0x2e')][_0x8f07('0x44')](_0x16b9be);})[_0x8f07('0x27')](function(_0x36b872){_0x4db5b9['rows']=_0x36b872;return _0x4db5b9;})[_0x8f07('0x27')](respondWithFilteredResult(_0x48255f,_0x16b9be))[_0x8f07('0x45')](handleError(_0x48255f,null));};exports['show']=function(_0x464f8e,_0x58cdf0){var _0x449a9a={'raw':!![],'where':{'id':_0x464f8e['params']['id']}},_0x5c214f={};_0x5c214f['model']=_[_0x8f07('0x33')](db[_0x8f07('0x2e')][_0x8f07('0x2f')]);_0x5c214f[_0x8f07('0x34')]=_[_0x8f07('0x33')](_0x464f8e[_0x8f07('0x34')]);_0x5c214f['filters']=_[_0x8f07('0x36')](_0x5c214f[_0x8f07('0x32')],_0x5c214f[_0x8f07('0x34')]);_0x449a9a[_0x8f07('0x37')]=_[_0x8f07('0x36')](_0x5c214f[_0x8f07('0x32')],qs['fields'](_0x464f8e[_0x8f07('0x34')]['fields']));_0x449a9a[_0x8f07('0x37')]=_0x449a9a[_0x8f07('0x37')][_0x8f07('0x39')]?_0x449a9a[_0x8f07('0x37')]:_0x5c214f[_0x8f07('0x32')];if(_0x464f8e[_0x8f07('0x34')][_0x8f07('0x43')]){_0x449a9a[_0x8f07('0x46')]=[{'all':!![]}];}_0x449a9a=_[_0x8f07('0x41')]({},_0x449a9a,_0x464f8e['options']);return db[_0x8f07('0x2e')][_0x8f07('0x47')](_0x449a9a)[_0x8f07('0x27')](handleEntityNotFound(_0x58cdf0,null))['then'](respondWithResult(_0x58cdf0,null))[_0x8f07('0x45')](handleError(_0x58cdf0,null));};exports[_0x8f07('0x48')]=function(_0x502f43,_0x4ff656){return db[_0x8f07('0x2e')]['create'](_0x502f43['body'],{})['then'](respondWithResult(_0x4ff656,0xc9))[_0x8f07('0x45')](handleError(_0x4ff656,null));};exports['update']=function(_0x22b4e6,_0x1262cd){if(_0x22b4e6[_0x8f07('0x49')]['id']){delete _0x22b4e6['body']['id'];}return db['SquareReport'][_0x8f07('0x47')]({'where':{'id':_0x22b4e6[_0x8f07('0x4a')]['id']}})[_0x8f07('0x27')](handleEntityNotFound(_0x1262cd,null))[_0x8f07('0x27')](saveUpdates(_0x22b4e6[_0x8f07('0x49')],null))['then'](respondWithResult(_0x1262cd,null))[_0x8f07('0x45')](handleError(_0x1262cd,null));};exports[_0x8f07('0x28')]=function(_0x4d3dad,_0x85ff33){return db[_0x8f07('0x2e')]['find']({'where':{'id':_0x4d3dad[_0x8f07('0x4a')]['id']}})[_0x8f07('0x27')](handleEntityNotFound(_0x85ff33,null))[_0x8f07('0x27')](removeEntity(_0x85ff33,null))[_0x8f07('0x45')](handleError(_0x85ff33,null));};exports[_0x8f07('0x4b')]=function(_0xcf9a55,_0x5c1d65){return db['SquareReport']['describe']()[_0x8f07('0x27')](respondWithResult(_0x5c1d65,null))['catch'](handleError(_0x5c1d65,null));};