Built motion from commit (unavailable).|2.5.15
[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 _0x65a9=['../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','Content-Range','reject','save','update','then','destroy','error','name','send','index','map','SquareDetailsReport','rawAttributes','fieldName','key','model','query','intersection','attributes','fields','length','nolimit','limit','sort','where','pick','filters','merge','type','VIRTUAL','options','findAll','rows','catch','show','params','keys','includeAll','include','create','body','find','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis'];(function(_0x1e06f1,_0x59d7e1){var _0x34f77e=function(_0x4f9f26){while(--_0x4f9f26){_0x1e06f1['push'](_0x1e06f1['shift']());}};_0x34f77e(++_0x59d7e1);}(_0x65a9,0x81));var _0x965a=function(_0xeb64af,_0x238102){_0xeb64af=_0xeb64af-0x0;var _0x446ffb=_0x65a9[_0xeb64af];return _0x446ffb;};'use strict';var pdf=require(_0x965a('0x0'));var emlformat=require(_0x965a('0x1'));var rimraf=require(_0x965a('0x2'));var zipdir=require(_0x965a('0x3'));var jsonpatch=require(_0x965a('0x4'));var rp=require(_0x965a('0x5'));var moment=require('moment');var BPromise=require(_0x965a('0x6'));var Mustache=require(_0x965a('0x7'));var util=require(_0x965a('0x8'));var path=require('path');var sox=require(_0x965a('0x9'));var csv=require(_0x965a('0xa'));var ejs=require(_0x965a('0xb'));var fs=require('fs');var _=require(_0x965a('0xc'));var squel=require(_0x965a('0xd'));var crypto=require(_0x965a('0xe'));var jsforce=require(_0x965a('0xf'));var deskjs=require(_0x965a('0x10'));var toCsv=require(_0x965a('0xa'));var querystring=require('querystring');var Papa=require(_0x965a('0x11'));var Redis=require(_0x965a('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x965a('0x13'));var logger=require(_0x965a('0x14'))(_0x965a('0x15'));var utils=require(_0x965a('0x16'));var config=require(_0x965a('0x17'));var licenseUtil=require(_0x965a('0x18'));var db=require(_0x965a('0x19'))['db'];function respondWithStatusCode(_0x22f227,_0x46f326){_0x46f326=_0x46f326||0xcc;return function(_0x4de30f){if(_0x4de30f){return _0x22f227[_0x965a('0x1a')](_0x46f326);}return _0x22f227[_0x965a('0x1b')](_0x46f326)[_0x965a('0x1c')]();};}function respondWithResult(_0x188785,_0x2cc975){_0x2cc975=_0x2cc975||0xc8;return function(_0x2a42d8){if(_0x2a42d8){return _0x188785[_0x965a('0x1b')](_0x2cc975)['json'](_0x2a42d8);}};}function respondWithFilteredResult(_0x2feaa4,_0x33ef00){return function(_0x3bd395){if(_0x3bd395){var _0x57eefc=_0x3bd395[_0x965a('0x1d')],_0x4b2672=_0x33ef00['offset'],_0xa6ebf4=_0x33ef00[_0x965a('0x1e')]+_0x33ef00['limit'],_0x2d63f1;if(_0xa6ebf4>=_0x57eefc){_0xa6ebf4=_0x57eefc;_0x2d63f1=0xc8;}else{_0x2d63f1=0xce;}_0x2feaa4['status'](_0x2d63f1);return _0x2feaa4['set'](_0x965a('0x1f'),_0x4b2672+'-'+_0xa6ebf4+'/'+_0x57eefc)['json'](_0x3bd395);}return null;};}function patchUpdates(_0x669338){return function(_0x2249a1){try{jsonpatch['apply'](_0x2249a1,_0x669338,!![]);}catch(_0x3891f2){return BPromise[_0x965a('0x20')](_0x3891f2);}return _0x2249a1[_0x965a('0x21')]();};}function saveUpdates(_0x4a369e,_0x13cf61){return function(_0x46f1af){if(_0x46f1af){return _0x46f1af[_0x965a('0x22')](_0x4a369e)[_0x965a('0x23')](function(_0x5238bc){return _0x5238bc;});}return null;};}function removeEntity(_0x50b5a1,_0x4935df){return function(_0x4346fb){if(_0x4346fb){return _0x4346fb[_0x965a('0x24')]()[_0x965a('0x23')](function(){_0x50b5a1[_0x965a('0x1b')](0xcc)[_0x965a('0x1c')]();});}};}function handleEntityNotFound(_0x439a15,_0x4c7436){return function(_0x150e91){if(!_0x150e91){_0x439a15[_0x965a('0x1a')](0x194);}return _0x150e91;};}function handleError(_0x2b72ff,_0x481d88){_0x481d88=_0x481d88||0x1f4;return function(_0x4ff031){logger[_0x965a('0x25')](_0x4ff031['stack']);if(_0x4ff031[_0x965a('0x26')]){delete _0x4ff031['name'];}_0x2b72ff[_0x965a('0x1b')](_0x481d88)[_0x965a('0x27')](_0x4ff031);};}exports[_0x965a('0x28')]=function(_0x235aef,_0x43e40b){var _0x55655f={},_0x2db2b2={},_0x5d7e66={'count':0x0,'rows':[]};var _0x4acebb=_[_0x965a('0x29')](db[_0x965a('0x2a')][_0x965a('0x2b')],function(_0x13aaac){return{'name':_0x13aaac[_0x965a('0x2c')],'type':_0x13aaac['type'][_0x965a('0x2d')]};});_0x2db2b2[_0x965a('0x2e')]=_[_0x965a('0x29')](_0x4acebb,_0x965a('0x26'));_0x2db2b2[_0x965a('0x2f')]=_['keys'](_0x235aef[_0x965a('0x2f')]);_0x2db2b2['filters']=_[_0x965a('0x30')](_0x2db2b2['model'],_0x2db2b2[_0x965a('0x2f')]);_0x55655f[_0x965a('0x31')]=_[_0x965a('0x30')](_0x2db2b2[_0x965a('0x2e')],qs[_0x965a('0x32')](_0x235aef['query'][_0x965a('0x32')]));_0x55655f[_0x965a('0x31')]=_0x55655f[_0x965a('0x31')][_0x965a('0x33')]?_0x55655f['attributes']:_0x2db2b2[_0x965a('0x2e')];if(!_0x235aef['query']['hasOwnProperty'](_0x965a('0x34'))){_0x55655f[_0x965a('0x35')]=qs[_0x965a('0x35')](_0x235aef['query'][_0x965a('0x35')]);_0x55655f['offset']=qs['offset'](_0x235aef[_0x965a('0x2f')]['offset']);}_0x55655f['order']=qs['sort'](_0x235aef[_0x965a('0x2f')][_0x965a('0x36')]);_0x55655f[_0x965a('0x37')]=qs['filters'](_[_0x965a('0x38')](_0x235aef['query'],_0x2db2b2[_0x965a('0x39')]),_0x4acebb);if(_0x235aef[_0x965a('0x2f')]['filter']){_0x55655f['where']=_[_0x965a('0x3a')](_0x55655f[_0x965a('0x37')],{'$or':_['map'](_0x4acebb,function(_0x493084){if(_0x493084[_0x965a('0x3b')]!==_0x965a('0x3c')){var _0x19c265={};_0x19c265[_0x493084[_0x965a('0x26')]]={'$like':'%'+_0x235aef[_0x965a('0x2f')]['filter']+'%'};return _0x19c265;}})});}_0x55655f=_[_0x965a('0x3a')]({},_0x55655f,_0x235aef[_0x965a('0x3d')]);var _0x183c6f={'where':_0x55655f[_0x965a('0x37')]};return db['SquareDetailsReport'][_0x965a('0x1d')](_0x183c6f)['then'](function(_0x31bc10){_0x5d7e66['count']=_0x31bc10;if(_0x235aef[_0x965a('0x2f')]['includeAll']){_0x55655f['include']=[{'all':!![]}];}return db[_0x965a('0x2a')][_0x965a('0x3e')](_0x55655f);})['then'](function(_0x51d78c){_0x5d7e66[_0x965a('0x3f')]=_0x51d78c;return _0x5d7e66;})['then'](respondWithFilteredResult(_0x43e40b,_0x55655f))[_0x965a('0x40')](handleError(_0x43e40b,null));};exports[_0x965a('0x41')]=function(_0x2c8996,_0x5ed231){var _0x247cc8={'raw':!![],'where':{'id':_0x2c8996[_0x965a('0x42')]['id']}},_0x18adc1={};_0x18adc1[_0x965a('0x2e')]=_[_0x965a('0x43')](db[_0x965a('0x2a')]['rawAttributes']);_0x18adc1[_0x965a('0x2f')]=_['keys'](_0x2c8996['query']);_0x18adc1['filters']=_[_0x965a('0x30')](_0x18adc1[_0x965a('0x2e')],_0x18adc1[_0x965a('0x2f')]);_0x247cc8[_0x965a('0x31')]=_[_0x965a('0x30')](_0x18adc1[_0x965a('0x2e')],qs[_0x965a('0x32')](_0x2c8996[_0x965a('0x2f')][_0x965a('0x32')]));_0x247cc8[_0x965a('0x31')]=_0x247cc8[_0x965a('0x31')]['length']?_0x247cc8[_0x965a('0x31')]:_0x18adc1[_0x965a('0x2e')];if(_0x2c8996[_0x965a('0x2f')][_0x965a('0x44')]){_0x247cc8[_0x965a('0x45')]=[{'all':!![]}];}_0x247cc8=_[_0x965a('0x3a')]({},_0x247cc8,_0x2c8996[_0x965a('0x3d')]);return db[_0x965a('0x2a')]['find'](_0x247cc8)['then'](handleEntityNotFound(_0x5ed231,null))[_0x965a('0x23')](respondWithResult(_0x5ed231,null))[_0x965a('0x40')](handleError(_0x5ed231,null));};exports['create']=function(_0x288756,_0x374c3c){return db[_0x965a('0x2a')][_0x965a('0x46')](_0x288756[_0x965a('0x47')],{})['then'](respondWithResult(_0x374c3c,0xc9))[_0x965a('0x40')](handleError(_0x374c3c,null));};exports[_0x965a('0x22')]=function(_0x482224,_0x521ec6){if(_0x482224[_0x965a('0x47')]['id']){delete _0x482224[_0x965a('0x47')]['id'];}return db['SquareDetailsReport'][_0x965a('0x48')]({'where':{'id':_0x482224[_0x965a('0x42')]['id']}})[_0x965a('0x23')](handleEntityNotFound(_0x521ec6,null))[_0x965a('0x23')](saveUpdates(_0x482224[_0x965a('0x47')],null))[_0x965a('0x23')](respondWithResult(_0x521ec6,null))[_0x965a('0x40')](handleError(_0x521ec6,null));};exports[_0x965a('0x24')]=function(_0xa9a060,_0x372df8){return db[_0x965a('0x2a')][_0x965a('0x48')]({'where':{'id':_0xa9a060[_0x965a('0x42')]['id']}})['then'](handleEntityNotFound(_0x372df8,null))['then'](removeEntity(_0x372df8,null))[_0x965a('0x40')](handleError(_0x372df8,null));};exports[_0x965a('0x49')]=function(_0x153843,_0x441cb7){return db['SquareDetailsReport']['describe']()[_0x965a('0x23')](respondWithResult(_0x441cb7,null))[_0x965a('0x40')](handleError(_0x441cb7,null));};