Built motion from commit (unavailable).|2.3.3
[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 _0x3f91=['options','count','includeAll','include','rows','catch','show','create','body','update','params','find','describe','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../components/parsers/qs','../../config/logger','api','../../config/environment','sendStatus','status','json','offset','limit','set','Content-Range','reject','then','destroy','end','error','stack','name','send','SquareReport','rawAttributes','model','query','keys','intersection','fields','attributes','length','nolimit','order','sort','where','filters','map','type','field','filter','merge'];(function(_0x40bffc,_0x3a45d7){var _0x3007e9=function(_0x4c8fda){while(--_0x4c8fda){_0x40bffc['push'](_0x40bffc['shift']());}};_0x3007e9(++_0x3a45d7);}(_0x3f91,0x99));var _0x13f9=function(_0x3d42d8,_0x4cffaa){_0x3d42d8=_0x3d42d8-0x0;var _0x27fc41=_0x3f91[_0x3d42d8];return _0x27fc41;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x13f9('0x0'));var zipdir=require(_0x13f9('0x1'));var jsonpatch=require(_0x13f9('0x2'));var rp=require('request-promise');var moment=require(_0x13f9('0x3'));var BPromise=require(_0x13f9('0x4'));var Mustache=require(_0x13f9('0x5'));var util=require(_0x13f9('0x6'));var path=require(_0x13f9('0x7'));var sox=require(_0x13f9('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x13f9('0x9'));var squel=require(_0x13f9('0xa'));var crypto=require(_0x13f9('0xb'));var jsforce=require(_0x13f9('0xc'));var deskjs=require(_0x13f9('0xd'));var toCsv=require(_0x13f9('0xe'));var querystring=require(_0x13f9('0xf'));var Papa=require(_0x13f9('0x10'));var authService=require(_0x13f9('0x11'));var hardwareService=require(_0x13f9('0x12'));var Redis=require('ioredis');var qs=require(_0x13f9('0x13'));var logger=require(_0x13f9('0x14'))(_0x13f9('0x15'));var utils=require('../../config/utils');var config=require(_0x13f9('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x11fbfa,_0x5b6d44){_0x5b6d44=_0x5b6d44||0xcc;return function(_0x43cad3){if(_0x43cad3){return _0x11fbfa[_0x13f9('0x17')](_0x5b6d44);}return _0x11fbfa[_0x13f9('0x18')](_0x5b6d44)['end']();};}function respondWithResult(_0x409bc7,_0x1df23d){_0x1df23d=_0x1df23d||0xc8;return function(_0x469942){if(_0x469942){return _0x409bc7[_0x13f9('0x18')](_0x1df23d)[_0x13f9('0x19')](_0x469942);}};}function respondWithFilteredResult(_0x5e0c6e,_0x594b1e){return function(_0x410b57){if(_0x410b57){var _0x103e32=_0x410b57['count'],_0x2cc4cf=_0x594b1e[_0x13f9('0x1a')],_0x3783c5=_0x594b1e[_0x13f9('0x1a')]+_0x594b1e[_0x13f9('0x1b')],_0x5cbb51;if(_0x3783c5>=_0x103e32){_0x3783c5=_0x103e32;_0x5cbb51=0xc8;}else{_0x5cbb51=0xce;}_0x5e0c6e[_0x13f9('0x18')](_0x5cbb51);return _0x5e0c6e[_0x13f9('0x1c')](_0x13f9('0x1d'),_0x2cc4cf+'-'+_0x3783c5+'/'+_0x103e32)[_0x13f9('0x19')](_0x410b57);}return null;};}function patchUpdates(_0xa33c5){return function(_0x5c2da2){try{jsonpatch['apply'](_0x5c2da2,_0xa33c5,!![]);}catch(_0x11d1d2){return BPromise[_0x13f9('0x1e')](_0x11d1d2);}return _0x5c2da2['save']();};}function saveUpdates(_0x15ecc3,_0x3f5226){return function(_0xf06a13){if(_0xf06a13){return _0xf06a13['update'](_0x15ecc3)[_0x13f9('0x1f')](function(_0x572b64){return _0x572b64;});}return null;};}function removeEntity(_0x2e4c8b,_0x3d48d4){return function(_0x5ae7ab){if(_0x5ae7ab){return _0x5ae7ab[_0x13f9('0x20')]()['then'](function(){_0x2e4c8b[_0x13f9('0x18')](0xcc)[_0x13f9('0x21')]();});}};}function handleEntityNotFound(_0x4bafb6,_0x4f9204){return function(_0x33e514){if(!_0x33e514){_0x4bafb6['sendStatus'](0x194);}return _0x33e514;};}function handleError(_0x275b14,_0x26682e){_0x26682e=_0x26682e||0x1f4;return function(_0x382e6f){logger[_0x13f9('0x22')](_0x382e6f[_0x13f9('0x23')]);if(_0x382e6f[_0x13f9('0x24')]){delete _0x382e6f[_0x13f9('0x24')];}_0x275b14[_0x13f9('0x18')](_0x26682e)[_0x13f9('0x25')](_0x382e6f);};}exports['index']=function(_0x560ffe,_0x3ce583){var _0x76700f={},_0x256ffd={},_0x4107d5={'count':0x0,'rows':[]};var _0x3595e2=db[_0x13f9('0x26')][_0x13f9('0x27')];_0x256ffd[_0x13f9('0x28')]=_['keys'](_0x3595e2);_0x256ffd[_0x13f9('0x29')]=_[_0x13f9('0x2a')](_0x560ffe[_0x13f9('0x29')]);_0x256ffd['filters']=_[_0x13f9('0x2b')](_0x256ffd[_0x13f9('0x28')],_0x256ffd['query']);_0x76700f['attributes']=_['intersection'](_0x256ffd[_0x13f9('0x28')],qs[_0x13f9('0x2c')](_0x560ffe[_0x13f9('0x29')][_0x13f9('0x2c')]));_0x76700f[_0x13f9('0x2d')]=_0x76700f[_0x13f9('0x2d')][_0x13f9('0x2e')]?_0x76700f[_0x13f9('0x2d')]:_0x256ffd[_0x13f9('0x28')];if(!_0x560ffe[_0x13f9('0x29')]['hasOwnProperty'](_0x13f9('0x2f'))){_0x76700f[_0x13f9('0x1b')]=qs[_0x13f9('0x1b')](_0x560ffe[_0x13f9('0x29')][_0x13f9('0x1b')]);_0x76700f[_0x13f9('0x1a')]=qs[_0x13f9('0x1a')](_0x560ffe[_0x13f9('0x29')][_0x13f9('0x1a')]);}_0x76700f[_0x13f9('0x30')]=qs['sort'](_0x560ffe[_0x13f9('0x29')][_0x13f9('0x31')]);_0x76700f[_0x13f9('0x32')]=qs['filters'](_['pick'](_0x560ffe[_0x13f9('0x29')],_0x256ffd[_0x13f9('0x33')]));if(_0x560ffe['query']['filter']){_0x76700f[_0x13f9('0x32')]=_['merge'](_0x76700f['where'],{'$or':_[_0x13f9('0x34')](_0x3595e2,function(_0x151785){if(_0x151785[_0x13f9('0x35')]['key']!=='VIRTUAL'){var _0x24ca1e={};_0x24ca1e[_0x151785[_0x13f9('0x36')]]={'$like':'%'+_0x560ffe[_0x13f9('0x29')][_0x13f9('0x37')]+'%'};return _0x24ca1e;}})});}_0x76700f=_[_0x13f9('0x38')]({},_0x76700f,_0x560ffe[_0x13f9('0x39')]);var _0x4b5a1a={'where':_0x76700f[_0x13f9('0x32')]};return db['SquareReport'][_0x13f9('0x3a')](_0x4b5a1a)['then'](function(_0x4221c7){_0x4107d5[_0x13f9('0x3a')]=_0x4221c7;if(_0x560ffe[_0x13f9('0x29')][_0x13f9('0x3b')]){_0x76700f[_0x13f9('0x3c')]=[{'all':!![]}];}return db[_0x13f9('0x26')]['findAll'](_0x76700f);})['then'](function(_0x895fc3){_0x4107d5[_0x13f9('0x3d')]=_0x895fc3;return _0x4107d5;})[_0x13f9('0x1f')](respondWithFilteredResult(_0x3ce583,_0x76700f))[_0x13f9('0x3e')](handleError(_0x3ce583,null));};exports[_0x13f9('0x3f')]=function(_0x1299a8,_0x5b1aba){var _0x29a09e={'raw':!![],'where':{'id':_0x1299a8['params']['id']}},_0x1901e6={};_0x1901e6[_0x13f9('0x28')]=_[_0x13f9('0x2a')](db[_0x13f9('0x26')][_0x13f9('0x27')]);_0x1901e6[_0x13f9('0x29')]=_[_0x13f9('0x2a')](_0x1299a8[_0x13f9('0x29')]);_0x1901e6[_0x13f9('0x33')]=_[_0x13f9('0x2b')](_0x1901e6[_0x13f9('0x28')],_0x1901e6[_0x13f9('0x29')]);_0x29a09e['attributes']=_[_0x13f9('0x2b')](_0x1901e6[_0x13f9('0x28')],qs[_0x13f9('0x2c')](_0x1299a8[_0x13f9('0x29')][_0x13f9('0x2c')]));_0x29a09e['attributes']=_0x29a09e[_0x13f9('0x2d')][_0x13f9('0x2e')]?_0x29a09e[_0x13f9('0x2d')]:_0x1901e6[_0x13f9('0x28')];if(_0x1299a8['query']['includeAll']){_0x29a09e[_0x13f9('0x3c')]=[{'all':!![]}];}_0x29a09e=_[_0x13f9('0x38')]({},_0x29a09e,_0x1299a8['options']);return db[_0x13f9('0x26')]['find'](_0x29a09e)[_0x13f9('0x1f')](handleEntityNotFound(_0x5b1aba,null))[_0x13f9('0x1f')](respondWithResult(_0x5b1aba,null))[_0x13f9('0x3e')](handleError(_0x5b1aba,null));};exports[_0x13f9('0x40')]=function(_0x589a6e,_0xe60447){return db[_0x13f9('0x26')][_0x13f9('0x40')](_0x589a6e[_0x13f9('0x41')],{})[_0x13f9('0x1f')](respondWithResult(_0xe60447,0xc9))[_0x13f9('0x3e')](handleError(_0xe60447,null));};exports[_0x13f9('0x42')]=function(_0x560a6b,_0x3a84a9){if(_0x560a6b[_0x13f9('0x41')]['id']){delete _0x560a6b[_0x13f9('0x41')]['id'];}return db[_0x13f9('0x26')]['find']({'where':{'id':_0x560a6b[_0x13f9('0x43')]['id']}})[_0x13f9('0x1f')](handleEntityNotFound(_0x3a84a9,null))[_0x13f9('0x1f')](saveUpdates(_0x560a6b[_0x13f9('0x41')],null))[_0x13f9('0x1f')](respondWithResult(_0x3a84a9,null))[_0x13f9('0x3e')](handleError(_0x3a84a9,null));};exports[_0x13f9('0x20')]=function(_0x605ffb,_0x7a6cc4){return db[_0x13f9('0x26')][_0x13f9('0x44')]({'where':{'id':_0x605ffb[_0x13f9('0x43')]['id']}})[_0x13f9('0x1f')](handleEntityNotFound(_0x7a6cc4,null))[_0x13f9('0x1f')](removeEntity(_0x7a6cc4,null))[_0x13f9('0x3e')](handleError(_0x7a6cc4,null));};exports[_0x13f9('0x45')]=function(_0x235077,_0x32ac77){return db['SquareReport'][_0x13f9('0x45')]()[_0x13f9('0x1f')](respondWithResult(_0x32ac77,null))[_0x13f9('0x3e')](handleError(_0x32ac77,null));};