Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / api / jscriptyProject / jscriptyProject.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 _0x3f3b=['Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','params','omit','createdAt','updatedAt','userProfileId','error','getSessions','JscriptySessionReport','nolimit','ProjectId','findOne','JscriptyAnswerReport','number','fromCharCode','indexOf','toString','replace','starttime','parse','startTime','-createdAt','questionId','question','format','YYYY-MM-DD\x20HH:mm:ss','SessionId','answer','isEmpty','now','/tmp/Jscripty_Project_%d_Summary_%s.csv','Content-disposition','attachment;\x20filename=','setHeader','Content-type','text/csv','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','apply','update','then','get','Projects','UserProfileResource','stack','name','index','map','rawAttributes','type','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','JscriptyProject','includeAll','include','findAll','rows','catch','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','autoAssociation'];(function(_0x3f2186,_0x37a65a){var _0x345637=function(_0xc74417){while(--_0xc74417){_0x3f2186['push'](_0x3f2186['shift']());}};_0x345637(++_0x37a65a);}(_0x3f3b,0x17b));var _0xb3f3=function(_0x785376,_0x1d4576){_0x785376=_0x785376-0x0;var _0x2bb87b=_0x3f3b[_0x785376];return _0x2bb87b;};'use strict';var pdf=require(_0xb3f3('0x0'));var emlformat=require(_0xb3f3('0x1'));var rimraf=require(_0xb3f3('0x2'));var zipdir=require(_0xb3f3('0x3'));var jsonpatch=require(_0xb3f3('0x4'));var rp=require(_0xb3f3('0x5'));var moment=require(_0xb3f3('0x6'));var BPromise=require(_0xb3f3('0x7'));var Mustache=require(_0xb3f3('0x8'));var util=require(_0xb3f3('0x9'));var path=require(_0xb3f3('0xa'));var sox=require(_0xb3f3('0xb'));var csv=require(_0xb3f3('0xc'));var ejs=require(_0xb3f3('0xd'));var fs=require('fs');var _=require(_0xb3f3('0xe'));var squel=require(_0xb3f3('0xf'));var crypto=require(_0xb3f3('0x10'));var jsforce=require('jsforce');var deskjs=require(_0xb3f3('0x11'));var toCsv=require(_0xb3f3('0xc'));var querystring=require(_0xb3f3('0x12'));var Papa=require(_0xb3f3('0x13'));var Redis=require(_0xb3f3('0x14'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xb3f3('0x15'));var hardwareService=require(_0xb3f3('0x16'));var logger=require('../../config/logger')('api');var utils=require(_0xb3f3('0x17'));var config=require(_0xb3f3('0x18'));var db=require(_0xb3f3('0x19'))['db'];function respondWithStatusCode(_0x19bdbb,_0x56537f){_0x56537f=_0x56537f||0xcc;return function(_0x3e514e){if(_0x3e514e){return _0x19bdbb[_0xb3f3('0x1a')](_0x56537f);}return _0x19bdbb[_0xb3f3('0x1b')](_0x56537f)[_0xb3f3('0x1c')]();};}function respondWithResult(_0x1d7db8,_0x3e2667){_0x3e2667=_0x3e2667||0xc8;return function(_0x563752){if(_0x563752){return _0x1d7db8[_0xb3f3('0x1b')](_0x3e2667)[_0xb3f3('0x1d')](_0x563752);}};}function respondWithFilteredResult(_0x2293d9,_0x3b998f){return function(_0x1d3ce1){if(_0x1d3ce1){var _0x272ee0=_0x1d3ce1[_0xb3f3('0x1e')],_0x1a0fad=_0x3b998f[_0xb3f3('0x1f')],_0x5addfd=_0x3b998f['offset']+_0x3b998f['limit'],_0x2014c6;if(_0x5addfd>=_0x272ee0){_0x5addfd=_0x272ee0;_0x2014c6=0xc8;}else{_0x2014c6=0xce;}_0x2293d9['status'](_0x2014c6);return _0x2293d9[_0xb3f3('0x20')](_0xb3f3('0x21'),_0x1a0fad+'-'+_0x5addfd+'/'+_0x272ee0)[_0xb3f3('0x1d')](_0x1d3ce1);}return null;};}function patchUpdates(_0xa8ca46){return function(_0x4e48bb){try{jsonpatch[_0xb3f3('0x22')](_0x4e48bb,_0xa8ca46,!![]);}catch(_0x2ce116){return BPromise['reject'](_0x2ce116);}return _0x4e48bb['save']();};}function saveUpdates(_0xe66834,_0x2bcbe3){return function(_0x3bb5ce){if(_0x3bb5ce){return _0x3bb5ce[_0xb3f3('0x23')](_0xe66834)[_0xb3f3('0x24')](function(_0x3c62b5){return _0x3c62b5;});}return null;};}function removeEntity(_0x278f00,_0x5d4e87){return function(_0x28152f){if(_0x28152f){return _0x28152f['destroy']()[_0xb3f3('0x24')](function(){var _0x3e1c12=_0x28152f[_0xb3f3('0x25')]({'plain':!![]});var _0x5c0b85=_0xb3f3('0x26');return db[_0xb3f3('0x27')]['destroy']({'where':{'type':_0x5c0b85,'resourceId':_0x3e1c12['id']}})['then'](function(){return _0x28152f;});})[_0xb3f3('0x24')](function(){_0x278f00[_0xb3f3('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x151bfb,_0x3d83a0){return function(_0x21fdba){if(!_0x21fdba){_0x151bfb[_0xb3f3('0x1a')](0x194);}return _0x21fdba;};}function handleError(_0x4c063b,_0x1b995b){_0x1b995b=_0x1b995b||0x1f4;return function(_0x274db4){logger['error'](_0x274db4[_0xb3f3('0x28')]);if(_0x274db4[_0xb3f3('0x29')]){delete _0x274db4[_0xb3f3('0x29')];}_0x4c063b[_0xb3f3('0x1b')](_0x1b995b)['send'](_0x274db4);};}exports[_0xb3f3('0x2a')]=function(_0xcd975f,_0xd1351b){var _0x380353={},_0x177dfb={},_0x3fc6a5={'count':0x0,'rows':[]};var _0x2c0aef=_[_0xb3f3('0x2b')](db['JscriptyProject'][_0xb3f3('0x2c')],function(_0x441b77){return{'name':_0x441b77['fieldName'],'type':_0x441b77[_0xb3f3('0x2d')]['key']};});_0x177dfb[_0xb3f3('0x2e')]=_[_0xb3f3('0x2b')](_0x2c0aef,_0xb3f3('0x29'));_0x177dfb['query']=_[_0xb3f3('0x2f')](_0xcd975f[_0xb3f3('0x30')]);_0x177dfb[_0xb3f3('0x31')]=_[_0xb3f3('0x32')](_0x177dfb[_0xb3f3('0x2e')],_0x177dfb[_0xb3f3('0x30')]);_0x380353[_0xb3f3('0x33')]=_['intersection'](_0x177dfb[_0xb3f3('0x2e')],qs[_0xb3f3('0x34')](_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x34')]));_0x380353[_0xb3f3('0x33')]=_0x380353[_0xb3f3('0x33')][_0xb3f3('0x35')]?_0x380353[_0xb3f3('0x33')]:_0x177dfb['model'];if(!_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x36')]('nolimit')){_0x380353[_0xb3f3('0x37')]=qs[_0xb3f3('0x37')](_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x37')]);_0x380353[_0xb3f3('0x1f')]=qs['offset'](_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x1f')]);}_0x380353[_0xb3f3('0x38')]=qs[_0xb3f3('0x39')](_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x39')]);_0x380353[_0xb3f3('0x3a')]=qs[_0xb3f3('0x31')](_[_0xb3f3('0x3b')](_0xcd975f[_0xb3f3('0x30')],_0x177dfb['filters']),_0x2c0aef);if(_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x3c')]){_0x380353[_0xb3f3('0x3a')]=_[_0xb3f3('0x3d')](_0x380353['where'],{'$or':_[_0xb3f3('0x2b')](_0x2c0aef,function(_0x447dc8){if(_0x447dc8[_0xb3f3('0x2d')]!==_0xb3f3('0x3e')){var _0x8b065d={};_0x8b065d[_0x447dc8[_0xb3f3('0x29')]]={'$like':'%'+_0xcd975f[_0xb3f3('0x30')][_0xb3f3('0x3c')]+'%'};return _0x8b065d;}})});}_0x380353=_[_0xb3f3('0x3d')]({},_0x380353,_0xcd975f[_0xb3f3('0x3f')]);var _0x56e430={'where':_0x380353['where']};return db[_0xb3f3('0x40')][_0xb3f3('0x1e')](_0x56e430)[_0xb3f3('0x24')](function(_0x583e16){_0x3fc6a5[_0xb3f3('0x1e')]=_0x583e16;if(_0xcd975f['query'][_0xb3f3('0x41')]){_0x380353[_0xb3f3('0x42')]=[{'all':!![]}];}return db['JscriptyProject'][_0xb3f3('0x43')](_0x380353);})[_0xb3f3('0x24')](function(_0x592242){_0x3fc6a5[_0xb3f3('0x44')]=_0x592242;return _0x3fc6a5;})[_0xb3f3('0x24')](respondWithFilteredResult(_0xd1351b,_0x380353))[_0xb3f3('0x45')](handleError(_0xd1351b,null));};exports['show']=function(_0x1ce00f,_0x4410a8){var _0xbc2c72={'raw':![],'where':{'id':_0x1ce00f['params']['id']}},_0x5aa431={};_0x5aa431[_0xb3f3('0x2e')]=_[_0xb3f3('0x2f')](db[_0xb3f3('0x40')][_0xb3f3('0x2c')]);_0x5aa431['query']=_[_0xb3f3('0x2f')](_0x1ce00f[_0xb3f3('0x30')]);_0x5aa431[_0xb3f3('0x31')]=_[_0xb3f3('0x32')](_0x5aa431[_0xb3f3('0x2e')],_0x5aa431[_0xb3f3('0x30')]);_0xbc2c72[_0xb3f3('0x33')]=_[_0xb3f3('0x32')](_0x5aa431[_0xb3f3('0x2e')],qs[_0xb3f3('0x34')](_0x1ce00f[_0xb3f3('0x30')][_0xb3f3('0x34')]));_0xbc2c72[_0xb3f3('0x33')]=_0xbc2c72[_0xb3f3('0x33')][_0xb3f3('0x35')]?_0xbc2c72['attributes']:_0x5aa431['model'];if(_0x1ce00f[_0xb3f3('0x30')]['includeAll']){_0xbc2c72['include']=[{'all':!![]}];}_0xbc2c72=_[_0xb3f3('0x3d')]({},_0xbc2c72,_0x1ce00f[_0xb3f3('0x3f')]);return db[_0xb3f3('0x40')][_0xb3f3('0x46')](_0xbc2c72)[_0xb3f3('0x24')](handleEntityNotFound(_0x4410a8,null))['then'](respondWithResult(_0x4410a8,null))[_0xb3f3('0x45')](handleError(_0x4410a8,null));};exports[_0xb3f3('0x47')]=function(_0x1e2909,_0x34d2c7){return db['JscriptyProject'][_0xb3f3('0x47')](_0x1e2909[_0xb3f3('0x48')],{})[_0xb3f3('0x24')](function(_0x5efdb8){var _0x6260ab=_0x1e2909[_0xb3f3('0x49')][_0xb3f3('0x25')]({'plain':!![]});if(!_0x6260ab)throw new Error(_0xb3f3('0x4a'));if(_0x6260ab['role']==='user'){var _0x33298a=_0x5efdb8[_0xb3f3('0x25')]({'plain':!![]});var _0x15a630=_0xb3f3('0x26');return db[_0xb3f3('0x4b')]['find']({'where':{'name':_0x15a630,'userProfileId':_0x6260ab['userProfileId']},'raw':!![]})['then'](function(_0x57b838){if(_0x57b838&&_0x57b838[_0xb3f3('0x4c')]===0x0){return db[_0xb3f3('0x27')][_0xb3f3('0x47')]({'name':_0x33298a[_0xb3f3('0x29')],'resourceId':_0x33298a['id'],'type':_0x57b838[_0xb3f3('0x29')],'sectionId':_0x57b838['id']},{})[_0xb3f3('0x24')](function(){return _0x5efdb8;});}else{return _0x5efdb8;}})[_0xb3f3('0x45')](function(_0x23a633){logger['error'](_0xb3f3('0x4d'),_0x23a633);throw _0x23a633;});}return _0x5efdb8;})[_0xb3f3('0x24')](respondWithResult(_0x34d2c7,0xc9))['catch'](handleError(_0x34d2c7,null));};exports[_0xb3f3('0x4e')]=function(_0x2f5e93,_0x426ab7){var _0x9835c7={'where':{'id':_0x2f5e93[_0xb3f3('0x4f')]['id']}},_0x4080bf={};_0x4080bf[_0xb3f3('0x2e')]=_[_0xb3f3('0x2f')](db[_0xb3f3('0x40')][_0xb3f3('0x2c')]);_0x9835c7['attributes']=_['intersection'](_0x4080bf['model'],qs['fields'](_0x2f5e93[_0xb3f3('0x30')][_0xb3f3('0x34')]));_0x9835c7[_0xb3f3('0x33')]=_0x9835c7[_0xb3f3('0x33')]['length']?_0x9835c7[_0xb3f3('0x33')]:_0x4080bf[_0xb3f3('0x2e')];if(_0x2f5e93[_0xb3f3('0x30')]['includeAll']){_0x9835c7[_0xb3f3('0x42')]=[{'all':!![]}];}_0x9835c7=_[_0xb3f3('0x3d')]({},_0x9835c7,_0x2f5e93['options']);return db[_0xb3f3('0x40')][_0xb3f3('0x46')](_0x9835c7)['then'](handleEntityNotFound(_0x426ab7,null))['then'](function(_0xcbd4f1){if(_0xcbd4f1){var _0x1bff1c=_0xcbd4f1[_0xb3f3('0x25')]({'plain':!![]});_0x1bff1c=qs[_0xb3f3('0x50')](_0x1bff1c,['id',_0xb3f3('0x51'),_0xb3f3('0x52')]);_0x2f5e93[_0xb3f3('0x48')]=_[_0xb3f3('0x50')](_0x2f5e93[_0xb3f3('0x48')],['id',_0xb3f3('0x51'),_0xb3f3('0x52')]);return db['JscriptyProject'][_0xb3f3('0x47')](_[_0xb3f3('0x3d')](_0x1bff1c,_0x2f5e93[_0xb3f3('0x48')]),{'include':_0x2f5e93['query'][_0xb3f3('0x41')]?[{'all':!![]}]:undefined})[_0xb3f3('0x24')](function(_0x41708b){var _0x1cf60b=_0x2f5e93[_0xb3f3('0x49')][_0xb3f3('0x25')]({'plain':!![]});if(!_0x1cf60b)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1cf60b['role']===_0xb3f3('0x49')){var _0x48d6f9=_0x41708b[_0xb3f3('0x25')]({'plain':!![]});var _0x21006d=_0xb3f3('0x26');return db[_0xb3f3('0x4b')][_0xb3f3('0x46')]({'where':{'name':_0x21006d,'userProfileId':_0x1cf60b[_0xb3f3('0x53')]},'raw':!![]})[_0xb3f3('0x24')](function(_0xaf585f){if(_0xaf585f&&_0xaf585f['autoAssociation']===0x0){return db[_0xb3f3('0x27')][_0xb3f3('0x47')]({'name':_0x48d6f9[_0xb3f3('0x29')],'resourceId':_0x48d6f9['id'],'type':_0xaf585f[_0xb3f3('0x29')],'sectionId':_0xaf585f['id']},{})[_0xb3f3('0x24')](function(){return _0x41708b;});}else{return _0x41708b;}})[_0xb3f3('0x45')](function(_0x39c46e){logger[_0xb3f3('0x54')](_0xb3f3('0x4d'),_0x39c46e);throw _0x39c46e;});}return _0x41708b;});}})[_0xb3f3('0x24')](respondWithResult(_0x426ab7,0xc9))[_0xb3f3('0x45')](handleError(_0x426ab7,null));};exports['update']=function(_0x1aa5fe,_0x2b459b){if(_0x1aa5fe[_0xb3f3('0x48')]['id']){delete _0x1aa5fe[_0xb3f3('0x48')]['id'];}return db[_0xb3f3('0x40')][_0xb3f3('0x46')]({'where':{'id':_0x1aa5fe['params']['id']}})[_0xb3f3('0x24')](handleEntityNotFound(_0x2b459b,null))[_0xb3f3('0x24')](saveUpdates(_0x1aa5fe[_0xb3f3('0x48')],null))['then'](respondWithResult(_0x2b459b,null))[_0xb3f3('0x45')](handleError(_0x2b459b,null));};exports['destroy']=function(_0x5f4b8a,_0x5bb8ef){return db[_0xb3f3('0x40')][_0xb3f3('0x46')]({'where':{'id':_0x5f4b8a[_0xb3f3('0x4f')]['id']}})[_0xb3f3('0x24')](handleEntityNotFound(_0x5bb8ef,null))[_0xb3f3('0x24')](removeEntity(_0x5bb8ef,null))[_0xb3f3('0x45')](handleError(_0x5bb8ef,null));};exports[_0xb3f3('0x55')]=function(_0x495f6d,_0x18f42a,_0x25a66c){var _0x58ce90={'raw':!![],'where':{}};var _0x67fc28={};var _0x3a1dd2={'count':0x0,'rows':[]};return db[_0xb3f3('0x40')]['findOne']({'where':{'id':_0x495f6d[_0xb3f3('0x4f')]['id']}})['then'](handleEntityNotFound(_0x18f42a,null))[_0xb3f3('0x24')](function(_0x26d75a){if(_0x26d75a){_0x67fc28['model']=_[_0xb3f3('0x2f')](db[_0xb3f3('0x56')]['rawAttributes']);_0x67fc28[_0xb3f3('0x30')]=_[_0xb3f3('0x2f')](_0x495f6d[_0xb3f3('0x30')]);_0x67fc28[_0xb3f3('0x31')]=_[_0xb3f3('0x32')](_0x67fc28['model'],_0x67fc28[_0xb3f3('0x30')]);_0x58ce90[_0xb3f3('0x33')]=_[_0xb3f3('0x32')](_0x67fc28['model'],qs['fields'](_0x495f6d[_0xb3f3('0x30')][_0xb3f3('0x34')]));_0x58ce90[_0xb3f3('0x33')]=_0x58ce90[_0xb3f3('0x33')][_0xb3f3('0x35')]?_0x58ce90[_0xb3f3('0x33')]:_0x67fc28[_0xb3f3('0x2e')];if(!_0x495f6d[_0xb3f3('0x30')][_0xb3f3('0x36')](_0xb3f3('0x57'))){_0x58ce90['limit']=qs[_0xb3f3('0x37')](_0x495f6d['query'][_0xb3f3('0x37')]);_0x58ce90['offset']=qs[_0xb3f3('0x1f')](_0x495f6d[_0xb3f3('0x30')][_0xb3f3('0x1f')]);}_0x58ce90[_0xb3f3('0x38')]=qs[_0xb3f3('0x39')](_0x495f6d[_0xb3f3('0x30')][_0xb3f3('0x39')]);_0x58ce90[_0xb3f3('0x3a')]=qs[_0xb3f3('0x31')](_[_0xb3f3('0x3b')](_0x495f6d['query'],_0x67fc28[_0xb3f3('0x31')]));_0x58ce90['where'][_0xb3f3('0x58')]=_0x26d75a['id'];if(_0x495f6d['query'][_0xb3f3('0x3c')]){_0x58ce90['where']=_[_0xb3f3('0x3d')](_0x58ce90['where'],{'$or':_[_0xb3f3('0x2b')](_0x58ce90[_0xb3f3('0x33')],function(_0x5915dc){var _0x317023={};_0x317023[_0x5915dc]={'$like':'%'+_0x495f6d['query'][_0xb3f3('0x3c')]+'%'};return _0x317023;})});}_0x58ce90=_[_0xb3f3('0x3d')]({},_0x58ce90,_0x495f6d['options']);return db[_0xb3f3('0x56')]['count']({'where':_0x58ce90[_0xb3f3('0x3a')]})[_0xb3f3('0x24')](function(_0x1ce8a1){_0x3a1dd2[_0xb3f3('0x1e')]=_0x1ce8a1;if(_0x495f6d[_0xb3f3('0x30')]['includeAll']){_0x58ce90['include']=[{'all':!![]}];}return db['JscriptySessionReport'][_0xb3f3('0x43')](_0x58ce90);})[_0xb3f3('0x24')](function(_0x4a6730){_0x3a1dd2[_0xb3f3('0x44')]=_0x4a6730;return _0x3a1dd2;});}})[_0xb3f3('0x24')](respondWithFilteredResult(_0x18f42a,_0x58ce90))[_0xb3f3('0x45')](handleError(_0x18f42a,null));};exports['getAnswers']=function(_0x53a1a2,_0x5e493d,_0x4f1a75){var _0x47eb6f={'raw':!![],'where':{}};var _0x315088={};var _0x3a33e1={'count':0x0,'rows':[]};return db[_0xb3f3('0x40')][_0xb3f3('0x59')]({'where':{'id':_0x53a1a2['params']['id']}})[_0xb3f3('0x24')](handleEntityNotFound(_0x5e493d,null))[_0xb3f3('0x24')](function(_0x50feb8){if(_0x50feb8){_0x315088[_0xb3f3('0x2e')]=_[_0xb3f3('0x2f')](db[_0xb3f3('0x5a')][_0xb3f3('0x2c')]);_0x315088[_0xb3f3('0x30')]=_[_0xb3f3('0x2f')](_0x53a1a2[_0xb3f3('0x30')]);_0x315088['filters']=_[_0xb3f3('0x32')](_0x315088['model'],_0x315088[_0xb3f3('0x30')]);_0x47eb6f[_0xb3f3('0x33')]=_[_0xb3f3('0x32')](_0x315088['model'],qs[_0xb3f3('0x34')](_0x53a1a2[_0xb3f3('0x30')][_0xb3f3('0x34')]));_0x47eb6f[_0xb3f3('0x33')]=_0x47eb6f[_0xb3f3('0x33')]['length']?_0x47eb6f[_0xb3f3('0x33')]:_0x315088['model'];if(!_0x53a1a2[_0xb3f3('0x30')][_0xb3f3('0x36')](_0xb3f3('0x57'))){_0x47eb6f['limit']=qs[_0xb3f3('0x37')](_0x53a1a2[_0xb3f3('0x30')][_0xb3f3('0x37')]);_0x47eb6f[_0xb3f3('0x1f')]=qs[_0xb3f3('0x1f')](_0x53a1a2[_0xb3f3('0x30')][_0xb3f3('0x1f')]);}_0x47eb6f[_0xb3f3('0x38')]=qs[_0xb3f3('0x39')](_0x53a1a2[_0xb3f3('0x30')][_0xb3f3('0x39')]);_0x47eb6f[_0xb3f3('0x3a')]=qs['filters'](_['pick'](_0x53a1a2[_0xb3f3('0x30')],_0x315088[_0xb3f3('0x31')]));_0x47eb6f['where']['ProjectId']=_0x50feb8['id'];if(_0x53a1a2[_0xb3f3('0x30')]['filter']){_0x47eb6f[_0xb3f3('0x3a')]=_[_0xb3f3('0x3d')](_0x47eb6f['where'],{'$or':_[_0xb3f3('0x2b')](_0x47eb6f[_0xb3f3('0x33')],function(_0x14283c){var _0x508f0d={};_0x508f0d[_0x14283c]={'$like':'%'+_0x53a1a2['query']['filter']+'%'};return _0x508f0d;})});}_0x47eb6f=_[_0xb3f3('0x3d')]({},_0x47eb6f,_0x53a1a2[_0xb3f3('0x3f')]);return db[_0xb3f3('0x5a')][_0xb3f3('0x1e')]({'where':_0x47eb6f[_0xb3f3('0x3a')]})['then'](function(_0x188598){_0x3a33e1[_0xb3f3('0x1e')]=_0x188598;if(_0x53a1a2['query'][_0xb3f3('0x41')]){_0x47eb6f[_0xb3f3('0x42')]=[{'all':!![]}];}return db[_0xb3f3('0x5a')]['findAll'](_0x47eb6f);})['then'](function(_0x14035d){_0x3a33e1[_0xb3f3('0x44')]=_0x14035d;return _0x3a33e1;});}})[_0xb3f3('0x24')](respondWithFilteredResult(_0x5e493d,_0x47eb6f))[_0xb3f3('0x45')](handleError(_0x5e493d,null));};function char(_0x1eb2c5){return _0xb3f3('0x5b')===typeof _0x1eb2c5?String[_0xb3f3('0x5c')][_0xb3f3('0x22')](null,arguments):_0x1eb2c5;}function needsEncapsulation(_0x127f70){return!!_0x127f70&&(_0x127f70['toString']()[_0xb3f3('0x5d')](char(0xd))>=0x0||_0x127f70[_0xb3f3('0x5e')]()['indexOf'](char(0xa))>=0x0||_0x127f70[_0xb3f3('0x5e')]()['indexOf'](char(0x2c))>=0x0||_0x127f70[_0xb3f3('0x5e')]()[_0xb3f3('0x5d')](char(0x22))>=0x0);}function encapsulate(_0x68ee1a){var _0x1eb19f=char(0x22),_0x221617='\x5c'+char(0x22),_0x5a81e8=_0x68ee1a['toString']()[_0xb3f3('0x5f')](new RegExp(_0x1eb19f,'g'),_0x221617);return _0x1eb19f+_0x5a81e8+_0x1eb19f;}exports['getSummary']=function(_0x4543e8,_0x57e0fd,_0x5416da){var _0x560b7e,_0x330a95;var _0x160f87={'where':{'ProjectId':_0x4543e8[_0xb3f3('0x4f')]['id']}};if(_0x4543e8[_0xb3f3('0x30')]['startTime']){_0x160f87[_0xb3f3('0x3a')][_0xb3f3('0x60')]=JSON[_0xb3f3('0x61')](_0x4543e8[_0xb3f3('0x30')][_0xb3f3('0x62')]);}return db['JscriptySessionReport'][_0xb3f3('0x43')](_0x160f87)['then'](handleEntityNotFound(_0x57e0fd,null))[_0xb3f3('0x24')](function(_0xed106c){if(_0xed106c){_0x560b7e=_0xed106c;return db['JscriptyQuestionReport'][_0xb3f3('0x43')]({'where':{'SessionId':{'$in':_['map'](_0x560b7e,'id')},'ProjectId':_0x4543e8['params']['id']},'order':_0xb3f3('0x63')});}})[_0xb3f3('0x24')](handleEntityNotFound(_0x57e0fd,null))[_0xb3f3('0x24')](function(_0x33ec59){if(_0x33ec59){_0x330a95=_0x33ec59;var _0xd69b4={};for(var _0x45edca=0x0,_0x35594f=_0x330a95['length'];_0x45edca<_0x35594f;_0x45edca++){if(!_0xd69b4[_0xb3f3('0x36')](_0x330a95[_0x45edca][_0xb3f3('0x64')])){_0xd69b4[_0x330a95[_0x45edca][_0xb3f3('0x64')]]=needsEncapsulation(_0x330a95[_0x45edca][_0xb3f3('0x65')])?encapsulate(_0x330a95[_0x45edca]['question']):_0x330a95[_0x45edca]['question'];}}var _0x1060e5=[],_0x5204eb={};for(var _0x34ea01=0x0,_0xfd5f36=_0x560b7e[_0xb3f3('0x35')];_0x34ea01<_0xfd5f36;_0x34ea01++){_0x5204eb={'ProjectId':_0x4543e8[_0xb3f3('0x4f')]['id'],'SessionId':_0x560b7e[_0x34ea01]['id'],'StartTime':moment(_0x560b7e[_0x34ea01][_0xb3f3('0x60')])[_0xb3f3('0x66')](_0xb3f3('0x67'))};for(var _0xd021b0=0x0,_0x5ae540=_0x330a95[_0xb3f3('0x35')];_0xd021b0<_0x5ae540;_0xd021b0++){if(_0x330a95[_0xd021b0][_0xb3f3('0x68')]==_0x560b7e[_0x34ea01]['id']&&_0xd69b4['hasOwnProperty'](_0x330a95[_0xd021b0][_0xb3f3('0x64')])){_0x5204eb[_0xd69b4[_0x330a95[_0xd021b0][_0xb3f3('0x64')]]]=_0x330a95[_0xd021b0][_0xb3f3('0x69')];}}for(var _0x4dc75d in _0xd69b4){if(!_0x5204eb[_0xb3f3('0x36')](_0xd69b4[_0x4dc75d])){_0x5204eb[_0xd69b4[_0x4dc75d]]=null;}}_0x1060e5['push'](_0x5204eb);}return _0x1060e5;}})['then'](function(_0x4db5b3){if(!_[_0xb3f3('0x6a')](_0x4db5b3)){var _0x18a78f=toCsv(_0x4db5b3);var _0x32d28=Date[_0xb3f3('0x6b')]();fs['writeFileSync'](util['format'](_0xb3f3('0x6c'),_0x4543e8['params']['id'],_0x32d28),_0x18a78f);_0x57e0fd['setHeader'](_0xb3f3('0x6d'),_0xb3f3('0x6e')+util[_0xb3f3('0x66')]('Jscripty_Project_%d_Summary_%s.csv',_0x4543e8[_0xb3f3('0x4f')]['id'],_0x32d28));_0x57e0fd[_0xb3f3('0x6f')](_0xb3f3('0x70'),_0xb3f3('0x71'));return _0x57e0fd['download'](util[_0xb3f3('0x66')](_0xb3f3('0x6c'),_0x4543e8[_0xb3f3('0x4f')]['id'],_0x32d28));}else{return _0x57e0fd[_0xb3f3('0x1a')](0xcc);}})[_0xb3f3('0x45')](handleError(_0x57e0fd,null));};