Built motion from commit (unavailable).|2.3.1
[motion2.git] / server / api / squareReportDetail / squareReportDetail.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 _0xf394=['rawAttributes','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','filter','where','merge','map','type','key','VIRTUAL','rows','show','params','includeAll','include','find','catch','body','destroy','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','../../config/license/hardware','ioredis','../../config/logger','api','../../config/utils','../../mysqldb','status','json','count','offset','limit','Content-Range','reject','update','then','end','sendStatus','error','name','index','SquareDetailsReport'];(function(_0xefd519,_0xc62635){var _0x4bb882=function(_0x37e0a1){while(--_0x37e0a1){_0xefd519['push'](_0xefd519['shift']());}};_0x4bb882(++_0xc62635);}(_0xf394,0xa9));var _0x4f39=function(_0x19e35c,_0x29cd1e){_0x19e35c=_0x19e35c-0x0;var _0x3e1fe8=_0xf394[_0x19e35c];return _0x3e1fe8;};'use strict';var pdf=require(_0x4f39('0x0'));var emlformat=require(_0x4f39('0x1'));var rimraf=require(_0x4f39('0x2'));var zipdir=require(_0x4f39('0x3'));var jsonpatch=require(_0x4f39('0x4'));var rp=require(_0x4f39('0x5'));var moment=require(_0x4f39('0x6'));var BPromise=require(_0x4f39('0x7'));var Mustache=require(_0x4f39('0x8'));var util=require(_0x4f39('0x9'));var path=require(_0x4f39('0xa'));var sox=require(_0x4f39('0xb'));var csv=require('to-csv');var ejs=require(_0x4f39('0xc'));var fs=require('fs');var _=require(_0x4f39('0xd'));var squel=require(_0x4f39('0xe'));var crypto=require('crypto');var jsforce=require(_0x4f39('0xf'));var deskjs=require(_0x4f39('0x10'));var toCsv=require(_0x4f39('0x11'));var querystring=require(_0x4f39('0x12'));var Papa=require(_0x4f39('0x13'));var authService=require('../../components/auth/service');var hardwareService=require(_0x4f39('0x14'));var Redis=require(_0x4f39('0x15'));var qs=require('../../components/parsers/qs');var logger=require(_0x4f39('0x16'))(_0x4f39('0x17'));var utils=require(_0x4f39('0x18'));var config=require('../../config/environment');var db=require(_0x4f39('0x19'))['db'];function respondWithStatusCode(_0x401a4b,_0x2eda0b){_0x2eda0b=_0x2eda0b||0xcc;return function(_0x38f065){if(_0x38f065){return _0x401a4b['sendStatus'](_0x2eda0b);}return _0x401a4b[_0x4f39('0x1a')](_0x2eda0b)['end']();};}function respondWithResult(_0x1017a2,_0x1889c2){_0x1889c2=_0x1889c2||0xc8;return function(_0x258592){if(_0x258592){return _0x1017a2['status'](_0x1889c2)[_0x4f39('0x1b')](_0x258592);}};}function respondWithFilteredResult(_0xf660e2,_0x3ad97c){return function(_0x21c3d4){if(_0x21c3d4){var _0x5ef241=_0x21c3d4[_0x4f39('0x1c')],_0x22f61e=_0x3ad97c[_0x4f39('0x1d')],_0x466ecc=_0x3ad97c[_0x4f39('0x1d')]+_0x3ad97c[_0x4f39('0x1e')],_0x4e214d;if(_0x466ecc>=_0x5ef241){_0x466ecc=_0x5ef241;_0x4e214d=0xc8;}else{_0x4e214d=0xce;}_0xf660e2[_0x4f39('0x1a')](_0x4e214d);return _0xf660e2['set'](_0x4f39('0x1f'),_0x22f61e+'-'+_0x466ecc+'/'+_0x5ef241)[_0x4f39('0x1b')](_0x21c3d4);}return null;};}function patchUpdates(_0x1881cc){return function(_0x12c63b){try{jsonpatch['apply'](_0x12c63b,_0x1881cc,!![]);}catch(_0x10d8d9){return BPromise[_0x4f39('0x20')](_0x10d8d9);}return _0x12c63b['save']();};}function saveUpdates(_0x4f1c2f,_0x581ea4){return function(_0x564e38){if(_0x564e38){return _0x564e38[_0x4f39('0x21')](_0x4f1c2f)[_0x4f39('0x22')](function(_0x190c00){return _0x190c00;});}return null;};}function removeEntity(_0x51c441,_0x122f36){return function(_0x21f0c0){if(_0x21f0c0){return _0x21f0c0['destroy']()[_0x4f39('0x22')](function(){_0x51c441['status'](0xcc)[_0x4f39('0x23')]();});}};}function handleEntityNotFound(_0x5330ae,_0x47951c){return function(_0x387d73){if(!_0x387d73){_0x5330ae[_0x4f39('0x24')](0x194);}return _0x387d73;};}function handleError(_0x343dfc,_0x1bf096){_0x1bf096=_0x1bf096||0x1f4;return function(_0x384c9e){logger[_0x4f39('0x25')](_0x384c9e['stack']);if(_0x384c9e[_0x4f39('0x26')]){delete _0x384c9e[_0x4f39('0x26')];}_0x343dfc[_0x4f39('0x1a')](_0x1bf096)['send'](_0x384c9e);};}exports[_0x4f39('0x27')]=function(_0x580f54,_0x223a7c){var _0x13a19e={},_0x165950={},_0x5c595c={'count':0x0,'rows':[]};var _0x273f0c=db[_0x4f39('0x28')][_0x4f39('0x29')];_0x165950[_0x4f39('0x2a')]=_['keys'](_0x273f0c);_0x165950[_0x4f39('0x2b')]=_[_0x4f39('0x2c')](_0x580f54[_0x4f39('0x2b')]);_0x165950[_0x4f39('0x2d')]=_[_0x4f39('0x2e')](_0x165950[_0x4f39('0x2a')],_0x165950['query']);_0x13a19e['attributes']=_[_0x4f39('0x2e')](_0x165950[_0x4f39('0x2a')],qs[_0x4f39('0x2f')](_0x580f54[_0x4f39('0x2b')][_0x4f39('0x2f')]));_0x13a19e[_0x4f39('0x30')]=_0x13a19e[_0x4f39('0x30')]['length']?_0x13a19e['attributes']:_0x165950['model'];if(!_0x580f54[_0x4f39('0x2b')][_0x4f39('0x31')](_0x4f39('0x32'))){_0x13a19e[_0x4f39('0x1e')]=qs[_0x4f39('0x1e')](_0x580f54['query'][_0x4f39('0x1e')]);_0x13a19e['offset']=qs['offset'](_0x580f54[_0x4f39('0x2b')][_0x4f39('0x1d')]);}_0x13a19e[_0x4f39('0x33')]=qs[_0x4f39('0x34')](_0x580f54['query']['sort']);_0x13a19e['where']=qs[_0x4f39('0x2d')](_['pick'](_0x580f54[_0x4f39('0x2b')],_0x165950[_0x4f39('0x2d')]));if(_0x580f54[_0x4f39('0x2b')][_0x4f39('0x35')]){_0x13a19e[_0x4f39('0x36')]=_[_0x4f39('0x37')](_0x13a19e[_0x4f39('0x36')],{'$or':_[_0x4f39('0x38')](_0x273f0c,function(_0x22fdcc){if(_0x22fdcc[_0x4f39('0x39')][_0x4f39('0x3a')]!==_0x4f39('0x3b')){var _0x2a6bd7={};_0x2a6bd7[_0x22fdcc['field']]={'$like':'%'+_0x580f54[_0x4f39('0x2b')][_0x4f39('0x35')]+'%'};return _0x2a6bd7;}})});}_0x13a19e=_['merge']({},_0x13a19e,_0x580f54['options']);var _0x31850b={'where':_0x13a19e[_0x4f39('0x36')]};return db[_0x4f39('0x28')][_0x4f39('0x1c')](_0x31850b)['then'](function(_0x55ec96){_0x5c595c[_0x4f39('0x1c')]=_0x55ec96;if(_0x580f54[_0x4f39('0x2b')]['includeAll']){_0x13a19e['include']=[{'all':!![]}];}return db[_0x4f39('0x28')]['findAll'](_0x13a19e);})[_0x4f39('0x22')](function(_0x42c7d9){_0x5c595c[_0x4f39('0x3c')]=_0x42c7d9;return _0x5c595c;})['then'](respondWithFilteredResult(_0x223a7c,_0x13a19e))['catch'](handleError(_0x223a7c,null));};exports[_0x4f39('0x3d')]=function(_0x1795cd,_0x183275){var _0x4367d1={'raw':!![],'where':{'id':_0x1795cd[_0x4f39('0x3e')]['id']}},_0x36fbff={};_0x36fbff['model']=_[_0x4f39('0x2c')](db[_0x4f39('0x28')]['rawAttributes']);_0x36fbff[_0x4f39('0x2b')]=_[_0x4f39('0x2c')](_0x1795cd[_0x4f39('0x2b')]);_0x36fbff[_0x4f39('0x2d')]=_['intersection'](_0x36fbff[_0x4f39('0x2a')],_0x36fbff[_0x4f39('0x2b')]);_0x4367d1[_0x4f39('0x30')]=_['intersection'](_0x36fbff[_0x4f39('0x2a')],qs['fields'](_0x1795cd[_0x4f39('0x2b')][_0x4f39('0x2f')]));_0x4367d1[_0x4f39('0x30')]=_0x4367d1['attributes']['length']?_0x4367d1[_0x4f39('0x30')]:_0x36fbff['model'];if(_0x1795cd[_0x4f39('0x2b')][_0x4f39('0x3f')]){_0x4367d1[_0x4f39('0x40')]=[{'all':!![]}];}_0x4367d1=_['merge']({},_0x4367d1,_0x1795cd['options']);return db[_0x4f39('0x28')][_0x4f39('0x41')](_0x4367d1)['then'](handleEntityNotFound(_0x183275,null))[_0x4f39('0x22')](respondWithResult(_0x183275,null))[_0x4f39('0x42')](handleError(_0x183275,null));};exports['create']=function(_0x10a6b1,_0x4b2b1f){return db['SquareDetailsReport']['create'](_0x10a6b1[_0x4f39('0x43')],{})[_0x4f39('0x22')](respondWithResult(_0x4b2b1f,0xc9))[_0x4f39('0x42')](handleError(_0x4b2b1f,null));};exports[_0x4f39('0x21')]=function(_0x195df7,_0x49d76c){if(_0x195df7[_0x4f39('0x43')]['id']){delete _0x195df7[_0x4f39('0x43')]['id'];}return db['SquareDetailsReport'][_0x4f39('0x41')]({'where':{'id':_0x195df7['params']['id']}})[_0x4f39('0x22')](handleEntityNotFound(_0x49d76c,null))[_0x4f39('0x22')](saveUpdates(_0x195df7[_0x4f39('0x43')],null))[_0x4f39('0x22')](respondWithResult(_0x49d76c,null))['catch'](handleError(_0x49d76c,null));};exports[_0x4f39('0x44')]=function(_0x882e58,_0x4ebd18){return db[_0x4f39('0x28')][_0x4f39('0x41')]({'where':{'id':_0x882e58[_0x4f39('0x3e')]['id']}})[_0x4f39('0x22')](handleEntityNotFound(_0x4ebd18,null))['then'](removeEntity(_0x4ebd18,null))[_0x4f39('0x42')](handleError(_0x4ebd18,null));};exports[_0x4f39('0x45')]=function(_0x34e70d,_0x4e4dee){return db[_0x4f39('0x28')][_0x4f39('0x45')]()['then'](respondWithResult(_0x4e4dee,null))[_0x4f39('0x42')](handleError(_0x4e4dee,null));};