334a099775ca040f5295b8b191a6325b61b044ff
[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 _0x2f9b=['ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','render','merge','body','agent','interaction','account','index','map','SquareDetailsReport','fieldName','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','filters','pick','filter','type','options','includeAll','include','rows','catch','show','rawAttributes','create','find','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','lodash','jsforce','querystring'];(function(_0x42bc91,_0x41f40a){var _0x3f5507=function(_0x20cfaf){while(--_0x20cfaf){_0x42bc91['push'](_0x42bc91['shift']());}};_0x3f5507(++_0x41f40a);}(_0x2f9b,0xd4));var _0xb2f9=function(_0x2d93f8,_0x5370f2){_0x2d93f8=_0x2d93f8-0x0;var _0x100113=_0x2f9b[_0x2d93f8];return _0x100113;};'use strict';var emlformat=require(_0xb2f9('0x0'));var rimraf=require(_0xb2f9('0x1'));var zipdir=require(_0xb2f9('0x2'));var jsonpatch=require(_0xb2f9('0x3'));var rp=require(_0xb2f9('0x4'));var moment=require(_0xb2f9('0x5'));var BPromise=require(_0xb2f9('0x6'));var Mustache=require('mustache');var util=require(_0xb2f9('0x7'));var path=require('path');var sox=require(_0xb2f9('0x8'));var csv=require(_0xb2f9('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb2f9('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xb2f9('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xb2f9('0x9'));var querystring=require(_0xb2f9('0xc'));var Papa=require('papaparse');var Redis=require(_0xb2f9('0xd'));var authService=require('../../components/auth/service');var qs=require(_0xb2f9('0xe'));var as=require(_0xb2f9('0xf'));var hardwareService=require(_0xb2f9('0x10'));var logger=require(_0xb2f9('0x11'))(_0xb2f9('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xb2f9('0x13'))['db'];function respondWithStatusCode(_0x51fdbb,_0x47a016){_0x47a016=_0x47a016||0xcc;return function(_0x458749){if(_0x458749){return _0x51fdbb[_0xb2f9('0x14')](_0x47a016);}return _0x51fdbb[_0xb2f9('0x15')](_0x47a016)[_0xb2f9('0x16')]();};}function respondWithResult(_0x5825a3,_0x3e83cd){_0x3e83cd=_0x3e83cd||0xc8;return function(_0x36937c){if(_0x36937c){return _0x5825a3[_0xb2f9('0x15')](_0x3e83cd)[_0xb2f9('0x17')](_0x36937c);}};}function respondWithFilteredResult(_0x277101,_0x28cf10){return function(_0x5b8b19){if(_0x5b8b19){var _0x4dec01=typeof _0x28cf10[_0xb2f9('0x18')]===_0xb2f9('0x19')&&typeof _0x28cf10[_0xb2f9('0x1a')]===_0xb2f9('0x19');var _0x497b76=_0x5b8b19[_0xb2f9('0x1b')];var _0x19cf0b=_0x4dec01?0x0:_0x28cf10[_0xb2f9('0x18')];var _0x8fd3b9=_0x4dec01?_0x5b8b19[_0xb2f9('0x1b')]:_0x28cf10[_0xb2f9('0x18')]+_0x28cf10[_0xb2f9('0x1a')];var _0x3fb383;if(_0x8fd3b9>=_0x497b76){_0x8fd3b9=_0x497b76;_0x3fb383=0xc8;}else{_0x3fb383=0xce;}_0x277101[_0xb2f9('0x15')](_0x3fb383);return _0x277101[_0xb2f9('0x1c')](_0xb2f9('0x1d'),_0x19cf0b+'-'+_0x8fd3b9+'/'+_0x497b76)[_0xb2f9('0x17')](_0x5b8b19);}return null;};}function patchUpdates(_0x3ddac4){return function(_0x3ca93a){try{jsonpatch[_0xb2f9('0x1e')](_0x3ca93a,_0x3ddac4,!![]);}catch(_0x194088){return BPromise[_0xb2f9('0x1f')](_0x194088);}return _0x3ca93a['save']();};}function saveUpdates(_0x19f2f3,_0x3187ee){return function(_0x3a5151){if(_0x3a5151){return _0x3a5151[_0xb2f9('0x20')](_0x19f2f3)[_0xb2f9('0x21')](function(_0x9e1025){return _0x9e1025;});}return null;};}function removeEntity(_0x4c118f,_0x406213){return function(_0x56e691){if(_0x56e691){return _0x56e691[_0xb2f9('0x22')]()[_0xb2f9('0x21')](function(){_0x4c118f['status'](0xcc)[_0xb2f9('0x16')]();});}};}function handleEntityNotFound(_0x21c3db,_0x91ecec){return function(_0x1bb615){if(!_0x1bb615){_0x21c3db['sendStatus'](0x194);}return _0x1bb615;};}function handleError(_0x40514a,_0x23b41c){_0x23b41c=_0x23b41c||0x1f4;return function(_0x4ed03e){logger[_0xb2f9('0x23')](_0x4ed03e[_0xb2f9('0x24')]);if(_0x4ed03e[_0xb2f9('0x25')]){delete _0x4ed03e[_0xb2f9('0x25')];}_0x40514a[_0xb2f9('0x15')](_0x23b41c)[_0xb2f9('0x26')](_0x4ed03e);};}function getMustacheRender(_0x5090b3,_0x326b34){return Mustache[_0xb2f9('0x27')](_0x5090b3,_[_0xb2f9('0x28')](_0x326b34[_0xb2f9('0x29')],{'contact':_0x326b34['contact'],'message':_0x326b34['message'],'agent':_0x326b34[_0xb2f9('0x2a')],'interaction':_0x326b34[_0xb2f9('0x2b')],'account':_0x326b34[_0xb2f9('0x2c')]}))||'';}exports[_0xb2f9('0x2d')]=function(_0xdbd3e8,_0x4dcd2e){var _0x3925e1={},_0x3958fc={},_0x2d0342={'count':0x0,'rows':[]};var _0x4bb1e5=_[_0xb2f9('0x2e')](db[_0xb2f9('0x2f')]['rawAttributes'],function(_0x526214){return{'name':_0x526214[_0xb2f9('0x30')],'type':_0x526214['type']['key']};});_0x3958fc[_0xb2f9('0x31')]=_[_0xb2f9('0x2e')](_0x4bb1e5,_0xb2f9('0x25'));_0x3958fc[_0xb2f9('0x32')]=_[_0xb2f9('0x33')](_0xdbd3e8['query']);_0x3958fc['filters']=_['intersection'](_0x3958fc[_0xb2f9('0x31')],_0x3958fc['query']);_0x3925e1[_0xb2f9('0x34')]=_[_0xb2f9('0x35')](_0x3958fc['model'],qs[_0xb2f9('0x36')](_0xdbd3e8[_0xb2f9('0x32')][_0xb2f9('0x36')]));_0x3925e1[_0xb2f9('0x34')]=_0x3925e1['attributes'][_0xb2f9('0x37')]?_0x3925e1[_0xb2f9('0x34')]:_0x3958fc[_0xb2f9('0x31')];if(!_0xdbd3e8['query'][_0xb2f9('0x38')]('nolimit')){_0x3925e1[_0xb2f9('0x1a')]=qs[_0xb2f9('0x1a')](_0xdbd3e8[_0xb2f9('0x32')][_0xb2f9('0x1a')]);_0x3925e1[_0xb2f9('0x18')]=qs[_0xb2f9('0x18')](_0xdbd3e8['query'][_0xb2f9('0x18')]);}_0x3925e1[_0xb2f9('0x39')]=qs['sort'](_0xdbd3e8[_0xb2f9('0x32')][_0xb2f9('0x3a')]);_0x3925e1[_0xb2f9('0x3b')]=qs[_0xb2f9('0x3c')](_[_0xb2f9('0x3d')](_0xdbd3e8[_0xb2f9('0x32')],_0x3958fc[_0xb2f9('0x3c')]),_0x4bb1e5);if(_0xdbd3e8['query'][_0xb2f9('0x3e')]){_0x3925e1[_0xb2f9('0x3b')]=_[_0xb2f9('0x28')](_0x3925e1['where'],{'$or':_[_0xb2f9('0x2e')](_0x4bb1e5,function(_0x122b99){if(_0x122b99[_0xb2f9('0x3f')]!=='VIRTUAL'){var _0x173d61={};_0x173d61[_0x122b99[_0xb2f9('0x25')]]={'$like':'%'+_0xdbd3e8[_0xb2f9('0x32')]['filter']+'%'};return _0x173d61;}})});}_0x3925e1=_[_0xb2f9('0x28')]({},_0x3925e1,_0xdbd3e8[_0xb2f9('0x40')]);var _0x19019c={'where':_0x3925e1[_0xb2f9('0x3b')]};return db[_0xb2f9('0x2f')]['count'](_0x19019c)[_0xb2f9('0x21')](function(_0x4ff7a8){_0x2d0342['count']=_0x4ff7a8;if(_0xdbd3e8[_0xb2f9('0x32')][_0xb2f9('0x41')]){_0x3925e1[_0xb2f9('0x42')]=[{'all':!![]}];}return db[_0xb2f9('0x2f')]['findAll'](_0x3925e1);})['then'](function(_0x4e44cf){_0x2d0342[_0xb2f9('0x43')]=_0x4e44cf;return _0x2d0342;})[_0xb2f9('0x21')](respondWithFilteredResult(_0x4dcd2e,_0x3925e1))[_0xb2f9('0x44')](handleError(_0x4dcd2e,null));};exports[_0xb2f9('0x45')]=function(_0x29f03c,_0x321af1){var _0xab6fad={'raw':!![],'where':{'id':_0x29f03c['params']['id']}},_0x29317b={};_0x29317b['model']=_['keys'](db[_0xb2f9('0x2f')][_0xb2f9('0x46')]);_0x29317b[_0xb2f9('0x32')]=_[_0xb2f9('0x33')](_0x29f03c['query']);_0x29317b[_0xb2f9('0x3c')]=_[_0xb2f9('0x35')](_0x29317b['model'],_0x29317b[_0xb2f9('0x32')]);_0xab6fad[_0xb2f9('0x34')]=_[_0xb2f9('0x35')](_0x29317b['model'],qs[_0xb2f9('0x36')](_0x29f03c[_0xb2f9('0x32')][_0xb2f9('0x36')]));_0xab6fad[_0xb2f9('0x34')]=_0xab6fad['attributes'][_0xb2f9('0x37')]?_0xab6fad[_0xb2f9('0x34')]:_0x29317b['model'];if(_0x29f03c['query'][_0xb2f9('0x41')]){_0xab6fad[_0xb2f9('0x42')]=[{'all':!![]}];}_0xab6fad=_[_0xb2f9('0x28')]({},_0xab6fad,_0x29f03c[_0xb2f9('0x40')]);return db[_0xb2f9('0x2f')]['find'](_0xab6fad)['then'](handleEntityNotFound(_0x321af1,null))['then'](respondWithResult(_0x321af1,null))[_0xb2f9('0x44')](handleError(_0x321af1,null));};exports[_0xb2f9('0x47')]=function(_0x3479d5,_0x10a44a){return db[_0xb2f9('0x2f')][_0xb2f9('0x47')](_0x3479d5[_0xb2f9('0x29')],{})[_0xb2f9('0x21')](respondWithResult(_0x10a44a,0xc9))['catch'](handleError(_0x10a44a,null));};exports[_0xb2f9('0x20')]=function(_0x54ad1b,_0x17d00d){if(_0x54ad1b['body']['id']){delete _0x54ad1b[_0xb2f9('0x29')]['id'];}return db[_0xb2f9('0x2f')][_0xb2f9('0x48')]({'where':{'id':_0x54ad1b[_0xb2f9('0x49')]['id']}})[_0xb2f9('0x21')](handleEntityNotFound(_0x17d00d,null))[_0xb2f9('0x21')](saveUpdates(_0x54ad1b[_0xb2f9('0x29')],null))[_0xb2f9('0x21')](respondWithResult(_0x17d00d,null))[_0xb2f9('0x44')](handleError(_0x17d00d,null));};exports['destroy']=function(_0x33377c,_0x5eda68){return db[_0xb2f9('0x2f')][_0xb2f9('0x48')]({'where':{'id':_0x33377c[_0xb2f9('0x49')]['id']}})[_0xb2f9('0x21')](handleEntityNotFound(_0x5eda68,null))[_0xb2f9('0x21')](removeEntity(_0x5eda68,null))[_0xb2f9('0x44')](handleError(_0x5eda68,null));};exports[_0xb2f9('0x4a')]=function(_0x26a43,_0x548d33){return db[_0xb2f9('0x2f')][_0xb2f9('0x4a')]()[_0xb2f9('0x21')](respondWithResult(_0x548d33,null))[_0xb2f9('0x44')](handleError(_0x548d33,null));};