b4b604306647c73ff84d49acfda6bedd3f14b79a
[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 _0xf5c4=['stack','name','send','index','map','JscriptyProject','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filters','merge','VIRTUAL','filter','options','include','rows','catch','params','rawAttributes','includeAll','find','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','updatedAt','create','role','getSessions','findOne','JscriptySessionReport','order','pick','ProjectId','findAll','JscriptyAnswerReport','number','fromCharCode','toString','indexOf','getSummary','startTime','starttime','parse','JscriptyQuestionReport','-createdAt','questionId','question','YYYY-MM-DD\x20HH:mm:ss','SessionId','answer','push','now','format','/tmp/Jscripty_Project_%d_Summary_%s.csv','Content-disposition','attachment;\x20filename=','setHeader','Content-type','text/csv','download','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','limit','count','set','json','apply','reject','update','then','destroy','get','Projects','UserProfileResource','end','error'];(function(_0x349ffc,_0x5c270d){var _0x17baa8=function(_0x146f93){while(--_0x146f93){_0x349ffc['push'](_0x349ffc['shift']());}};_0x17baa8(++_0x5c270d);}(_0xf5c4,0x1ae));var _0x4f5c=function(_0x405d4a,_0x2b774e){_0x405d4a=_0x405d4a-0x0;var _0x33b57d=_0xf5c4[_0x405d4a];return _0x33b57d;};'use strict';var emlformat=require(_0x4f5c('0x0'));var rimraf=require(_0x4f5c('0x1'));var zipdir=require(_0x4f5c('0x2'));var jsonpatch=require(_0x4f5c('0x3'));var rp=require(_0x4f5c('0x4'));var moment=require(_0x4f5c('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x4f5c('0x6'));var util=require('util');var path=require('path');var sox=require(_0x4f5c('0x7'));var csv=require(_0x4f5c('0x8'));var ejs=require(_0x4f5c('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x4f5c('0xa'));var squel=require(_0x4f5c('0xb'));var crypto=require('crypto');var jsforce=require(_0x4f5c('0xc'));var deskjs=require(_0x4f5c('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x4f5c('0xe'));var Redis=require(_0x4f5c('0xf'));var authService=require(_0x4f5c('0x10'));var qs=require(_0x4f5c('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4f5c('0x12'));var logger=require('../../config/logger')(_0x4f5c('0x13'));var utils=require(_0x4f5c('0x14'));var config=require(_0x4f5c('0x15'));var licenseUtil=require(_0x4f5c('0x16'));var db=require(_0x4f5c('0x17'))['db'];function respondWithStatusCode(_0x4ec410,_0x46e319){_0x46e319=_0x46e319||0xcc;return function(_0x554382){if(_0x554382){return _0x4ec410[_0x4f5c('0x18')](_0x46e319);}return _0x4ec410[_0x4f5c('0x19')](_0x46e319)['end']();};}function respondWithResult(_0x4a37d8,_0x1a160a){_0x1a160a=_0x1a160a||0xc8;return function(_0xfe0e5){if(_0xfe0e5){return _0x4a37d8[_0x4f5c('0x19')](_0x1a160a)['json'](_0xfe0e5);}};}function respondWithFilteredResult(_0x2ae5f6,_0x796709){return function(_0x4bb4b3){if(_0x4bb4b3){var _0x3ea3dd=typeof _0x796709[_0x4f5c('0x1a')]===_0x4f5c('0x1b')&&typeof _0x796709[_0x4f5c('0x1c')]===_0x4f5c('0x1b');var _0x55ccb6=_0x4bb4b3[_0x4f5c('0x1d')];var _0x2b1fad=_0x3ea3dd?0x0:_0x796709[_0x4f5c('0x1a')];var _0x47739d=_0x3ea3dd?_0x4bb4b3['count']:_0x796709[_0x4f5c('0x1a')]+_0x796709[_0x4f5c('0x1c')];var _0x5db75b;if(_0x47739d>=_0x55ccb6){_0x47739d=_0x55ccb6;_0x5db75b=0xc8;}else{_0x5db75b=0xce;}_0x2ae5f6[_0x4f5c('0x19')](_0x5db75b);return _0x2ae5f6[_0x4f5c('0x1e')]('Content-Range',_0x2b1fad+'-'+_0x47739d+'/'+_0x55ccb6)[_0x4f5c('0x1f')](_0x4bb4b3);}return null;};}function patchUpdates(_0x300410){return function(_0x25fca0){try{jsonpatch[_0x4f5c('0x20')](_0x25fca0,_0x300410,!![]);}catch(_0x1f942f){return BPromise[_0x4f5c('0x21')](_0x1f942f);}return _0x25fca0['save']();};}function saveUpdates(_0x56e3bb,_0x3843de){return function(_0xa7b7df){if(_0xa7b7df){return _0xa7b7df[_0x4f5c('0x22')](_0x56e3bb)[_0x4f5c('0x23')](function(_0xe6871){return _0xe6871;});}return null;};}function removeEntity(_0x1af746,_0x1691e5){return function(_0x1b0829){if(_0x1b0829){return _0x1b0829[_0x4f5c('0x24')]()['then'](function(){var _0x36bbf7=_0x1b0829[_0x4f5c('0x25')]({'plain':!![]});var _0x555b88=_0x4f5c('0x26');return db[_0x4f5c('0x27')][_0x4f5c('0x24')]({'where':{'type':_0x555b88,'resourceId':_0x36bbf7['id']}})[_0x4f5c('0x23')](function(){return _0x1b0829;});})[_0x4f5c('0x23')](function(){_0x1af746[_0x4f5c('0x19')](0xcc)[_0x4f5c('0x28')]();});}};}function handleEntityNotFound(_0xf4910b,_0x2ec563){return function(_0x356e45){if(!_0x356e45){_0xf4910b[_0x4f5c('0x18')](0x194);}return _0x356e45;};}function handleError(_0x5dd2ee,_0xf3012d){_0xf3012d=_0xf3012d||0x1f4;return function(_0x208695){logger[_0x4f5c('0x29')](_0x208695[_0x4f5c('0x2a')]);if(_0x208695[_0x4f5c('0x2b')]){delete _0x208695[_0x4f5c('0x2b')];}_0x5dd2ee['status'](_0xf3012d)[_0x4f5c('0x2c')](_0x208695);};}exports[_0x4f5c('0x2d')]=function(_0x1f9e73,_0x578393){var _0x8a0412={},_0x5ea0b6={},_0x4b8a98={'count':0x0,'rows':[]};var _0x1d8f8b=_[_0x4f5c('0x2e')](db[_0x4f5c('0x2f')]['rawAttributes'],function(_0x4224b8){return{'name':_0x4224b8['fieldName'],'type':_0x4224b8[_0x4f5c('0x30')][_0x4f5c('0x31')]};});_0x5ea0b6[_0x4f5c('0x32')]=_[_0x4f5c('0x2e')](_0x1d8f8b,_0x4f5c('0x2b'));_0x5ea0b6[_0x4f5c('0x33')]=_[_0x4f5c('0x34')](_0x1f9e73[_0x4f5c('0x33')]);_0x5ea0b6['filters']=_[_0x4f5c('0x35')](_0x5ea0b6[_0x4f5c('0x32')],_0x5ea0b6[_0x4f5c('0x33')]);_0x8a0412[_0x4f5c('0x36')]=_['intersection'](_0x5ea0b6[_0x4f5c('0x32')],qs[_0x4f5c('0x37')](_0x1f9e73[_0x4f5c('0x33')][_0x4f5c('0x37')]));_0x8a0412[_0x4f5c('0x36')]=_0x8a0412[_0x4f5c('0x36')][_0x4f5c('0x38')]?_0x8a0412[_0x4f5c('0x36')]:_0x5ea0b6[_0x4f5c('0x32')];if(!_0x1f9e73['query'][_0x4f5c('0x39')](_0x4f5c('0x3a'))){_0x8a0412[_0x4f5c('0x1c')]=qs[_0x4f5c('0x1c')](_0x1f9e73['query'][_0x4f5c('0x1c')]);_0x8a0412[_0x4f5c('0x1a')]=qs[_0x4f5c('0x1a')](_0x1f9e73[_0x4f5c('0x33')]['offset']);}_0x8a0412['order']=qs[_0x4f5c('0x3b')](_0x1f9e73[_0x4f5c('0x33')][_0x4f5c('0x3b')]);_0x8a0412[_0x4f5c('0x3c')]=qs[_0x4f5c('0x3d')](_['pick'](_0x1f9e73['query'],_0x5ea0b6[_0x4f5c('0x3d')]),_0x1d8f8b);if(_0x1f9e73[_0x4f5c('0x33')]['filter']){_0x8a0412[_0x4f5c('0x3c')]=_[_0x4f5c('0x3e')](_0x8a0412[_0x4f5c('0x3c')],{'$or':_[_0x4f5c('0x2e')](_0x1d8f8b,function(_0xdca9c3){if(_0xdca9c3[_0x4f5c('0x30')]!==_0x4f5c('0x3f')){var _0x46094d={};_0x46094d[_0xdca9c3['name']]={'$like':'%'+_0x1f9e73[_0x4f5c('0x33')][_0x4f5c('0x40')]+'%'};return _0x46094d;}})});}_0x8a0412=_[_0x4f5c('0x3e')]({},_0x8a0412,_0x1f9e73[_0x4f5c('0x41')]);var _0x21eb2a={'where':_0x8a0412[_0x4f5c('0x3c')]};return db[_0x4f5c('0x2f')]['count'](_0x21eb2a)[_0x4f5c('0x23')](function(_0x545262){_0x4b8a98[_0x4f5c('0x1d')]=_0x545262;if(_0x1f9e73[_0x4f5c('0x33')]['includeAll']){_0x8a0412[_0x4f5c('0x42')]=[{'all':!![]}];}return db['JscriptyProject']['findAll'](_0x8a0412);})[_0x4f5c('0x23')](function(_0x1dc368){_0x4b8a98[_0x4f5c('0x43')]=_0x1dc368;return _0x4b8a98;})[_0x4f5c('0x23')](respondWithFilteredResult(_0x578393,_0x8a0412))[_0x4f5c('0x44')](handleError(_0x578393,null));};exports['show']=function(_0x372143,_0x45b1f0){var _0x32d09c={'raw':![],'where':{'id':_0x372143[_0x4f5c('0x45')]['id']}},_0x33e734={};_0x33e734[_0x4f5c('0x32')]=_[_0x4f5c('0x34')](db[_0x4f5c('0x2f')][_0x4f5c('0x46')]);_0x33e734[_0x4f5c('0x33')]=_[_0x4f5c('0x34')](_0x372143[_0x4f5c('0x33')]);_0x33e734['filters']=_[_0x4f5c('0x35')](_0x33e734[_0x4f5c('0x32')],_0x33e734['query']);_0x32d09c[_0x4f5c('0x36')]=_[_0x4f5c('0x35')](_0x33e734['model'],qs[_0x4f5c('0x37')](_0x372143[_0x4f5c('0x33')][_0x4f5c('0x37')]));_0x32d09c[_0x4f5c('0x36')]=_0x32d09c[_0x4f5c('0x36')]['length']?_0x32d09c[_0x4f5c('0x36')]:_0x33e734[_0x4f5c('0x32')];if(_0x372143[_0x4f5c('0x33')][_0x4f5c('0x47')]){_0x32d09c['include']=[{'all':!![]}];}_0x32d09c=_[_0x4f5c('0x3e')]({},_0x32d09c,_0x372143[_0x4f5c('0x41')]);return db[_0x4f5c('0x2f')][_0x4f5c('0x48')](_0x32d09c)[_0x4f5c('0x23')](handleEntityNotFound(_0x45b1f0,null))[_0x4f5c('0x23')](respondWithResult(_0x45b1f0,null))[_0x4f5c('0x44')](handleError(_0x45b1f0,null));};exports['create']=function(_0x493159,_0x30793e){return db[_0x4f5c('0x2f')]['create'](_0x493159[_0x4f5c('0x49')],{})['then'](function(_0x17a30a){var _0x3241c5=_0x493159['user'][_0x4f5c('0x25')]({'plain':!![]});if(!_0x3241c5)throw new Error(_0x4f5c('0x4a'));if(_0x3241c5['role']===_0x4f5c('0x4b')){var _0x128ac0=_0x17a30a[_0x4f5c('0x25')]({'plain':!![]});var _0x279904=_0x4f5c('0x26');return db[_0x4f5c('0x4c')][_0x4f5c('0x48')]({'where':{'name':_0x279904,'userProfileId':_0x3241c5[_0x4f5c('0x4d')]},'raw':!![]})[_0x4f5c('0x23')](function(_0xbc03dd){if(_0xbc03dd&&_0xbc03dd[_0x4f5c('0x4e')]===0x0){return db['UserProfileResource']['create']({'name':_0x128ac0[_0x4f5c('0x2b')],'resourceId':_0x128ac0['id'],'type':_0xbc03dd[_0x4f5c('0x2b')],'sectionId':_0xbc03dd['id']},{})[_0x4f5c('0x23')](function(){return _0x17a30a;});}else{return _0x17a30a;}})['catch'](function(_0x34eba5){logger[_0x4f5c('0x29')](_0x4f5c('0x4f'),_0x34eba5);throw _0x34eba5;});}return _0x17a30a;})['then'](respondWithResult(_0x30793e,0xc9))[_0x4f5c('0x44')](handleError(_0x30793e,null));};exports[_0x4f5c('0x50')]=function(_0x34b57e,_0x54e8e8){var _0x1df03b={'where':{'id':_0x34b57e[_0x4f5c('0x45')]['id']}},_0xb5adf={};_0xb5adf[_0x4f5c('0x32')]=_['keys'](db[_0x4f5c('0x2f')][_0x4f5c('0x46')]);_0x1df03b[_0x4f5c('0x36')]=_['intersection'](_0xb5adf[_0x4f5c('0x32')],qs[_0x4f5c('0x37')](_0x34b57e[_0x4f5c('0x33')][_0x4f5c('0x37')]));_0x1df03b[_0x4f5c('0x36')]=_0x1df03b[_0x4f5c('0x36')]['length']?_0x1df03b[_0x4f5c('0x36')]:_0xb5adf[_0x4f5c('0x32')];if(_0x34b57e[_0x4f5c('0x33')]['includeAll']){_0x1df03b[_0x4f5c('0x42')]=[{'all':!![]}];}_0x1df03b=_['merge']({},_0x1df03b,_0x34b57e[_0x4f5c('0x41')]);return db[_0x4f5c('0x2f')][_0x4f5c('0x48')](_0x1df03b)[_0x4f5c('0x23')](handleEntityNotFound(_0x54e8e8,null))['then'](function(_0x35cd37){if(_0x35cd37){var _0xe3f3b2=_0x35cd37[_0x4f5c('0x25')]({'plain':!![]});_0xe3f3b2=qs[_0x4f5c('0x51')](_0xe3f3b2,['id','createdAt',_0x4f5c('0x52')]);_0x34b57e[_0x4f5c('0x49')]=_[_0x4f5c('0x51')](_0x34b57e['body'],['id','createdAt',_0x4f5c('0x52')]);return db['JscriptyProject'][_0x4f5c('0x53')](_[_0x4f5c('0x3e')](_0xe3f3b2,_0x34b57e[_0x4f5c('0x49')]),{'include':_0x34b57e[_0x4f5c('0x33')][_0x4f5c('0x47')]?[{'all':!![]}]:undefined})[_0x4f5c('0x23')](function(_0x597c60){var _0x5ba483=_0x34b57e[_0x4f5c('0x4b')][_0x4f5c('0x25')]({'plain':!![]});if(!_0x5ba483)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5ba483[_0x4f5c('0x54')]===_0x4f5c('0x4b')){var _0x4c1df8=_0x597c60[_0x4f5c('0x25')]({'plain':!![]});var _0x3e7dd6=_0x4f5c('0x26');return db[_0x4f5c('0x4c')]['find']({'where':{'name':_0x3e7dd6,'userProfileId':_0x5ba483[_0x4f5c('0x4d')]},'raw':!![]})[_0x4f5c('0x23')](function(_0x2fa47c){if(_0x2fa47c&&_0x2fa47c['autoAssociation']===0x0){return db[_0x4f5c('0x27')]['create']({'name':_0x4c1df8[_0x4f5c('0x2b')],'resourceId':_0x4c1df8['id'],'type':_0x2fa47c[_0x4f5c('0x2b')],'sectionId':_0x2fa47c['id']},{})[_0x4f5c('0x23')](function(){return _0x597c60;});}else{return _0x597c60;}})[_0x4f5c('0x44')](function(_0x454590){logger[_0x4f5c('0x29')](_0x4f5c('0x4f'),_0x454590);throw _0x454590;});}return _0x597c60;});}})[_0x4f5c('0x23')](respondWithResult(_0x54e8e8,0xc9))['catch'](handleError(_0x54e8e8,null));};exports[_0x4f5c('0x22')]=function(_0x225c9d,_0x44ced8){if(_0x225c9d[_0x4f5c('0x49')]['id']){delete _0x225c9d[_0x4f5c('0x49')]['id'];}return db[_0x4f5c('0x2f')][_0x4f5c('0x48')]({'where':{'id':_0x225c9d['params']['id']}})[_0x4f5c('0x23')](handleEntityNotFound(_0x44ced8,null))['then'](saveUpdates(_0x225c9d[_0x4f5c('0x49')],null))['then'](respondWithResult(_0x44ced8,null))[_0x4f5c('0x44')](handleError(_0x44ced8,null));};exports[_0x4f5c('0x24')]=function(_0x411600,_0x1ee0a3){return db[_0x4f5c('0x2f')]['find']({'where':{'id':_0x411600['params']['id']}})[_0x4f5c('0x23')](handleEntityNotFound(_0x1ee0a3,null))['then'](removeEntity(_0x1ee0a3,null))[_0x4f5c('0x44')](handleError(_0x1ee0a3,null));};exports[_0x4f5c('0x55')]=function(_0x5c8f9d,_0x5786fb,_0x2efbda){var _0x170e5c={'raw':!![],'where':{}};var _0x4aa602={};var _0x29edd7={'count':0x0,'rows':[]};return db[_0x4f5c('0x2f')][_0x4f5c('0x56')]({'where':{'id':_0x5c8f9d[_0x4f5c('0x45')]['id']}})[_0x4f5c('0x23')](handleEntityNotFound(_0x5786fb,null))['then'](function(_0x7287d2){if(_0x7287d2){_0x4aa602[_0x4f5c('0x32')]=_[_0x4f5c('0x34')](db[_0x4f5c('0x57')][_0x4f5c('0x46')]);_0x4aa602[_0x4f5c('0x33')]=_[_0x4f5c('0x34')](_0x5c8f9d[_0x4f5c('0x33')]);_0x4aa602[_0x4f5c('0x3d')]=_[_0x4f5c('0x35')](_0x4aa602[_0x4f5c('0x32')],_0x4aa602[_0x4f5c('0x33')]);_0x170e5c[_0x4f5c('0x36')]=_['intersection'](_0x4aa602[_0x4f5c('0x32')],qs['fields'](_0x5c8f9d[_0x4f5c('0x33')][_0x4f5c('0x37')]));_0x170e5c[_0x4f5c('0x36')]=_0x170e5c[_0x4f5c('0x36')][_0x4f5c('0x38')]?_0x170e5c[_0x4f5c('0x36')]:_0x4aa602[_0x4f5c('0x32')];if(!_0x5c8f9d[_0x4f5c('0x33')][_0x4f5c('0x39')]('nolimit')){_0x170e5c['limit']=qs[_0x4f5c('0x1c')](_0x5c8f9d[_0x4f5c('0x33')][_0x4f5c('0x1c')]);_0x170e5c['offset']=qs['offset'](_0x5c8f9d[_0x4f5c('0x33')][_0x4f5c('0x1a')]);}_0x170e5c[_0x4f5c('0x58')]=qs['sort'](_0x5c8f9d[_0x4f5c('0x33')]['sort']);_0x170e5c[_0x4f5c('0x3c')]=qs['filters'](_[_0x4f5c('0x59')](_0x5c8f9d[_0x4f5c('0x33')],_0x4aa602[_0x4f5c('0x3d')]));_0x170e5c[_0x4f5c('0x3c')][_0x4f5c('0x5a')]=_0x7287d2['id'];if(_0x5c8f9d[_0x4f5c('0x33')][_0x4f5c('0x40')]){_0x170e5c[_0x4f5c('0x3c')]=_[_0x4f5c('0x3e')](_0x170e5c[_0x4f5c('0x3c')],{'$or':_[_0x4f5c('0x2e')](_0x170e5c['attributes'],function(_0x37fe9c){var _0x437100={};_0x437100[_0x37fe9c]={'$like':'%'+_0x5c8f9d['query'][_0x4f5c('0x40')]+'%'};return _0x437100;})});}_0x170e5c=_[_0x4f5c('0x3e')]({},_0x170e5c,_0x5c8f9d[_0x4f5c('0x41')]);return db[_0x4f5c('0x57')][_0x4f5c('0x1d')]({'where':_0x170e5c[_0x4f5c('0x3c')]})[_0x4f5c('0x23')](function(_0x31224f){_0x29edd7[_0x4f5c('0x1d')]=_0x31224f;if(_0x5c8f9d[_0x4f5c('0x33')][_0x4f5c('0x47')]){_0x170e5c['include']=[{'all':!![]}];}return db[_0x4f5c('0x57')][_0x4f5c('0x5b')](_0x170e5c);})['then'](function(_0x26ae22){_0x29edd7[_0x4f5c('0x43')]=_0x26ae22;return _0x29edd7;});}})[_0x4f5c('0x23')](respondWithFilteredResult(_0x5786fb,_0x170e5c))[_0x4f5c('0x44')](handleError(_0x5786fb,null));};exports['getAnswers']=function(_0x19ef6a,_0x25f4da,_0x4213f2){var _0x47357f={'raw':!![],'where':{}};var _0x583ed3={};var _0x5dc23a={'count':0x0,'rows':[]};return db['JscriptyProject']['findOne']({'where':{'id':_0x19ef6a['params']['id']}})[_0x4f5c('0x23')](handleEntityNotFound(_0x25f4da,null))[_0x4f5c('0x23')](function(_0xf0b83e){if(_0xf0b83e){_0x583ed3[_0x4f5c('0x32')]=_[_0x4f5c('0x34')](db[_0x4f5c('0x5c')]['rawAttributes']);_0x583ed3['query']=_[_0x4f5c('0x34')](_0x19ef6a[_0x4f5c('0x33')]);_0x583ed3['filters']=_[_0x4f5c('0x35')](_0x583ed3[_0x4f5c('0x32')],_0x583ed3[_0x4f5c('0x33')]);_0x47357f['attributes']=_[_0x4f5c('0x35')](_0x583ed3[_0x4f5c('0x32')],qs[_0x4f5c('0x37')](_0x19ef6a[_0x4f5c('0x33')][_0x4f5c('0x37')]));_0x47357f[_0x4f5c('0x36')]=_0x47357f[_0x4f5c('0x36')][_0x4f5c('0x38')]?_0x47357f[_0x4f5c('0x36')]:_0x583ed3['model'];if(!_0x19ef6a[_0x4f5c('0x33')][_0x4f5c('0x39')](_0x4f5c('0x3a'))){_0x47357f[_0x4f5c('0x1c')]=qs[_0x4f5c('0x1c')](_0x19ef6a['query']['limit']);_0x47357f[_0x4f5c('0x1a')]=qs['offset'](_0x19ef6a[_0x4f5c('0x33')][_0x4f5c('0x1a')]);}_0x47357f[_0x4f5c('0x58')]=qs[_0x4f5c('0x3b')](_0x19ef6a[_0x4f5c('0x33')]['sort']);_0x47357f['where']=qs[_0x4f5c('0x3d')](_[_0x4f5c('0x59')](_0x19ef6a[_0x4f5c('0x33')],_0x583ed3[_0x4f5c('0x3d')]));_0x47357f['where']['ProjectId']=_0xf0b83e['id'];if(_0x19ef6a[_0x4f5c('0x33')][_0x4f5c('0x40')]){_0x47357f[_0x4f5c('0x3c')]=_['merge'](_0x47357f['where'],{'$or':_[_0x4f5c('0x2e')](_0x47357f[_0x4f5c('0x36')],function(_0x3910bf){var _0x3bb8d5={};_0x3bb8d5[_0x3910bf]={'$like':'%'+_0x19ef6a[_0x4f5c('0x33')][_0x4f5c('0x40')]+'%'};return _0x3bb8d5;})});}_0x47357f=_[_0x4f5c('0x3e')]({},_0x47357f,_0x19ef6a[_0x4f5c('0x41')]);return db['JscriptyAnswerReport'][_0x4f5c('0x1d')]({'where':_0x47357f[_0x4f5c('0x3c')]})[_0x4f5c('0x23')](function(_0x3676ed){_0x5dc23a[_0x4f5c('0x1d')]=_0x3676ed;if(_0x19ef6a[_0x4f5c('0x33')]['includeAll']){_0x47357f[_0x4f5c('0x42')]=[{'all':!![]}];}return db[_0x4f5c('0x5c')]['findAll'](_0x47357f);})['then'](function(_0x1eafd0){_0x5dc23a[_0x4f5c('0x43')]=_0x1eafd0;return _0x5dc23a;});}})['then'](respondWithFilteredResult(_0x25f4da,_0x47357f))[_0x4f5c('0x44')](handleError(_0x25f4da,null));};function char(_0xfb23af){return _0x4f5c('0x5d')===typeof _0xfb23af?String[_0x4f5c('0x5e')][_0x4f5c('0x20')](null,arguments):_0xfb23af;}function needsEncapsulation(_0x41708b){return!!_0x41708b&&(_0x41708b[_0x4f5c('0x5f')]()[_0x4f5c('0x60')](char(0xd))>=0x0||_0x41708b[_0x4f5c('0x5f')]()[_0x4f5c('0x60')](char(0xa))>=0x0||_0x41708b['toString']()[_0x4f5c('0x60')](char(0x2c))>=0x0||_0x41708b[_0x4f5c('0x5f')]()[_0x4f5c('0x60')](char(0x22))>=0x0);}function encapsulate(_0x3f46f6){var _0x3a82bf=char(0x22),_0x4b3e2b='\x5c'+char(0x22),_0x45a0d8=_0x3f46f6[_0x4f5c('0x5f')]()['replace'](new RegExp(_0x3a82bf,'g'),_0x4b3e2b);return _0x3a82bf+_0x45a0d8+_0x3a82bf;}exports[_0x4f5c('0x61')]=function(_0x22062c,_0x3bbace,_0x42950b){var _0x1425d7,_0x29a84b;var _0x320579={'where':{'ProjectId':_0x22062c[_0x4f5c('0x45')]['id']}};if(_0x22062c[_0x4f5c('0x33')][_0x4f5c('0x62')]){_0x320579[_0x4f5c('0x3c')][_0x4f5c('0x63')]=JSON[_0x4f5c('0x64')](_0x22062c['query'][_0x4f5c('0x62')]);}return db[_0x4f5c('0x57')][_0x4f5c('0x5b')](_0x320579)[_0x4f5c('0x23')](handleEntityNotFound(_0x3bbace,null))['then'](function(_0x2cb4d8){if(_0x2cb4d8){_0x1425d7=_0x2cb4d8;return db[_0x4f5c('0x65')][_0x4f5c('0x5b')]({'where':{'SessionId':{'$in':_[_0x4f5c('0x2e')](_0x1425d7,'id')},'ProjectId':_0x22062c[_0x4f5c('0x45')]['id']},'order':_0x4f5c('0x66')});}})[_0x4f5c('0x23')](handleEntityNotFound(_0x3bbace,null))[_0x4f5c('0x23')](function(_0x335d24){if(_0x335d24){_0x29a84b=_0x335d24;var _0x3c7cf5={};for(var _0x56f1a3=0x0,_0x41cdae=_0x29a84b[_0x4f5c('0x38')];_0x56f1a3<_0x41cdae;_0x56f1a3++){if(!_0x3c7cf5[_0x4f5c('0x39')](_0x29a84b[_0x56f1a3][_0x4f5c('0x67')])){_0x3c7cf5[_0x29a84b[_0x56f1a3][_0x4f5c('0x67')]]=needsEncapsulation(_0x29a84b[_0x56f1a3][_0x4f5c('0x68')])?encapsulate(_0x29a84b[_0x56f1a3][_0x4f5c('0x68')]):_0x29a84b[_0x56f1a3][_0x4f5c('0x68')];}}var _0x2fe642=[],_0x532cf6={};for(var _0x56d7a9=0x0,_0x41b44f=_0x1425d7['length'];_0x56d7a9<_0x41b44f;_0x56d7a9++){_0x532cf6={'ProjectId':_0x22062c[_0x4f5c('0x45')]['id'],'SessionId':_0x1425d7[_0x56d7a9]['id'],'StartTime':moment(_0x1425d7[_0x56d7a9][_0x4f5c('0x63')])['format'](_0x4f5c('0x69'))};for(var _0x14537c=0x0,_0x43f22d=_0x29a84b[_0x4f5c('0x38')];_0x14537c<_0x43f22d;_0x14537c++){if(_0x29a84b[_0x14537c][_0x4f5c('0x6a')]==_0x1425d7[_0x56d7a9]['id']&&_0x3c7cf5[_0x4f5c('0x39')](_0x29a84b[_0x14537c]['questionId'])){_0x532cf6[_0x3c7cf5[_0x29a84b[_0x14537c][_0x4f5c('0x67')]]]=_0x29a84b[_0x14537c][_0x4f5c('0x6b')];}}for(var _0x49ecf2 in _0x3c7cf5){if(!_0x532cf6[_0x4f5c('0x39')](_0x3c7cf5[_0x49ecf2])){_0x532cf6[_0x3c7cf5[_0x49ecf2]]=null;}}_0x2fe642[_0x4f5c('0x6c')](_0x532cf6);}return _0x2fe642;}})[_0x4f5c('0x23')](function(_0x3333c6){if(!_['isEmpty'](_0x3333c6)){var _0x3e6093=toCsv(_0x3333c6);var _0x2ff3f9=Date[_0x4f5c('0x6d')]();fs['writeFileSync'](util[_0x4f5c('0x6e')](_0x4f5c('0x6f'),_0x22062c[_0x4f5c('0x45')]['id'],_0x2ff3f9),_0x3e6093);_0x3bbace['setHeader'](_0x4f5c('0x70'),_0x4f5c('0x71')+util[_0x4f5c('0x6e')]('Jscripty_Project_%d_Summary_%s.csv',_0x22062c[_0x4f5c('0x45')]['id'],_0x2ff3f9));_0x3bbace[_0x4f5c('0x72')](_0x4f5c('0x73'),_0x4f5c('0x74'));return _0x3bbace[_0x4f5c('0x75')](util['format']('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x22062c[_0x4f5c('0x45')]['id'],_0x2ff3f9));}else{return _0x3bbace[_0x4f5c('0x18')](0xcc);}})['catch'](handleError(_0x3bbace,null));};