Built motion from commit (unavailable).|2.5.19
[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 _0xcdee=['options','include','findAll','rows','catch','show','params','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','role','autoAssociation','getSessions','JscriptySessionReport','rawAttributes','ProjectId','getAnswers','findOne','JscriptyAnswerReport','number','fromCharCode','toString','indexOf','replace','getSummary','startTime','starttime','parse','-createdAt','questionId','question','format','SessionId','answer','push','isEmpty','now','writeFileSync','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','attachment;\x20filename=','text/csv','download','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','reject','update','then','get','Projects','destroy','error','stack','name','send','map','JscriptyProject','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL'];(function(_0x27a0a0,_0x1f4a23){var _0x31336f=function(_0x4ef92d){while(--_0x4ef92d){_0x27a0a0['push'](_0x27a0a0['shift']());}};_0x31336f(++_0x1f4a23);}(_0xcdee,0xaf));var _0xecde=function(_0xe0b5eb,_0x2c38d1){_0xe0b5eb=_0xe0b5eb-0x0;var _0x3350b5=_0xcdee[_0xe0b5eb];return _0x3350b5;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xecde('0x0'));var rimraf=require(_0xecde('0x1'));var zipdir=require(_0xecde('0x2'));var jsonpatch=require(_0xecde('0x3'));var rp=require('request-promise');var moment=require(_0xecde('0x4'));var BPromise=require(_0xecde('0x5'));var Mustache=require(_0xecde('0x6'));var util=require(_0xecde('0x7'));var path=require(_0xecde('0x8'));var sox=require(_0xecde('0x9'));var csv=require(_0xecde('0xa'));var ejs=require(_0xecde('0xb'));var fs=require('fs');var _=require(_0xecde('0xc'));var squel=require(_0xecde('0xd'));var crypto=require(_0xecde('0xe'));var jsforce=require(_0xecde('0xf'));var deskjs=require(_0xecde('0x10'));var toCsv=require(_0xecde('0xa'));var querystring=require(_0xecde('0x11'));var Papa=require(_0xecde('0x12'));var Redis=require(_0xecde('0x13'));var authService=require(_0xecde('0x14'));var qs=require(_0xecde('0x15'));var as=require(_0xecde('0x16'));var hardwareService=require(_0xecde('0x17'));var logger=require(_0xecde('0x18'))('api');var utils=require('../../config/utils');var config=require(_0xecde('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0xecde('0x1a'))['db'];function respondWithStatusCode(_0x183da7,_0x53cfe){_0x53cfe=_0x53cfe||0xcc;return function(_0x337383){if(_0x337383){return _0x183da7[_0xecde('0x1b')](_0x53cfe);}return _0x183da7['status'](_0x53cfe)[_0xecde('0x1c')]();};}function respondWithResult(_0x3e28c5,_0x43d8ca){_0x43d8ca=_0x43d8ca||0xc8;return function(_0x2f8493){if(_0x2f8493){return _0x3e28c5[_0xecde('0x1d')](_0x43d8ca)[_0xecde('0x1e')](_0x2f8493);}};}function respondWithFilteredResult(_0x4bbf81,_0x3a35d7){return function(_0x38cbb9){if(_0x38cbb9){var _0x2255c7=_0x38cbb9[_0xecde('0x1f')],_0x3771b3=_0x3a35d7['offset'],_0x3f242b=_0x3a35d7[_0xecde('0x20')]+_0x3a35d7[_0xecde('0x21')],_0x37b1f6;if(_0x3f242b>=_0x2255c7){_0x3f242b=_0x2255c7;_0x37b1f6=0xc8;}else{_0x37b1f6=0xce;}_0x4bbf81[_0xecde('0x1d')](_0x37b1f6);return _0x4bbf81[_0xecde('0x22')](_0xecde('0x23'),_0x3771b3+'-'+_0x3f242b+'/'+_0x2255c7)[_0xecde('0x1e')](_0x38cbb9);}return null;};}function patchUpdates(_0x341e8a){return function(_0x3204bc){try{jsonpatch[_0xecde('0x24')](_0x3204bc,_0x341e8a,!![]);}catch(_0x5980ba){return BPromise[_0xecde('0x25')](_0x5980ba);}return _0x3204bc['save']();};}function saveUpdates(_0x406d1c,_0x2d7348){return function(_0x37be2b){if(_0x37be2b){return _0x37be2b[_0xecde('0x26')](_0x406d1c)[_0xecde('0x27')](function(_0x38f382){return _0x38f382;});}return null;};}function removeEntity(_0x3244f9,_0x209ae5){return function(_0x481ccd){if(_0x481ccd){return _0x481ccd['destroy']()['then'](function(){var _0x4fe245=_0x481ccd[_0xecde('0x28')]({'plain':!![]});var _0x5b11b9=_0xecde('0x29');return db['UserProfileResource'][_0xecde('0x2a')]({'where':{'type':_0x5b11b9,'resourceId':_0x4fe245['id']}})[_0xecde('0x27')](function(){return _0x481ccd;});})['then'](function(){_0x3244f9[_0xecde('0x1d')](0xcc)[_0xecde('0x1c')]();});}};}function handleEntityNotFound(_0x8bb691,_0x1aaa9d){return function(_0x26e9bd){if(!_0x26e9bd){_0x8bb691[_0xecde('0x1b')](0x194);}return _0x26e9bd;};}function handleError(_0x82ecbe,_0x5b558a){_0x5b558a=_0x5b558a||0x1f4;return function(_0x492c9a){logger[_0xecde('0x2b')](_0x492c9a[_0xecde('0x2c')]);if(_0x492c9a['name']){delete _0x492c9a[_0xecde('0x2d')];}_0x82ecbe['status'](_0x5b558a)[_0xecde('0x2e')](_0x492c9a);};}exports['index']=function(_0x156ecd,_0x3fcdc3){var _0x7e71ef={},_0x4fdb87={},_0x458cc7={'count':0x0,'rows':[]};var _0x393500=_[_0xecde('0x2f')](db[_0xecde('0x30')]['rawAttributes'],function(_0x333803){return{'name':_0x333803[_0xecde('0x31')],'type':_0x333803[_0xecde('0x32')][_0xecde('0x33')]};});_0x4fdb87[_0xecde('0x34')]=_[_0xecde('0x2f')](_0x393500,_0xecde('0x2d'));_0x4fdb87[_0xecde('0x35')]=_[_0xecde('0x36')](_0x156ecd['query']);_0x4fdb87[_0xecde('0x37')]=_[_0xecde('0x38')](_0x4fdb87['model'],_0x4fdb87[_0xecde('0x35')]);_0x7e71ef[_0xecde('0x39')]=_[_0xecde('0x38')](_0x4fdb87[_0xecde('0x34')],qs[_0xecde('0x3a')](_0x156ecd[_0xecde('0x35')][_0xecde('0x3a')]));_0x7e71ef[_0xecde('0x39')]=_0x7e71ef[_0xecde('0x39')][_0xecde('0x3b')]?_0x7e71ef[_0xecde('0x39')]:_0x4fdb87[_0xecde('0x34')];if(!_0x156ecd[_0xecde('0x35')][_0xecde('0x3c')](_0xecde('0x3d'))){_0x7e71ef[_0xecde('0x21')]=qs[_0xecde('0x21')](_0x156ecd[_0xecde('0x35')][_0xecde('0x21')]);_0x7e71ef[_0xecde('0x20')]=qs['offset'](_0x156ecd['query'][_0xecde('0x20')]);}_0x7e71ef[_0xecde('0x3e')]=qs[_0xecde('0x3f')](_0x156ecd[_0xecde('0x35')][_0xecde('0x3f')]);_0x7e71ef[_0xecde('0x40')]=qs[_0xecde('0x37')](_[_0xecde('0x41')](_0x156ecd[_0xecde('0x35')],_0x4fdb87[_0xecde('0x37')]),_0x393500);if(_0x156ecd[_0xecde('0x35')][_0xecde('0x42')]){_0x7e71ef[_0xecde('0x40')]=_[_0xecde('0x43')](_0x7e71ef[_0xecde('0x40')],{'$or':_['map'](_0x393500,function(_0xc61cd7){if(_0xc61cd7[_0xecde('0x32')]!==_0xecde('0x44')){var _0x493a89={};_0x493a89[_0xc61cd7[_0xecde('0x2d')]]={'$like':'%'+_0x156ecd['query'][_0xecde('0x42')]+'%'};return _0x493a89;}})});}_0x7e71ef=_['merge']({},_0x7e71ef,_0x156ecd[_0xecde('0x45')]);var _0x1ac923={'where':_0x7e71ef[_0xecde('0x40')]};return db[_0xecde('0x30')][_0xecde('0x1f')](_0x1ac923)[_0xecde('0x27')](function(_0xe16f1c){_0x458cc7['count']=_0xe16f1c;if(_0x156ecd[_0xecde('0x35')]['includeAll']){_0x7e71ef[_0xecde('0x46')]=[{'all':!![]}];}return db['JscriptyProject'][_0xecde('0x47')](_0x7e71ef);})[_0xecde('0x27')](function(_0x2c1ac8){_0x458cc7[_0xecde('0x48')]=_0x2c1ac8;return _0x458cc7;})['then'](respondWithFilteredResult(_0x3fcdc3,_0x7e71ef))[_0xecde('0x49')](handleError(_0x3fcdc3,null));};exports[_0xecde('0x4a')]=function(_0xe14b8d,_0x1b9d43){var _0x4831cb={'raw':![],'where':{'id':_0xe14b8d[_0xecde('0x4b')]['id']}},_0x41c44f={};_0x41c44f['model']=_[_0xecde('0x36')](db[_0xecde('0x30')]['rawAttributes']);_0x41c44f[_0xecde('0x35')]=_[_0xecde('0x36')](_0xe14b8d[_0xecde('0x35')]);_0x41c44f[_0xecde('0x37')]=_[_0xecde('0x38')](_0x41c44f[_0xecde('0x34')],_0x41c44f[_0xecde('0x35')]);_0x4831cb[_0xecde('0x39')]=_[_0xecde('0x38')](_0x41c44f[_0xecde('0x34')],qs[_0xecde('0x3a')](_0xe14b8d['query']['fields']));_0x4831cb['attributes']=_0x4831cb[_0xecde('0x39')]['length']?_0x4831cb[_0xecde('0x39')]:_0x41c44f[_0xecde('0x34')];if(_0xe14b8d[_0xecde('0x35')][_0xecde('0x4c')]){_0x4831cb['include']=[{'all':!![]}];}_0x4831cb=_[_0xecde('0x43')]({},_0x4831cb,_0xe14b8d[_0xecde('0x45')]);return db[_0xecde('0x30')][_0xecde('0x4d')](_0x4831cb)['then'](handleEntityNotFound(_0x1b9d43,null))[_0xecde('0x27')](respondWithResult(_0x1b9d43,null))[_0xecde('0x49')](handleError(_0x1b9d43,null));};exports['create']=function(_0x26a087,_0x1da9c0){return db[_0xecde('0x30')][_0xecde('0x4e')](_0x26a087[_0xecde('0x4f')],{})['then'](function(_0x33947e){var _0x1d7b2b=_0x26a087[_0xecde('0x50')][_0xecde('0x28')]({'plain':!![]});if(!_0x1d7b2b)throw new Error(_0xecde('0x51'));if(_0x1d7b2b['role']===_0xecde('0x50')){var _0x4ddf66=_0x33947e[_0xecde('0x28')]({'plain':!![]});var _0x452795=_0xecde('0x29');return db[_0xecde('0x52')][_0xecde('0x4d')]({'where':{'name':_0x452795,'userProfileId':_0x1d7b2b[_0xecde('0x53')]},'raw':!![]})[_0xecde('0x27')](function(_0x57d5e8){if(_0x57d5e8&&_0x57d5e8['autoAssociation']===0x0){return db[_0xecde('0x54')][_0xecde('0x4e')]({'name':_0x4ddf66[_0xecde('0x2d')],'resourceId':_0x4ddf66['id'],'type':_0x57d5e8[_0xecde('0x2d')],'sectionId':_0x57d5e8['id']},{})[_0xecde('0x27')](function(){return _0x33947e;});}else{return _0x33947e;}})[_0xecde('0x49')](function(_0x1a9db2){logger[_0xecde('0x2b')](_0xecde('0x55'),_0x1a9db2);throw _0x1a9db2;});}return _0x33947e;})[_0xecde('0x27')](respondWithResult(_0x1da9c0,0xc9))[_0xecde('0x49')](handleError(_0x1da9c0,null));};exports[_0xecde('0x56')]=function(_0x4e5067,_0x4cfb3f){var _0x7fa033={'where':{'id':_0x4e5067[_0xecde('0x4b')]['id']}},_0x7dccc8={};_0x7dccc8[_0xecde('0x34')]=_[_0xecde('0x36')](db[_0xecde('0x30')]['rawAttributes']);_0x7fa033[_0xecde('0x39')]=_[_0xecde('0x38')](_0x7dccc8[_0xecde('0x34')],qs['fields'](_0x4e5067[_0xecde('0x35')][_0xecde('0x3a')]));_0x7fa033[_0xecde('0x39')]=_0x7fa033[_0xecde('0x39')][_0xecde('0x3b')]?_0x7fa033[_0xecde('0x39')]:_0x7dccc8['model'];if(_0x4e5067['query'][_0xecde('0x4c')]){_0x7fa033[_0xecde('0x46')]=[{'all':!![]}];}_0x7fa033=_[_0xecde('0x43')]({},_0x7fa033,_0x4e5067[_0xecde('0x45')]);return db['JscriptyProject'][_0xecde('0x4d')](_0x7fa033)[_0xecde('0x27')](handleEntityNotFound(_0x4cfb3f,null))[_0xecde('0x27')](function(_0x161b94){if(_0x161b94){var _0x194f4d=_0x161b94['get']({'plain':!![]});_0x194f4d=qs[_0xecde('0x57')](_0x194f4d,['id',_0xecde('0x58'),'updatedAt']);_0x4e5067['body']=_[_0xecde('0x57')](_0x4e5067['body'],['id',_0xecde('0x58'),'updatedAt']);return db[_0xecde('0x30')]['create'](_[_0xecde('0x43')](_0x194f4d,_0x4e5067[_0xecde('0x4f')]),{'include':_0x4e5067[_0xecde('0x35')][_0xecde('0x4c')]?[{'all':!![]}]:undefined})[_0xecde('0x27')](function(_0xf0840e){var _0x2b8fdd=_0x4e5067['user']['get']({'plain':!![]});if(!_0x2b8fdd)throw new Error(_0xecde('0x51'));if(_0x2b8fdd[_0xecde('0x59')]===_0xecde('0x50')){var _0x62e7f5=_0xf0840e[_0xecde('0x28')]({'plain':!![]});var _0x209ea5=_0xecde('0x29');return db[_0xecde('0x52')][_0xecde('0x4d')]({'where':{'name':_0x209ea5,'userProfileId':_0x2b8fdd[_0xecde('0x53')]},'raw':!![]})[_0xecde('0x27')](function(_0x206733){if(_0x206733&&_0x206733[_0xecde('0x5a')]===0x0){return db[_0xecde('0x54')]['create']({'name':_0x62e7f5[_0xecde('0x2d')],'resourceId':_0x62e7f5['id'],'type':_0x206733['name'],'sectionId':_0x206733['id']},{})[_0xecde('0x27')](function(){return _0xf0840e;});}else{return _0xf0840e;}})[_0xecde('0x49')](function(_0x231982){logger[_0xecde('0x2b')](_0xecde('0x55'),_0x231982);throw _0x231982;});}return _0xf0840e;});}})[_0xecde('0x27')](respondWithResult(_0x4cfb3f,0xc9))[_0xecde('0x49')](handleError(_0x4cfb3f,null));};exports[_0xecde('0x26')]=function(_0x575263,_0x213ffa){if(_0x575263[_0xecde('0x4f')]['id']){delete _0x575263['body']['id'];}return db[_0xecde('0x30')][_0xecde('0x4d')]({'where':{'id':_0x575263[_0xecde('0x4b')]['id']}})[_0xecde('0x27')](handleEntityNotFound(_0x213ffa,null))[_0xecde('0x27')](saveUpdates(_0x575263['body'],null))[_0xecde('0x27')](respondWithResult(_0x213ffa,null))[_0xecde('0x49')](handleError(_0x213ffa,null));};exports[_0xecde('0x2a')]=function(_0x3ef46a,_0x4e5531){return db['JscriptyProject'][_0xecde('0x4d')]({'where':{'id':_0x3ef46a['params']['id']}})['then'](handleEntityNotFound(_0x4e5531,null))[_0xecde('0x27')](removeEntity(_0x4e5531,null))[_0xecde('0x49')](handleError(_0x4e5531,null));};exports[_0xecde('0x5b')]=function(_0x55bb3d,_0xaa88a8,_0x4646bf){var _0x5d11f0={'raw':!![],'where':{}};var _0x328401={};var _0x3e1cc9={'count':0x0,'rows':[]};return db['JscriptyProject']['findOne']({'where':{'id':_0x55bb3d[_0xecde('0x4b')]['id']}})[_0xecde('0x27')](handleEntityNotFound(_0xaa88a8,null))['then'](function(_0xc4a8d9){if(_0xc4a8d9){_0x328401['model']=_[_0xecde('0x36')](db[_0xecde('0x5c')][_0xecde('0x5d')]);_0x328401['query']=_[_0xecde('0x36')](_0x55bb3d['query']);_0x328401[_0xecde('0x37')]=_[_0xecde('0x38')](_0x328401[_0xecde('0x34')],_0x328401[_0xecde('0x35')]);_0x5d11f0[_0xecde('0x39')]=_['intersection'](_0x328401[_0xecde('0x34')],qs['fields'](_0x55bb3d[_0xecde('0x35')][_0xecde('0x3a')]));_0x5d11f0['attributes']=_0x5d11f0[_0xecde('0x39')][_0xecde('0x3b')]?_0x5d11f0['attributes']:_0x328401['model'];if(!_0x55bb3d['query'][_0xecde('0x3c')](_0xecde('0x3d'))){_0x5d11f0[_0xecde('0x21')]=qs['limit'](_0x55bb3d[_0xecde('0x35')][_0xecde('0x21')]);_0x5d11f0[_0xecde('0x20')]=qs['offset'](_0x55bb3d['query']['offset']);}_0x5d11f0[_0xecde('0x3e')]=qs[_0xecde('0x3f')](_0x55bb3d['query']['sort']);_0x5d11f0['where']=qs[_0xecde('0x37')](_['pick'](_0x55bb3d[_0xecde('0x35')],_0x328401['filters']));_0x5d11f0['where'][_0xecde('0x5e')]=_0xc4a8d9['id'];if(_0x55bb3d[_0xecde('0x35')][_0xecde('0x42')]){_0x5d11f0['where']=_['merge'](_0x5d11f0[_0xecde('0x40')],{'$or':_[_0xecde('0x2f')](_0x5d11f0['attributes'],function(_0x3115bd){var _0x4df2f6={};_0x4df2f6[_0x3115bd]={'$like':'%'+_0x55bb3d[_0xecde('0x35')][_0xecde('0x42')]+'%'};return _0x4df2f6;})});}_0x5d11f0=_[_0xecde('0x43')]({},_0x5d11f0,_0x55bb3d[_0xecde('0x45')]);return db[_0xecde('0x5c')]['count']({'where':_0x5d11f0[_0xecde('0x40')]})[_0xecde('0x27')](function(_0x453e98){_0x3e1cc9[_0xecde('0x1f')]=_0x453e98;if(_0x55bb3d[_0xecde('0x35')][_0xecde('0x4c')]){_0x5d11f0['include']=[{'all':!![]}];}return db[_0xecde('0x5c')][_0xecde('0x47')](_0x5d11f0);})['then'](function(_0x3f744c){_0x3e1cc9[_0xecde('0x48')]=_0x3f744c;return _0x3e1cc9;});}})[_0xecde('0x27')](respondWithFilteredResult(_0xaa88a8,_0x5d11f0))['catch'](handleError(_0xaa88a8,null));};exports[_0xecde('0x5f')]=function(_0x742c51,_0x8eb734,_0x502f61){var _0x482dcb={'raw':!![],'where':{}};var _0x1097b4={};var _0x2e406d={'count':0x0,'rows':[]};return db[_0xecde('0x30')][_0xecde('0x60')]({'where':{'id':_0x742c51[_0xecde('0x4b')]['id']}})[_0xecde('0x27')](handleEntityNotFound(_0x8eb734,null))[_0xecde('0x27')](function(_0x11df3f){if(_0x11df3f){_0x1097b4[_0xecde('0x34')]=_[_0xecde('0x36')](db[_0xecde('0x61')]['rawAttributes']);_0x1097b4[_0xecde('0x35')]=_[_0xecde('0x36')](_0x742c51[_0xecde('0x35')]);_0x1097b4['filters']=_[_0xecde('0x38')](_0x1097b4[_0xecde('0x34')],_0x1097b4[_0xecde('0x35')]);_0x482dcb[_0xecde('0x39')]=_['intersection'](_0x1097b4[_0xecde('0x34')],qs[_0xecde('0x3a')](_0x742c51[_0xecde('0x35')]['fields']));_0x482dcb[_0xecde('0x39')]=_0x482dcb[_0xecde('0x39')][_0xecde('0x3b')]?_0x482dcb[_0xecde('0x39')]:_0x1097b4[_0xecde('0x34')];if(!_0x742c51[_0xecde('0x35')][_0xecde('0x3c')](_0xecde('0x3d'))){_0x482dcb[_0xecde('0x21')]=qs[_0xecde('0x21')](_0x742c51[_0xecde('0x35')][_0xecde('0x21')]);_0x482dcb[_0xecde('0x20')]=qs[_0xecde('0x20')](_0x742c51[_0xecde('0x35')][_0xecde('0x20')]);}_0x482dcb[_0xecde('0x3e')]=qs[_0xecde('0x3f')](_0x742c51[_0xecde('0x35')]['sort']);_0x482dcb[_0xecde('0x40')]=qs['filters'](_['pick'](_0x742c51[_0xecde('0x35')],_0x1097b4['filters']));_0x482dcb['where'][_0xecde('0x5e')]=_0x11df3f['id'];if(_0x742c51['query'][_0xecde('0x42')]){_0x482dcb['where']=_[_0xecde('0x43')](_0x482dcb['where'],{'$or':_[_0xecde('0x2f')](_0x482dcb['attributes'],function(_0xc11f87){var _0x37d71c={};_0x37d71c[_0xc11f87]={'$like':'%'+_0x742c51['query'][_0xecde('0x42')]+'%'};return _0x37d71c;})});}_0x482dcb=_[_0xecde('0x43')]({},_0x482dcb,_0x742c51[_0xecde('0x45')]);return db[_0xecde('0x61')][_0xecde('0x1f')]({'where':_0x482dcb['where']})[_0xecde('0x27')](function(_0x47d0c8){_0x2e406d['count']=_0x47d0c8;if(_0x742c51[_0xecde('0x35')][_0xecde('0x4c')]){_0x482dcb['include']=[{'all':!![]}];}return db[_0xecde('0x61')][_0xecde('0x47')](_0x482dcb);})[_0xecde('0x27')](function(_0x10c12b){_0x2e406d['rows']=_0x10c12b;return _0x2e406d;});}})[_0xecde('0x27')](respondWithFilteredResult(_0x8eb734,_0x482dcb))['catch'](handleError(_0x8eb734,null));};function char(_0x530382){return _0xecde('0x62')===typeof _0x530382?String[_0xecde('0x63')][_0xecde('0x24')](null,arguments):_0x530382;}function needsEncapsulation(_0x4653bb){return!!_0x4653bb&&(_0x4653bb[_0xecde('0x64')]()['indexOf'](char(0xd))>=0x0||_0x4653bb[_0xecde('0x64')]()[_0xecde('0x65')](char(0xa))>=0x0||_0x4653bb['toString']()[_0xecde('0x65')](char(0x2c))>=0x0||_0x4653bb[_0xecde('0x64')]()['indexOf'](char(0x22))>=0x0);}function encapsulate(_0x313618){var _0x1b0eb4=char(0x22),_0x989436='\x5c'+char(0x22),_0x486c3c=_0x313618[_0xecde('0x64')]()[_0xecde('0x66')](new RegExp(_0x1b0eb4,'g'),_0x989436);return _0x1b0eb4+_0x486c3c+_0x1b0eb4;}exports[_0xecde('0x67')]=function(_0x514a10,_0x3a26fe,_0xcd4c69){var _0x25dbb3,_0x553c64;var _0x3a47b6={'where':{'ProjectId':_0x514a10['params']['id']}};if(_0x514a10['query'][_0xecde('0x68')]){_0x3a47b6[_0xecde('0x40')][_0xecde('0x69')]=JSON[_0xecde('0x6a')](_0x514a10[_0xecde('0x35')][_0xecde('0x68')]);}return db['JscriptySessionReport'][_0xecde('0x47')](_0x3a47b6)['then'](handleEntityNotFound(_0x3a26fe,null))['then'](function(_0x2be3ed){if(_0x2be3ed){_0x25dbb3=_0x2be3ed;return db['JscriptyQuestionReport'][_0xecde('0x47')]({'where':{'SessionId':{'$in':_[_0xecde('0x2f')](_0x25dbb3,'id')},'ProjectId':_0x514a10['params']['id']},'order':_0xecde('0x6b')});}})[_0xecde('0x27')](handleEntityNotFound(_0x3a26fe,null))[_0xecde('0x27')](function(_0x5cb5e1){if(_0x5cb5e1){_0x553c64=_0x5cb5e1;var _0x16e1f3={};for(var _0x516da6=0x0,_0x444332=_0x553c64[_0xecde('0x3b')];_0x516da6<_0x444332;_0x516da6++){if(!_0x16e1f3['hasOwnProperty'](_0x553c64[_0x516da6][_0xecde('0x6c')])){_0x16e1f3[_0x553c64[_0x516da6][_0xecde('0x6c')]]=needsEncapsulation(_0x553c64[_0x516da6][_0xecde('0x6d')])?encapsulate(_0x553c64[_0x516da6][_0xecde('0x6d')]):_0x553c64[_0x516da6][_0xecde('0x6d')];}}var _0x427d5b=[],_0x4090e5={};for(var _0x31e0c1=0x0,_0x57a4b9=_0x25dbb3[_0xecde('0x3b')];_0x31e0c1<_0x57a4b9;_0x31e0c1++){_0x4090e5={'ProjectId':_0x514a10[_0xecde('0x4b')]['id'],'SessionId':_0x25dbb3[_0x31e0c1]['id'],'StartTime':moment(_0x25dbb3[_0x31e0c1][_0xecde('0x69')])[_0xecde('0x6e')]('YYYY-MM-DD\x20HH:mm:ss')};for(var _0x5b28b6=0x0,_0x3814e2=_0x553c64['length'];_0x5b28b6<_0x3814e2;_0x5b28b6++){if(_0x553c64[_0x5b28b6][_0xecde('0x6f')]==_0x25dbb3[_0x31e0c1]['id']&&_0x16e1f3[_0xecde('0x3c')](_0x553c64[_0x5b28b6]['questionId'])){_0x4090e5[_0x16e1f3[_0x553c64[_0x5b28b6]['questionId']]]=_0x553c64[_0x5b28b6][_0xecde('0x70')];}}for(var _0x2912de in _0x16e1f3){if(!_0x4090e5[_0xecde('0x3c')](_0x16e1f3[_0x2912de])){_0x4090e5[_0x16e1f3[_0x2912de]]=null;}}_0x427d5b[_0xecde('0x71')](_0x4090e5);}return _0x427d5b;}})[_0xecde('0x27')](function(_0x121fcf){if(!_[_0xecde('0x72')](_0x121fcf)){var _0x39663a=toCsv(_0x121fcf);var _0x51a674=Date[_0xecde('0x73')]();fs[_0xecde('0x74')](util[_0xecde('0x6e')](_0xecde('0x75'),_0x514a10['params']['id'],_0x51a674),_0x39663a);_0x3a26fe[_0xecde('0x76')]('Content-disposition',_0xecde('0x77')+util[_0xecde('0x6e')]('Jscripty_Project_%d_Summary_%s.csv',_0x514a10['params']['id'],_0x51a674));_0x3a26fe[_0xecde('0x76')]('Content-type',_0xecde('0x78'));return _0x3a26fe[_0xecde('0x79')](util[_0xecde('0x6e')]('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x514a10['params']['id'],_0x51a674));}else{return _0x3a26fe['sendStatus'](0xcc);}})[_0xecde('0x49')](handleError(_0x3a26fe,null));};