Built motion from commit (unavailable).|2.0.75
[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 _0xbcf4=['SquareDetailsReport','rawAttributes','model','keys','query','dateEnd','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','dateStart','add','day','merge','filter','options','includeAll','include','rows','catch','params','find','create','body','describe','fast-json-patch','request-promise','util','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../mysqldb','status','end','json','count','offset','limit','Content-Range','apply','reject','update','then','destroy','sendStatus','error','stack','name','send','index'];(function(_0x1fea49,_0x2e8b16){var _0xd1fc37=function(_0x5a0439){while(--_0x5a0439){_0x1fea49['push'](_0x1fea49['shift']());}};_0xd1fc37(++_0x2e8b16);}(_0xbcf4,0x64));var _0x4bcf=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xbcf4[_0x3dd15e];return _0x231fd0;};'use strict';var jsonpatch=require(_0x4bcf('0x0'));var rp=require(_0x4bcf('0x1'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x4bcf('0x2'));var path=require(_0x4bcf('0x3'));var sox=require(_0x4bcf('0x4'));var csv=require(_0x4bcf('0x5'));var ejs=require(_0x4bcf('0x6'));var fs=require('fs');var _=require('lodash');var squel=require(_0x4bcf('0x7'));var crypto=require(_0x4bcf('0x8'));var jsforce=require(_0x4bcf('0x9'));var deskjs=require(_0x4bcf('0xa'));var toCsv=require(_0x4bcf('0x5'));var querystring=require(_0x4bcf('0xb'));var Papa=require(_0x4bcf('0xc'));var qs=require(_0x4bcf('0xd'));var logger=require(_0x4bcf('0xe'))(_0x4bcf('0xf'));var utils=require(_0x4bcf('0x10'));var config=require('../../config/environment');var db=require(_0x4bcf('0x11'))['db'];function respondWithStatusCode(_0x51330f,_0x35adfe){_0x35adfe=_0x35adfe||0xcc;return function(_0x2e7d59){if(_0x2e7d59){return _0x51330f['sendStatus'](_0x35adfe);}return _0x51330f[_0x4bcf('0x12')](_0x35adfe)[_0x4bcf('0x13')]();};}function respondWithResult(_0xf6efab,_0x59aace){_0x59aace=_0x59aace||0xc8;return function(_0x21f875){if(_0x21f875){return _0xf6efab[_0x4bcf('0x12')](_0x59aace)[_0x4bcf('0x14')](_0x21f875);}};}function respondWithFilteredResult(_0x5d75d6,_0x290ced){return function(_0x452bc4){if(_0x452bc4){var _0x29ad9c=_0x452bc4[_0x4bcf('0x15')],_0x365a9b=_0x290ced[_0x4bcf('0x16')],_0x1ec0a5=_0x290ced[_0x4bcf('0x16')]+_0x290ced[_0x4bcf('0x17')],_0x1f51fb;if(_0x1ec0a5>=_0x29ad9c){_0x1ec0a5=_0x29ad9c;_0x1f51fb=0xc8;}else{_0x1f51fb=0xce;}_0x5d75d6[_0x4bcf('0x12')](_0x1f51fb);return _0x5d75d6['set'](_0x4bcf('0x18'),_0x365a9b+'-'+_0x1ec0a5+'/'+_0x29ad9c)['json'](_0x452bc4);}return null;};}function patchUpdates(_0x428265){return function(_0x2599da){try{jsonpatch[_0x4bcf('0x19')](_0x2599da,_0x428265,!![]);}catch(_0x4f6d04){return BPromise[_0x4bcf('0x1a')](_0x4f6d04);}return _0x2599da['save']();};}function saveUpdates(_0x1e1a1d,_0x129e91){return function(_0x281b5f){if(_0x281b5f){return _0x281b5f[_0x4bcf('0x1b')](_0x1e1a1d)[_0x4bcf('0x1c')](function(_0x3b9ab8){return _0x3b9ab8;});}return null;};}function removeEntity(_0x4aa104,_0x259391){return function(_0x42dd4d){if(_0x42dd4d){return _0x42dd4d[_0x4bcf('0x1d')]()[_0x4bcf('0x1c')](function(){_0x4aa104[_0x4bcf('0x12')](0xcc)[_0x4bcf('0x13')]();});}};}function handleEntityNotFound(_0x559040,_0x3a45a9){return function(_0x3c5f59){if(!_0x3c5f59){_0x559040[_0x4bcf('0x1e')](0x194);}return _0x3c5f59;};}function handleError(_0x3d742c,_0x176387){_0x176387=_0x176387||0x1f4;return function(_0x2bd2d2){logger[_0x4bcf('0x1f')](_0x2bd2d2[_0x4bcf('0x20')]);if(_0x2bd2d2['name']){delete _0x2bd2d2[_0x4bcf('0x21')];}_0x3d742c[_0x4bcf('0x12')](_0x176387)[_0x4bcf('0x22')](_0x2bd2d2);};}exports[_0x4bcf('0x23')]=function(_0x5f0f6a,_0x23d661){var _0x214349={},_0x1e034f={},_0x2f3bec={'count':0x0,'rows':[]};var _0x3738f1=db[_0x4bcf('0x24')][_0x4bcf('0x25')];_0x1e034f[_0x4bcf('0x26')]=_[_0x4bcf('0x27')](_0x3738f1);var _0x575ff4={'dateStart':_0x5f0f6a[_0x4bcf('0x28')]['dateStart'],'dateEnd':_0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x29')]};delete _0x5f0f6a[_0x4bcf('0x28')]['dateStart'];delete _0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x29')];_0x1e034f[_0x4bcf('0x28')]=_[_0x4bcf('0x27')](_0x5f0f6a[_0x4bcf('0x28')]);_0x1e034f['filters']=_[_0x4bcf('0x2a')](_0x1e034f['model'],_0x1e034f['query']);_0x214349[_0x4bcf('0x2b')]=_['intersection'](_0x1e034f['model'],qs[_0x4bcf('0x2c')](_0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x2c')]));_0x214349[_0x4bcf('0x2b')]=_0x214349[_0x4bcf('0x2b')][_0x4bcf('0x2d')]?_0x214349['attributes']:_0x1e034f[_0x4bcf('0x26')];if(!_0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x2e')](_0x4bcf('0x2f'))){_0x214349[_0x4bcf('0x17')]=qs[_0x4bcf('0x17')](_0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x17')]);_0x214349['offset']=qs[_0x4bcf('0x16')](_0x5f0f6a[_0x4bcf('0x28')]['offset']);}_0x214349[_0x4bcf('0x30')]=qs[_0x4bcf('0x31')](_0x5f0f6a[_0x4bcf('0x28')]['sort']);_0x214349[_0x4bcf('0x32')]=qs[_0x4bcf('0x33')](_[_0x4bcf('0x34')](_0x5f0f6a['query'],_0x1e034f[_0x4bcf('0x33')]));if(_0x575ff4[_0x4bcf('0x35')]){if(_0x575ff4['dateEnd']){_0x575ff4[_0x4bcf('0x29')]=moment(_0x575ff4['dateEnd'])[_0x4bcf('0x36')](0x1,'day');}else{_0x575ff4[_0x4bcf('0x29')]=moment(_0x575ff4['dateStart'])[_0x4bcf('0x36')](0x1,_0x4bcf('0x37'));}_[_0x4bcf('0x38')](_0x214349['where'],{'createdAt':{'$gte':_0x575ff4[_0x4bcf('0x35')],'$lte':_0x575ff4[_0x4bcf('0x29')]}});}if(_0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x39')]){_0x214349[_0x4bcf('0x32')]=_[_0x4bcf('0x38')](_0x214349[_0x4bcf('0x32')],{'$or':_['map'](_0x214349['attributes'],function(_0x30bdf6){var _0x36a12b={};_0x36a12b[_0x30bdf6]={'$like':'%'+_0x5f0f6a['query']['filter']+'%'};return _0x36a12b;})});}_0x214349=_[_0x4bcf('0x38')]({},_0x214349,_0x5f0f6a[_0x4bcf('0x3a')]);var _0x99968={'where':_0x214349[_0x4bcf('0x32')]};return db[_0x4bcf('0x24')][_0x4bcf('0x15')](_0x99968)[_0x4bcf('0x1c')](function(_0x438472){_0x2f3bec[_0x4bcf('0x15')]=_0x438472;if(_0x5f0f6a[_0x4bcf('0x28')][_0x4bcf('0x3b')]){_0x214349[_0x4bcf('0x3c')]=[{'all':!![]}];}return db[_0x4bcf('0x24')]['findAll'](_0x214349);})[_0x4bcf('0x1c')](function(_0x1b7f0f){_0x2f3bec[_0x4bcf('0x3d')]=_0x1b7f0f;return _0x2f3bec;})[_0x4bcf('0x1c')](respondWithFilteredResult(_0x23d661,_0x214349))[_0x4bcf('0x3e')](handleError(_0x23d661,null));};exports['show']=function(_0x3f823f,_0x5aa9b2){var _0x3d4481={'raw':!![],'where':{'id':_0x3f823f[_0x4bcf('0x3f')]['id']}},_0xacc83e={};_0xacc83e[_0x4bcf('0x26')]=_['keys'](db[_0x4bcf('0x24')][_0x4bcf('0x25')]);_0xacc83e['query']=_[_0x4bcf('0x27')](_0x3f823f[_0x4bcf('0x28')]);_0xacc83e[_0x4bcf('0x33')]=_[_0x4bcf('0x2a')](_0xacc83e[_0x4bcf('0x26')],_0xacc83e[_0x4bcf('0x28')]);_0x3d4481[_0x4bcf('0x2b')]=_[_0x4bcf('0x2a')](_0xacc83e[_0x4bcf('0x26')],qs[_0x4bcf('0x2c')](_0x3f823f[_0x4bcf('0x28')][_0x4bcf('0x2c')]));_0x3d4481[_0x4bcf('0x2b')]=_0x3d4481['attributes'][_0x4bcf('0x2d')]?_0x3d4481[_0x4bcf('0x2b')]:_0xacc83e[_0x4bcf('0x26')];if(_0x3f823f['query']['includeAll']){_0x3d4481[_0x4bcf('0x3c')]=[{'all':!![]}];}_0x3d4481=_[_0x4bcf('0x38')]({},_0x3d4481,_0x3f823f[_0x4bcf('0x3a')]);return db[_0x4bcf('0x24')][_0x4bcf('0x40')](_0x3d4481)[_0x4bcf('0x1c')](handleEntityNotFound(_0x5aa9b2,null))['then'](respondWithResult(_0x5aa9b2,null))[_0x4bcf('0x3e')](handleError(_0x5aa9b2,null));};exports[_0x4bcf('0x41')]=function(_0x3e9b79,_0x270697){return db[_0x4bcf('0x24')][_0x4bcf('0x41')](_0x3e9b79[_0x4bcf('0x42')],{})['then'](respondWithResult(_0x270697,0xc9))['catch'](handleError(_0x270697,null));};exports[_0x4bcf('0x1b')]=function(_0x7c0fe5,_0x48dbf4){if(_0x7c0fe5[_0x4bcf('0x42')]['id']){delete _0x7c0fe5[_0x4bcf('0x42')]['id'];}return db[_0x4bcf('0x24')][_0x4bcf('0x40')]({'where':{'id':_0x7c0fe5[_0x4bcf('0x3f')]['id']}})[_0x4bcf('0x1c')](handleEntityNotFound(_0x48dbf4,null))[_0x4bcf('0x1c')](saveUpdates(_0x7c0fe5[_0x4bcf('0x42')],null))[_0x4bcf('0x1c')](respondWithResult(_0x48dbf4,null))[_0x4bcf('0x3e')](handleError(_0x48dbf4,null));};exports[_0x4bcf('0x1d')]=function(_0x2b55a1,_0x335638){return db[_0x4bcf('0x24')][_0x4bcf('0x40')]({'where':{'id':_0x2b55a1[_0x4bcf('0x3f')]['id']}})['then'](handleEntityNotFound(_0x335638,null))[_0x4bcf('0x1c')](removeEntity(_0x335638,null))[_0x4bcf('0x3e')](handleError(_0x335638,null));};exports[_0x4bcf('0x43')]=function(_0x183d43,_0x5617b2){return db[_0x4bcf('0x24')][_0x4bcf('0x43')]()[_0x4bcf('0x1c')](respondWithResult(_0x5617b2,null))[_0x4bcf('0x3e')](handleError(_0x5617b2,null));};