393e866a63a30e5c7ab9ad9d2b7b33e66335c163
[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 _0xbf77=['bluebird','mustache','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','get','Projects','UserProfileResource','error','stack','name','send','index','map','rawAttributes','type','model','query','keys','intersection','fields','attributes','hasOwnProperty','sort','where','filters','pick','filter','VIRTUAL','merge','options','JscriptyProject','includeAll','include','catch','show','length','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','params','createdAt','updatedAt','body','role','userProfileId','getSessions','findOne','JscriptySessionReport','nolimit','order','findAll','getAnswers','ProjectId','JscriptyAnswerReport','rows','fromCharCode','toString','indexOf','startTime','parse','JscriptyQuestionReport','-createdAt','questionId','question','starttime','format','YYYY-MM-DD\x20HH:mm:ss','SessionId','answer','push','now','writeFileSync','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','Content-disposition','attachment;\x20filename=','Content-type','text/csv','download','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment'];(function(_0x1b5ab2,_0x3b968c){var _0x259577=function(_0x39af1d){while(--_0x39af1d){_0x1b5ab2['push'](_0x1b5ab2['shift']());}};_0x259577(++_0x3b968c);}(_0xbf77,0xec));var _0x7bf7=function(_0x273c39,_0x1052e6){_0x273c39=_0x273c39-0x0;var _0x46d6b5=_0xbf77[_0x273c39];return _0x46d6b5;};'use strict';var emlformat=require(_0x7bf7('0x0'));var rimraf=require(_0x7bf7('0x1'));var zipdir=require(_0x7bf7('0x2'));var jsonpatch=require(_0x7bf7('0x3'));var rp=require(_0x7bf7('0x4'));var moment=require(_0x7bf7('0x5'));var BPromise=require(_0x7bf7('0x6'));var Mustache=require(_0x7bf7('0x7'));var util=require('util');var path=require(_0x7bf7('0x8'));var sox=require(_0x7bf7('0x9'));var csv=require(_0x7bf7('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7bf7('0xb'));var _=require(_0x7bf7('0xc'));var squel=require('squel');var crypto=require(_0x7bf7('0xd'));var jsforce=require(_0x7bf7('0xe'));var deskjs=require(_0x7bf7('0xf'));var toCsv=require(_0x7bf7('0xa'));var querystring=require('querystring');var Papa=require(_0x7bf7('0x10'));var Redis=require(_0x7bf7('0x11'));var authService=require(_0x7bf7('0x12'));var qs=require(_0x7bf7('0x13'));var as=require(_0x7bf7('0x14'));var hardwareService=require(_0x7bf7('0x15'));var logger=require(_0x7bf7('0x16'))(_0x7bf7('0x17'));var utils=require(_0x7bf7('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x7bf7('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x358af0,_0x20b1e7){_0x20b1e7=_0x20b1e7||0xcc;return function(_0x4df560){if(_0x4df560){return _0x358af0[_0x7bf7('0x1a')](_0x20b1e7);}return _0x358af0[_0x7bf7('0x1b')](_0x20b1e7)[_0x7bf7('0x1c')]();};}function respondWithResult(_0x25417e,_0x3c204f){_0x3c204f=_0x3c204f||0xc8;return function(_0x16c12d){if(_0x16c12d){return _0x25417e[_0x7bf7('0x1b')](_0x3c204f)[_0x7bf7('0x1d')](_0x16c12d);}};}function respondWithFilteredResult(_0x22e730,_0x4f78f1){return function(_0x1f1ff4){if(_0x1f1ff4){var _0x1dba4d=typeof _0x4f78f1['offset']===_0x7bf7('0x1e')&&typeof _0x4f78f1[_0x7bf7('0x1f')]===_0x7bf7('0x1e');var _0x2bedd7=_0x1f1ff4[_0x7bf7('0x20')];var _0xd72252=_0x1dba4d?0x0:_0x4f78f1['offset'];var _0x41c0d1=_0x1dba4d?_0x1f1ff4[_0x7bf7('0x20')]:_0x4f78f1[_0x7bf7('0x21')]+_0x4f78f1[_0x7bf7('0x1f')];var _0x1bf1c1;if(_0x41c0d1>=_0x2bedd7){_0x41c0d1=_0x2bedd7;_0x1bf1c1=0xc8;}else{_0x1bf1c1=0xce;}_0x22e730[_0x7bf7('0x1b')](_0x1bf1c1);return _0x22e730[_0x7bf7('0x22')](_0x7bf7('0x23'),_0xd72252+'-'+_0x41c0d1+'/'+_0x2bedd7)[_0x7bf7('0x1d')](_0x1f1ff4);}return null;};}function patchUpdates(_0x4b164a){return function(_0x26aafc){try{jsonpatch[_0x7bf7('0x24')](_0x26aafc,_0x4b164a,!![]);}catch(_0x3ba286){return BPromise[_0x7bf7('0x25')](_0x3ba286);}return _0x26aafc[_0x7bf7('0x26')]();};}function saveUpdates(_0x28ee36,_0xf17450){return function(_0x21b02d){if(_0x21b02d){return _0x21b02d[_0x7bf7('0x27')](_0x28ee36)[_0x7bf7('0x28')](function(_0x14584){return _0x14584;});}return null;};}function removeEntity(_0xaca87e,_0x4a09eb){return function(_0x4584c4){if(_0x4584c4){return _0x4584c4[_0x7bf7('0x29')]()[_0x7bf7('0x28')](function(){var _0xf6dd77=_0x4584c4[_0x7bf7('0x2a')]({'plain':!![]});var _0x2d50d7=_0x7bf7('0x2b');return db[_0x7bf7('0x2c')]['destroy']({'where':{'type':_0x2d50d7,'resourceId':_0xf6dd77['id']}})['then'](function(){return _0x4584c4;});})[_0x7bf7('0x28')](function(){_0xaca87e[_0x7bf7('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x303d84,_0x465664){return function(_0x30cd5d){if(!_0x30cd5d){_0x303d84[_0x7bf7('0x1a')](0x194);}return _0x30cd5d;};}function handleError(_0x111531,_0x58e36a){_0x58e36a=_0x58e36a||0x1f4;return function(_0x4be063){logger[_0x7bf7('0x2d')](_0x4be063[_0x7bf7('0x2e')]);if(_0x4be063[_0x7bf7('0x2f')]){delete _0x4be063[_0x7bf7('0x2f')];}_0x111531[_0x7bf7('0x1b')](_0x58e36a)[_0x7bf7('0x30')](_0x4be063);};}exports[_0x7bf7('0x31')]=function(_0xecc3cf,_0xaacc01){var _0x1549ef={},_0xa332ce={},_0x3f91be={'count':0x0,'rows':[]};var _0x337ab8=_[_0x7bf7('0x32')](db['JscriptyProject'][_0x7bf7('0x33')],function(_0x33c113){return{'name':_0x33c113['fieldName'],'type':_0x33c113[_0x7bf7('0x34')]['key']};});_0xa332ce[_0x7bf7('0x35')]=_['map'](_0x337ab8,'name');_0xa332ce[_0x7bf7('0x36')]=_[_0x7bf7('0x37')](_0xecc3cf['query']);_0xa332ce['filters']=_[_0x7bf7('0x38')](_0xa332ce[_0x7bf7('0x35')],_0xa332ce[_0x7bf7('0x36')]);_0x1549ef['attributes']=_[_0x7bf7('0x38')](_0xa332ce['model'],qs[_0x7bf7('0x39')](_0xecc3cf['query'][_0x7bf7('0x39')]));_0x1549ef[_0x7bf7('0x3a')]=_0x1549ef['attributes']['length']?_0x1549ef['attributes']:_0xa332ce[_0x7bf7('0x35')];if(!_0xecc3cf[_0x7bf7('0x36')][_0x7bf7('0x3b')]('nolimit')){_0x1549ef[_0x7bf7('0x1f')]=qs[_0x7bf7('0x1f')](_0xecc3cf[_0x7bf7('0x36')][_0x7bf7('0x1f')]);_0x1549ef[_0x7bf7('0x21')]=qs[_0x7bf7('0x21')](_0xecc3cf[_0x7bf7('0x36')]['offset']);}_0x1549ef['order']=qs[_0x7bf7('0x3c')](_0xecc3cf[_0x7bf7('0x36')][_0x7bf7('0x3c')]);_0x1549ef[_0x7bf7('0x3d')]=qs[_0x7bf7('0x3e')](_[_0x7bf7('0x3f')](_0xecc3cf[_0x7bf7('0x36')],_0xa332ce[_0x7bf7('0x3e')]),_0x337ab8);if(_0xecc3cf['query'][_0x7bf7('0x40')]){_0x1549ef[_0x7bf7('0x3d')]=_['merge'](_0x1549ef['where'],{'$or':_[_0x7bf7('0x32')](_0x337ab8,function(_0x4dca87){if(_0x4dca87[_0x7bf7('0x34')]!==_0x7bf7('0x41')){var _0x3f9587={};_0x3f9587[_0x4dca87[_0x7bf7('0x2f')]]={'$like':'%'+_0xecc3cf[_0x7bf7('0x36')][_0x7bf7('0x40')]+'%'};return _0x3f9587;}})});}_0x1549ef=_[_0x7bf7('0x42')]({},_0x1549ef,_0xecc3cf[_0x7bf7('0x43')]);var _0x2ca4f5={'where':_0x1549ef['where']};return db[_0x7bf7('0x44')]['count'](_0x2ca4f5)[_0x7bf7('0x28')](function(_0x53add7){_0x3f91be[_0x7bf7('0x20')]=_0x53add7;if(_0xecc3cf[_0x7bf7('0x36')][_0x7bf7('0x45')]){_0x1549ef[_0x7bf7('0x46')]=[{'all':!![]}];}return db[_0x7bf7('0x44')]['findAll'](_0x1549ef);})[_0x7bf7('0x28')](function(_0x46dd05){_0x3f91be['rows']=_0x46dd05;return _0x3f91be;})[_0x7bf7('0x28')](respondWithFilteredResult(_0xaacc01,_0x1549ef))[_0x7bf7('0x47')](handleError(_0xaacc01,null));};exports[_0x7bf7('0x48')]=function(_0x185175,_0x3470df){var _0x57ab9c={'raw':![],'where':{'id':_0x185175['params']['id']}},_0x494c6a={};_0x494c6a[_0x7bf7('0x35')]=_[_0x7bf7('0x37')](db[_0x7bf7('0x44')]['rawAttributes']);_0x494c6a[_0x7bf7('0x36')]=_[_0x7bf7('0x37')](_0x185175['query']);_0x494c6a[_0x7bf7('0x3e')]=_[_0x7bf7('0x38')](_0x494c6a[_0x7bf7('0x35')],_0x494c6a[_0x7bf7('0x36')]);_0x57ab9c['attributes']=_[_0x7bf7('0x38')](_0x494c6a[_0x7bf7('0x35')],qs[_0x7bf7('0x39')](_0x185175[_0x7bf7('0x36')][_0x7bf7('0x39')]));_0x57ab9c[_0x7bf7('0x3a')]=_0x57ab9c['attributes'][_0x7bf7('0x49')]?_0x57ab9c[_0x7bf7('0x3a')]:_0x494c6a['model'];if(_0x185175[_0x7bf7('0x36')][_0x7bf7('0x45')]){_0x57ab9c[_0x7bf7('0x46')]=[{'all':!![]}];}_0x57ab9c=_['merge']({},_0x57ab9c,_0x185175[_0x7bf7('0x43')]);return db['JscriptyProject'][_0x7bf7('0x4a')](_0x57ab9c)[_0x7bf7('0x28')](handleEntityNotFound(_0x3470df,null))[_0x7bf7('0x28')](respondWithResult(_0x3470df,null))[_0x7bf7('0x47')](handleError(_0x3470df,null));};exports[_0x7bf7('0x4b')]=function(_0x5edf0c,_0x4a7948){return db[_0x7bf7('0x44')][_0x7bf7('0x4b')](_0x5edf0c['body'],{})[_0x7bf7('0x28')](function(_0x4dae5c){var _0x47d2f1=_0x5edf0c[_0x7bf7('0x4c')][_0x7bf7('0x2a')]({'plain':!![]});if(!_0x47d2f1)throw new Error(_0x7bf7('0x4d'));if(_0x47d2f1['role']===_0x7bf7('0x4c')){var _0x569305=_0x4dae5c[_0x7bf7('0x2a')]({'plain':!![]});var _0x4a4fa0='Projects';return db[_0x7bf7('0x4e')][_0x7bf7('0x4a')]({'where':{'name':_0x4a4fa0,'userProfileId':_0x47d2f1['userProfileId']},'raw':!![]})[_0x7bf7('0x28')](function(_0x535573){if(_0x535573&&_0x535573['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x569305[_0x7bf7('0x2f')],'resourceId':_0x569305['id'],'type':_0x535573[_0x7bf7('0x2f')],'sectionId':_0x535573['id']},{})['then'](function(){return _0x4dae5c;});}else{return _0x4dae5c;}})['catch'](function(_0x45b156){logger[_0x7bf7('0x2d')](_0x7bf7('0x4f'),_0x45b156);throw _0x45b156;});}return _0x4dae5c;})[_0x7bf7('0x28')](respondWithResult(_0x4a7948,0xc9))[_0x7bf7('0x47')](handleError(_0x4a7948,null));};exports[_0x7bf7('0x50')]=function(_0x3f19a9,_0x309ce8){var _0x31371c={'where':{'id':_0x3f19a9[_0x7bf7('0x51')]['id']}},_0xd4d3fd={};_0xd4d3fd[_0x7bf7('0x35')]=_[_0x7bf7('0x37')](db[_0x7bf7('0x44')][_0x7bf7('0x33')]);_0x31371c['attributes']=_['intersection'](_0xd4d3fd['model'],qs[_0x7bf7('0x39')](_0x3f19a9[_0x7bf7('0x36')][_0x7bf7('0x39')]));_0x31371c[_0x7bf7('0x3a')]=_0x31371c[_0x7bf7('0x3a')][_0x7bf7('0x49')]?_0x31371c[_0x7bf7('0x3a')]:_0xd4d3fd[_0x7bf7('0x35')];if(_0x3f19a9['query'][_0x7bf7('0x45')]){_0x31371c[_0x7bf7('0x46')]=[{'all':!![]}];}_0x31371c=_[_0x7bf7('0x42')]({},_0x31371c,_0x3f19a9['options']);return db['JscriptyProject'][_0x7bf7('0x4a')](_0x31371c)[_0x7bf7('0x28')](handleEntityNotFound(_0x309ce8,null))['then'](function(_0x29f3ff){if(_0x29f3ff){var _0x230d83=_0x29f3ff[_0x7bf7('0x2a')]({'plain':!![]});_0x230d83=qs['omit'](_0x230d83,['id',_0x7bf7('0x52'),_0x7bf7('0x53')]);_0x3f19a9[_0x7bf7('0x54')]=_['omit'](_0x3f19a9[_0x7bf7('0x54')],['id',_0x7bf7('0x52'),'updatedAt']);return db[_0x7bf7('0x44')][_0x7bf7('0x4b')](_[_0x7bf7('0x42')](_0x230d83,_0x3f19a9[_0x7bf7('0x54')]),{'include':_0x3f19a9[_0x7bf7('0x36')][_0x7bf7('0x45')]?[{'all':!![]}]:undefined})[_0x7bf7('0x28')](function(_0x1e39d1){var _0x28e43f=_0x3f19a9[_0x7bf7('0x4c')][_0x7bf7('0x2a')]({'plain':!![]});if(!_0x28e43f)throw new Error(_0x7bf7('0x4d'));if(_0x28e43f[_0x7bf7('0x55')]===_0x7bf7('0x4c')){var _0x5e59e2=_0x1e39d1[_0x7bf7('0x2a')]({'plain':!![]});var _0x50e7c0=_0x7bf7('0x2b');return db[_0x7bf7('0x4e')][_0x7bf7('0x4a')]({'where':{'name':_0x50e7c0,'userProfileId':_0x28e43f[_0x7bf7('0x56')]},'raw':!![]})['then'](function(_0x20facb){if(_0x20facb&&_0x20facb['autoAssociation']===0x0){return db[_0x7bf7('0x2c')][_0x7bf7('0x4b')]({'name':_0x5e59e2['name'],'resourceId':_0x5e59e2['id'],'type':_0x20facb[_0x7bf7('0x2f')],'sectionId':_0x20facb['id']},{})[_0x7bf7('0x28')](function(){return _0x1e39d1;});}else{return _0x1e39d1;}})[_0x7bf7('0x47')](function(_0x40847a){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x40847a);throw _0x40847a;});}return _0x1e39d1;});}})[_0x7bf7('0x28')](respondWithResult(_0x309ce8,0xc9))[_0x7bf7('0x47')](handleError(_0x309ce8,null));};exports[_0x7bf7('0x27')]=function(_0x43497a,_0x3bd9b8){if(_0x43497a[_0x7bf7('0x54')]['id']){delete _0x43497a[_0x7bf7('0x54')]['id'];}return db[_0x7bf7('0x44')][_0x7bf7('0x4a')]({'where':{'id':_0x43497a[_0x7bf7('0x51')]['id']}})[_0x7bf7('0x28')](handleEntityNotFound(_0x3bd9b8,null))[_0x7bf7('0x28')](saveUpdates(_0x43497a[_0x7bf7('0x54')],null))[_0x7bf7('0x28')](respondWithResult(_0x3bd9b8,null))['catch'](handleError(_0x3bd9b8,null));};exports['destroy']=function(_0x5da573,_0x3edb7c){return db[_0x7bf7('0x44')][_0x7bf7('0x4a')]({'where':{'id':_0x5da573[_0x7bf7('0x51')]['id']}})[_0x7bf7('0x28')](handleEntityNotFound(_0x3edb7c,null))[_0x7bf7('0x28')](removeEntity(_0x3edb7c,null))['catch'](handleError(_0x3edb7c,null));};exports[_0x7bf7('0x57')]=function(_0x27b630,_0x51b10f,_0x3b93a0){var _0x3783e6={'raw':!![],'where':{}};var _0x2e874f={};var _0x3f1001={'count':0x0,'rows':[]};return db[_0x7bf7('0x44')][_0x7bf7('0x58')]({'where':{'id':_0x27b630[_0x7bf7('0x51')]['id']}})[_0x7bf7('0x28')](handleEntityNotFound(_0x51b10f,null))[_0x7bf7('0x28')](function(_0x4bf94a){if(_0x4bf94a){_0x2e874f['model']=_[_0x7bf7('0x37')](db[_0x7bf7('0x59')][_0x7bf7('0x33')]);_0x2e874f[_0x7bf7('0x36')]=_[_0x7bf7('0x37')](_0x27b630[_0x7bf7('0x36')]);_0x2e874f[_0x7bf7('0x3e')]=_[_0x7bf7('0x38')](_0x2e874f[_0x7bf7('0x35')],_0x2e874f[_0x7bf7('0x36')]);_0x3783e6[_0x7bf7('0x3a')]=_[_0x7bf7('0x38')](_0x2e874f['model'],qs[_0x7bf7('0x39')](_0x27b630[_0x7bf7('0x36')][_0x7bf7('0x39')]));_0x3783e6[_0x7bf7('0x3a')]=_0x3783e6[_0x7bf7('0x3a')][_0x7bf7('0x49')]?_0x3783e6[_0x7bf7('0x3a')]:_0x2e874f[_0x7bf7('0x35')];if(!_0x27b630[_0x7bf7('0x36')]['hasOwnProperty'](_0x7bf7('0x5a'))){_0x3783e6['limit']=qs[_0x7bf7('0x1f')](_0x27b630[_0x7bf7('0x36')][_0x7bf7('0x1f')]);_0x3783e6[_0x7bf7('0x21')]=qs[_0x7bf7('0x21')](_0x27b630[_0x7bf7('0x36')][_0x7bf7('0x21')]);}_0x3783e6[_0x7bf7('0x5b')]=qs[_0x7bf7('0x3c')](_0x27b630[_0x7bf7('0x36')][_0x7bf7('0x3c')]);_0x3783e6['where']=qs['filters'](_[_0x7bf7('0x3f')](_0x27b630['query'],_0x2e874f[_0x7bf7('0x3e')]));_0x3783e6[_0x7bf7('0x3d')]['ProjectId']=_0x4bf94a['id'];if(_0x27b630[_0x7bf7('0x36')]['filter']){_0x3783e6[_0x7bf7('0x3d')]=_[_0x7bf7('0x42')](_0x3783e6[_0x7bf7('0x3d')],{'$or':_[_0x7bf7('0x32')](_0x3783e6['attributes'],function(_0x383b8b){var _0x392c25={};_0x392c25[_0x383b8b]={'$like':'%'+_0x27b630[_0x7bf7('0x36')][_0x7bf7('0x40')]+'%'};return _0x392c25;})});}_0x3783e6=_[_0x7bf7('0x42')]({},_0x3783e6,_0x27b630['options']);return db[_0x7bf7('0x59')][_0x7bf7('0x20')]({'where':_0x3783e6['where']})[_0x7bf7('0x28')](function(_0xcdd3b8){_0x3f1001[_0x7bf7('0x20')]=_0xcdd3b8;if(_0x27b630[_0x7bf7('0x36')][_0x7bf7('0x45')]){_0x3783e6[_0x7bf7('0x46')]=[{'all':!![]}];}return db[_0x7bf7('0x59')][_0x7bf7('0x5c')](_0x3783e6);})[_0x7bf7('0x28')](function(_0x2a24fe){_0x3f1001['rows']=_0x2a24fe;return _0x3f1001;});}})[_0x7bf7('0x28')](respondWithFilteredResult(_0x51b10f,_0x3783e6))[_0x7bf7('0x47')](handleError(_0x51b10f,null));};exports[_0x7bf7('0x5d')]=function(_0x2b8089,_0x218c52,_0x16458e){var _0x31575a={'raw':!![],'where':{}};var _0x3fd30f={};var _0x3d7429={'count':0x0,'rows':[]};return db[_0x7bf7('0x44')][_0x7bf7('0x58')]({'where':{'id':_0x2b8089[_0x7bf7('0x51')]['id']}})[_0x7bf7('0x28')](handleEntityNotFound(_0x218c52,null))['then'](function(_0x21092e){if(_0x21092e){_0x3fd30f[_0x7bf7('0x35')]=_[_0x7bf7('0x37')](db['JscriptyAnswerReport'][_0x7bf7('0x33')]);_0x3fd30f[_0x7bf7('0x36')]=_[_0x7bf7('0x37')](_0x2b8089[_0x7bf7('0x36')]);_0x3fd30f[_0x7bf7('0x3e')]=_[_0x7bf7('0x38')](_0x3fd30f[_0x7bf7('0x35')],_0x3fd30f[_0x7bf7('0x36')]);_0x31575a[_0x7bf7('0x3a')]=_[_0x7bf7('0x38')](_0x3fd30f[_0x7bf7('0x35')],qs[_0x7bf7('0x39')](_0x2b8089[_0x7bf7('0x36')][_0x7bf7('0x39')]));_0x31575a['attributes']=_0x31575a['attributes'][_0x7bf7('0x49')]?_0x31575a[_0x7bf7('0x3a')]:_0x3fd30f[_0x7bf7('0x35')];if(!_0x2b8089[_0x7bf7('0x36')][_0x7bf7('0x3b')](_0x7bf7('0x5a'))){_0x31575a[_0x7bf7('0x1f')]=qs[_0x7bf7('0x1f')](_0x2b8089[_0x7bf7('0x36')][_0x7bf7('0x1f')]);_0x31575a[_0x7bf7('0x21')]=qs['offset'](_0x2b8089[_0x7bf7('0x36')]['offset']);}_0x31575a[_0x7bf7('0x5b')]=qs['sort'](_0x2b8089['query'][_0x7bf7('0x3c')]);_0x31575a['where']=qs['filters'](_[_0x7bf7('0x3f')](_0x2b8089['query'],_0x3fd30f['filters']));_0x31575a['where'][_0x7bf7('0x5e')]=_0x21092e['id'];if(_0x2b8089[_0x7bf7('0x36')][_0x7bf7('0x40')]){_0x31575a[_0x7bf7('0x3d')]=_['merge'](_0x31575a[_0x7bf7('0x3d')],{'$or':_['map'](_0x31575a[_0x7bf7('0x3a')],function(_0xc339e8){var _0xd39363={};_0xd39363[_0xc339e8]={'$like':'%'+_0x2b8089['query'][_0x7bf7('0x40')]+'%'};return _0xd39363;})});}_0x31575a=_[_0x7bf7('0x42')]({},_0x31575a,_0x2b8089['options']);return db['JscriptyAnswerReport'][_0x7bf7('0x20')]({'where':_0x31575a['where']})['then'](function(_0x30a3b4){_0x3d7429[_0x7bf7('0x20')]=_0x30a3b4;if(_0x2b8089['query']['includeAll']){_0x31575a[_0x7bf7('0x46')]=[{'all':!![]}];}return db[_0x7bf7('0x5f')][_0x7bf7('0x5c')](_0x31575a);})['then'](function(_0x4a342f){_0x3d7429[_0x7bf7('0x60')]=_0x4a342f;return _0x3d7429;});}})[_0x7bf7('0x28')](respondWithFilteredResult(_0x218c52,_0x31575a))[_0x7bf7('0x47')](handleError(_0x218c52,null));};function char(_0x43855a){return'number'===typeof _0x43855a?String[_0x7bf7('0x61')]['apply'](null,arguments):_0x43855a;}function needsEncapsulation(_0x41e827){return!!_0x41e827&&(_0x41e827[_0x7bf7('0x62')]()['indexOf'](char(0xd))>=0x0||_0x41e827['toString']()[_0x7bf7('0x63')](char(0xa))>=0x0||_0x41e827[_0x7bf7('0x62')]()[_0x7bf7('0x63')](char(0x2c))>=0x0||_0x41e827[_0x7bf7('0x62')]()['indexOf'](char(0x22))>=0x0);}function encapsulate(_0x5262e9){var _0x32a845=char(0x22),_0x23b164='\x5c'+char(0x22),_0x2844a3=_0x5262e9[_0x7bf7('0x62')]()['replace'](new RegExp(_0x32a845,'g'),_0x23b164);return _0x32a845+_0x2844a3+_0x32a845;}exports['getSummary']=function(_0x50a6a7,_0x26d339,_0x5485f0){var _0x348c1f,_0x27923b;var _0x20b6a9={'where':{'ProjectId':_0x50a6a7[_0x7bf7('0x51')]['id']}};if(_0x50a6a7[_0x7bf7('0x36')][_0x7bf7('0x64')]){_0x20b6a9['where']['starttime']=JSON[_0x7bf7('0x65')](_0x50a6a7[_0x7bf7('0x36')][_0x7bf7('0x64')]);}return db[_0x7bf7('0x59')]['findAll'](_0x20b6a9)[_0x7bf7('0x28')](handleEntityNotFound(_0x26d339,null))['then'](function(_0x51fb81){if(_0x51fb81){_0x348c1f=_0x51fb81;return db[_0x7bf7('0x66')][_0x7bf7('0x5c')]({'where':{'SessionId':{'$in':_['map'](_0x348c1f,'id')},'ProjectId':_0x50a6a7[_0x7bf7('0x51')]['id']},'order':_0x7bf7('0x67')});}})['then'](handleEntityNotFound(_0x26d339,null))[_0x7bf7('0x28')](function(_0x5264e3){if(_0x5264e3){_0x27923b=_0x5264e3;var _0x54f507={};for(var _0x59f25e=0x0,_0x54a3f0=_0x27923b[_0x7bf7('0x49')];_0x59f25e<_0x54a3f0;_0x59f25e++){if(!_0x54f507[_0x7bf7('0x3b')](_0x27923b[_0x59f25e][_0x7bf7('0x68')])){_0x54f507[_0x27923b[_0x59f25e][_0x7bf7('0x68')]]=needsEncapsulation(_0x27923b[_0x59f25e][_0x7bf7('0x69')])?encapsulate(_0x27923b[_0x59f25e][_0x7bf7('0x69')]):_0x27923b[_0x59f25e][_0x7bf7('0x69')];}}var _0x2cba56=[],_0xc7bda0={};for(var _0x32f119=0x0,_0x514a39=_0x348c1f[_0x7bf7('0x49')];_0x32f119<_0x514a39;_0x32f119++){_0xc7bda0={'ProjectId':_0x50a6a7[_0x7bf7('0x51')]['id'],'SessionId':_0x348c1f[_0x32f119]['id'],'StartTime':moment(_0x348c1f[_0x32f119][_0x7bf7('0x6a')])[_0x7bf7('0x6b')](_0x7bf7('0x6c'))};for(var _0x378dfc=0x0,_0x41de5a=_0x27923b[_0x7bf7('0x49')];_0x378dfc<_0x41de5a;_0x378dfc++){if(_0x27923b[_0x378dfc][_0x7bf7('0x6d')]==_0x348c1f[_0x32f119]['id']&&_0x54f507[_0x7bf7('0x3b')](_0x27923b[_0x378dfc]['questionId'])){_0xc7bda0[_0x54f507[_0x27923b[_0x378dfc][_0x7bf7('0x68')]]]=_0x27923b[_0x378dfc][_0x7bf7('0x6e')];}}for(var _0x14d245 in _0x54f507){if(!_0xc7bda0[_0x7bf7('0x3b')](_0x54f507[_0x14d245])){_0xc7bda0[_0x54f507[_0x14d245]]=null;}}_0x2cba56[_0x7bf7('0x6f')](_0xc7bda0);}return _0x2cba56;}})['then'](function(_0x4ee313){if(!_['isEmpty'](_0x4ee313)){var _0x341cc2=toCsv(_0x4ee313);var _0x564836=Date[_0x7bf7('0x70')]();fs[_0x7bf7('0x71')](util[_0x7bf7('0x6b')](_0x7bf7('0x72'),_0x50a6a7[_0x7bf7('0x51')]['id'],_0x564836),_0x341cc2);_0x26d339[_0x7bf7('0x73')](_0x7bf7('0x74'),_0x7bf7('0x75')+util['format']('Jscripty_Project_%d_Summary_%s.csv',_0x50a6a7['params']['id'],_0x564836));_0x26d339['setHeader'](_0x7bf7('0x76'),_0x7bf7('0x77'));return _0x26d339[_0x7bf7('0x78')](util[_0x7bf7('0x6b')](_0x7bf7('0x72'),_0x50a6a7[_0x7bf7('0x51')]['id'],_0x564836));}else{return _0x26d339[_0x7bf7('0x1a')](0xcc);}})[_0x7bf7('0x47')](handleError(_0x26d339,null));};