Built motion from commit (unavailable).|2.4.8
[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 _0xb10b=['filter','merge','map','field','options','count','includeAll','findAll','rows','show','params','keys','include','find','catch','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','updatedAt','user','findOne','rawAttributes','pick','ProjectId','JscriptySessionReport','JscriptyAnswerReport','number','toString','indexOf','replace','getSummary','startTime','starttime','parse','JscriptyQuestionReport','-createdAt','questionId','question','YYYY-MM-DD\x20HH:mm:ss','SessionId','answer','push','isEmpty','now','writeFileSync','format','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','Jscripty_Project_%d_Summary_%s.csv','Content-type','text/csv','download','html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','destroy','then','get','Projects','UserProfileResource','error','stack','name','send','index','JscriptyProject','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where'];(function(_0x3e0e6a,_0x2d178c){var _0x34deeb=function(_0x32d809){while(--_0x32d809){_0x3e0e6a['push'](_0x3e0e6a['shift']());}};_0x34deeb(++_0x2d178c);}(_0xb10b,0x12a));var _0xbb10=function(_0x5a6961,_0xd41ca6){_0x5a6961=_0x5a6961-0x0;var _0x4af0a6=_0xb10b[_0x5a6961];return _0x4af0a6;};'use strict';var pdf=require(_0xbb10('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbb10('0x1'));var zipdir=require(_0xbb10('0x2'));var jsonpatch=require(_0xbb10('0x3'));var rp=require('request-promise');var moment=require(_0xbb10('0x4'));var BPromise=require(_0xbb10('0x5'));var Mustache=require(_0xbb10('0x6'));var util=require(_0xbb10('0x7'));var path=require(_0xbb10('0x8'));var sox=require(_0xbb10('0x9'));var csv=require('to-csv');var ejs=require(_0xbb10('0xa'));var fs=require('fs');var _=require(_0xbb10('0xb'));var squel=require('squel');var crypto=require(_0xbb10('0xc'));var jsforce=require(_0xbb10('0xd'));var deskjs=require(_0xbb10('0xe'));var toCsv=require(_0xbb10('0xf'));var querystring=require(_0xbb10('0x10'));var Papa=require(_0xbb10('0x11'));var Redis=require(_0xbb10('0x12'));var authService=require(_0xbb10('0x13'));var qs=require('../../components/parsers/qs');var hardwareService=require('../../config/license/hardware');var logger=require(_0xbb10('0x14'))(_0xbb10('0x15'));var utils=require(_0xbb10('0x16'));var config=require('../../config/environment');var db=require(_0xbb10('0x17'))['db'];function respondWithStatusCode(_0x5be7e0,_0x44fb19){_0x44fb19=_0x44fb19||0xcc;return function(_0x916a32){if(_0x916a32){return _0x5be7e0[_0xbb10('0x18')](_0x44fb19);}return _0x5be7e0[_0xbb10('0x19')](_0x44fb19)[_0xbb10('0x1a')]();};}function respondWithResult(_0x147230,_0x58a612){_0x58a612=_0x58a612||0xc8;return function(_0x26e021){if(_0x26e021){return _0x147230[_0xbb10('0x19')](_0x58a612)[_0xbb10('0x1b')](_0x26e021);}};}function respondWithFilteredResult(_0x17fd46,_0x3df17b){return function(_0x2f2ebf){if(_0x2f2ebf){var _0x24a57b=_0x2f2ebf['count'],_0x36b5e8=_0x3df17b[_0xbb10('0x1c')],_0x3e26f4=_0x3df17b[_0xbb10('0x1c')]+_0x3df17b[_0xbb10('0x1d')],_0x2b184e;if(_0x3e26f4>=_0x24a57b){_0x3e26f4=_0x24a57b;_0x2b184e=0xc8;}else{_0x2b184e=0xce;}_0x17fd46[_0xbb10('0x19')](_0x2b184e);return _0x17fd46[_0xbb10('0x1e')](_0xbb10('0x1f'),_0x36b5e8+'-'+_0x3e26f4+'/'+_0x24a57b)[_0xbb10('0x1b')](_0x2f2ebf);}return null;};}function patchUpdates(_0x30efc6){return function(_0xbf2906){try{jsonpatch[_0xbb10('0x20')](_0xbf2906,_0x30efc6,!![]);}catch(_0x48b6e9){return BPromise[_0xbb10('0x21')](_0x48b6e9);}return _0xbf2906[_0xbb10('0x22')]();};}function saveUpdates(_0x388fab,_0x109908){return function(_0xdf237d){if(_0xdf237d){return _0xdf237d[_0xbb10('0x23')](_0x388fab)['then'](function(_0x12f888){return _0x12f888;});}return null;};}function removeEntity(_0x12ef77,_0x50aea1){return function(_0x4c4b0d){if(_0x4c4b0d){return _0x4c4b0d[_0xbb10('0x24')]()[_0xbb10('0x25')](function(){var _0x2e911d=_0x4c4b0d[_0xbb10('0x26')]({'plain':!![]});var _0x445761=_0xbb10('0x27');return db[_0xbb10('0x28')][_0xbb10('0x24')]({'where':{'type':_0x445761,'resourceId':_0x2e911d['id']}})[_0xbb10('0x25')](function(){return _0x4c4b0d;});})[_0xbb10('0x25')](function(){_0x12ef77[_0xbb10('0x19')](0xcc)[_0xbb10('0x1a')]();});}};}function handleEntityNotFound(_0x537898,_0x4fedac){return function(_0x4fb5e0){if(!_0x4fb5e0){_0x537898[_0xbb10('0x18')](0x194);}return _0x4fb5e0;};}function handleError(_0x3c5ae7,_0x2c89b9){_0x2c89b9=_0x2c89b9||0x1f4;return function(_0x4e25ff){logger[_0xbb10('0x29')](_0x4e25ff[_0xbb10('0x2a')]);if(_0x4e25ff[_0xbb10('0x2b')]){delete _0x4e25ff[_0xbb10('0x2b')];}_0x3c5ae7[_0xbb10('0x19')](_0x2c89b9)[_0xbb10('0x2c')](_0x4e25ff);};}exports[_0xbb10('0x2d')]=function(_0x4aabb9,_0x3796c7){var _0x21ac54={},_0xfc3595={},_0x2e0249={'count':0x0,'rows':[]};var _0x1d30aa=db[_0xbb10('0x2e')]['rawAttributes'];_0xfc3595[_0xbb10('0x2f')]=_['keys'](_0x1d30aa);_0xfc3595[_0xbb10('0x30')]=_['keys'](_0x4aabb9[_0xbb10('0x30')]);_0xfc3595[_0xbb10('0x31')]=_[_0xbb10('0x32')](_0xfc3595['model'],_0xfc3595['query']);_0x21ac54[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0xfc3595['model'],qs[_0xbb10('0x34')](_0x4aabb9[_0xbb10('0x30')][_0xbb10('0x34')]));_0x21ac54[_0xbb10('0x33')]=_0x21ac54[_0xbb10('0x33')][_0xbb10('0x35')]?_0x21ac54[_0xbb10('0x33')]:_0xfc3595['model'];if(!_0x4aabb9[_0xbb10('0x30')][_0xbb10('0x36')](_0xbb10('0x37'))){_0x21ac54[_0xbb10('0x1d')]=qs[_0xbb10('0x1d')](_0x4aabb9[_0xbb10('0x30')][_0xbb10('0x1d')]);_0x21ac54[_0xbb10('0x1c')]=qs[_0xbb10('0x1c')](_0x4aabb9['query'][_0xbb10('0x1c')]);}_0x21ac54[_0xbb10('0x38')]=qs[_0xbb10('0x39')](_0x4aabb9[_0xbb10('0x30')]['sort']);_0x21ac54[_0xbb10('0x3a')]=qs['filters'](_['pick'](_0x4aabb9[_0xbb10('0x30')],_0xfc3595[_0xbb10('0x31')]));if(_0x4aabb9[_0xbb10('0x30')][_0xbb10('0x3b')]){_0x21ac54[_0xbb10('0x3a')]=_[_0xbb10('0x3c')](_0x21ac54['where'],{'$or':_[_0xbb10('0x3d')](_0x1d30aa,function(_0x25d72f){if(_0x25d72f['type']['key']!=='VIRTUAL'){var _0x31bee3={};_0x31bee3[_0x25d72f[_0xbb10('0x3e')]]={'$like':'%'+_0x4aabb9[_0xbb10('0x30')]['filter']+'%'};return _0x31bee3;}})});}_0x21ac54=_[_0xbb10('0x3c')]({},_0x21ac54,_0x4aabb9[_0xbb10('0x3f')]);var _0x4345f3={'where':_0x21ac54['where']};return db[_0xbb10('0x2e')][_0xbb10('0x40')](_0x4345f3)[_0xbb10('0x25')](function(_0x446f49){_0x2e0249['count']=_0x446f49;if(_0x4aabb9[_0xbb10('0x30')][_0xbb10('0x41')]){_0x21ac54['include']=[{'all':!![]}];}return db[_0xbb10('0x2e')][_0xbb10('0x42')](_0x21ac54);})[_0xbb10('0x25')](function(_0x3a9934){_0x2e0249[_0xbb10('0x43')]=_0x3a9934;return _0x2e0249;})[_0xbb10('0x25')](respondWithFilteredResult(_0x3796c7,_0x21ac54))['catch'](handleError(_0x3796c7,null));};exports[_0xbb10('0x44')]=function(_0x1c7fae,_0x3e7b4c){var _0x3d3c41={'raw':![],'where':{'id':_0x1c7fae[_0xbb10('0x45')]['id']}},_0x4943d9={};_0x4943d9[_0xbb10('0x2f')]=_[_0xbb10('0x46')](db[_0xbb10('0x2e')]['rawAttributes']);_0x4943d9[_0xbb10('0x30')]=_[_0xbb10('0x46')](_0x1c7fae['query']);_0x4943d9['filters']=_[_0xbb10('0x32')](_0x4943d9['model'],_0x4943d9[_0xbb10('0x30')]);_0x3d3c41[_0xbb10('0x33')]=_['intersection'](_0x4943d9[_0xbb10('0x2f')],qs[_0xbb10('0x34')](_0x1c7fae[_0xbb10('0x30')]['fields']));_0x3d3c41[_0xbb10('0x33')]=_0x3d3c41[_0xbb10('0x33')][_0xbb10('0x35')]?_0x3d3c41[_0xbb10('0x33')]:_0x4943d9[_0xbb10('0x2f')];if(_0x1c7fae[_0xbb10('0x30')][_0xbb10('0x41')]){_0x3d3c41[_0xbb10('0x47')]=[{'all':!![]}];}_0x3d3c41=_[_0xbb10('0x3c')]({},_0x3d3c41,_0x1c7fae[_0xbb10('0x3f')]);return db[_0xbb10('0x2e')][_0xbb10('0x48')](_0x3d3c41)['then'](handleEntityNotFound(_0x3e7b4c,null))[_0xbb10('0x25')](respondWithResult(_0x3e7b4c,null))[_0xbb10('0x49')](handleError(_0x3e7b4c,null));};exports['create']=function(_0x14e1cb,_0x2f5027){return db[_0xbb10('0x2e')][_0xbb10('0x4a')](_0x14e1cb[_0xbb10('0x4b')],{})[_0xbb10('0x25')](function(_0x3e06b0){var _0x5be85e=_0x14e1cb['user'][_0xbb10('0x26')]({'plain':!![]});if(!_0x5be85e)throw new Error(_0xbb10('0x4c'));if(_0x5be85e[_0xbb10('0x4d')]==='user'){var _0x5f0c12=_0x3e06b0[_0xbb10('0x26')]({'plain':!![]});var _0x34cf4e=_0xbb10('0x27');return db[_0xbb10('0x4e')][_0xbb10('0x48')]({'where':{'name':_0x34cf4e,'userProfileId':_0x5be85e[_0xbb10('0x4f')]},'raw':!![]})[_0xbb10('0x25')](function(_0x460788){if(_0x460788&&_0x460788[_0xbb10('0x50')]===0x0){return db[_0xbb10('0x28')]['create']({'name':_0x5f0c12['name'],'resourceId':_0x5f0c12['id'],'type':_0x460788[_0xbb10('0x2b')],'sectionId':_0x460788['id']},{})[_0xbb10('0x25')](function(){return _0x3e06b0;});}else{return _0x3e06b0;}})[_0xbb10('0x49')](function(_0xb014b0){logger[_0xbb10('0x29')](_0xbb10('0x51'),_0xb014b0);throw _0xb014b0;});}return _0x3e06b0;})[_0xbb10('0x25')](respondWithResult(_0x2f5027,0xc9))[_0xbb10('0x49')](handleError(_0x2f5027,null));};exports[_0xbb10('0x52')]=function(_0x1214f7,_0x19ca3e){var _0x20e18a={'raw':![],'where':{'id':_0x1214f7[_0xbb10('0x45')]['id']}},_0x61e689={};_0x61e689[_0xbb10('0x2f')]=_['keys'](db[_0xbb10('0x2e')]['rawAttributes']);_0x20e18a[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0x61e689[_0xbb10('0x2f')],qs[_0xbb10('0x34')](_0x1214f7[_0xbb10('0x30')][_0xbb10('0x34')]));_0x20e18a[_0xbb10('0x33')]=_0x20e18a[_0xbb10('0x33')][_0xbb10('0x35')]?_0x20e18a[_0xbb10('0x33')]:_0x61e689[_0xbb10('0x2f')];if(_0x1214f7[_0xbb10('0x30')][_0xbb10('0x41')]){_0x20e18a[_0xbb10('0x47')]=[{'all':!![]}];}_0x20e18a=_[_0xbb10('0x3c')]({},_0x20e18a,_0x1214f7['options']);return db[_0xbb10('0x2e')][_0xbb10('0x48')](_0x20e18a)[_0xbb10('0x25')](handleEntityNotFound(_0x19ca3e,null))[_0xbb10('0x25')](function(_0xbffa3c){if(_0xbffa3c){var _0x379d8c=_0xbffa3c['get']({'plain':!![]});_0x379d8c=qs[_0xbb10('0x53')](_0x379d8c,['id',_0xbb10('0x54'),_0xbb10('0x55')]);_0x1214f7[_0xbb10('0x4b')]=_[_0xbb10('0x53')](_0x1214f7[_0xbb10('0x4b')],['id',_0xbb10('0x54'),_0xbb10('0x55')]);return db[_0xbb10('0x2e')][_0xbb10('0x4a')](_[_0xbb10('0x3c')](_0x379d8c,_0x1214f7[_0xbb10('0x4b')]),{'include':_0x1214f7[_0xbb10('0x30')]['includeAll']?[{'all':!![]}]:undefined})['then'](function(_0x16272d){var _0x3e6338=_0x1214f7[_0xbb10('0x56')][_0xbb10('0x26')]({'plain':!![]});if(!_0x3e6338)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3e6338['role']===_0xbb10('0x56')){var _0xaf2cc3=_0x16272d[_0xbb10('0x26')]({'plain':!![]});var _0x2dd150=_0xbb10('0x27');return db[_0xbb10('0x4e')][_0xbb10('0x48')]({'where':{'name':_0x2dd150,'userProfileId':_0x3e6338['userProfileId']},'raw':!![]})[_0xbb10('0x25')](function(_0x216cff){if(_0x216cff&&_0x216cff['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0xaf2cc3[_0xbb10('0x2b')],'resourceId':_0xaf2cc3['id'],'type':_0x216cff[_0xbb10('0x2b')],'sectionId':_0x216cff['id']},{})[_0xbb10('0x25')](function(){return _0x16272d;});}else{return _0x16272d;}})['catch'](function(_0x4e6e7c){logger['error'](_0xbb10('0x51'),_0x4e6e7c);throw _0x4e6e7c;});}return _0x16272d;});}})[_0xbb10('0x25')](respondWithResult(_0x19ca3e,0xc9))[_0xbb10('0x49')](handleError(_0x19ca3e,null));};exports['update']=function(_0xa1bbd9,_0x13131c){if(_0xa1bbd9['body']['id']){delete _0xa1bbd9['body']['id'];}return db[_0xbb10('0x2e')][_0xbb10('0x48')]({'where':{'id':_0xa1bbd9[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x13131c,null))['then'](saveUpdates(_0xa1bbd9[_0xbb10('0x4b')],null))[_0xbb10('0x25')](respondWithResult(_0x13131c,null))[_0xbb10('0x49')](handleError(_0x13131c,null));};exports['destroy']=function(_0x402a01,_0x2f05bc){return db[_0xbb10('0x2e')]['find']({'where':{'id':_0x402a01[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x2f05bc,null))[_0xbb10('0x25')](removeEntity(_0x2f05bc,null))[_0xbb10('0x49')](handleError(_0x2f05bc,null));};exports['getSessions']=function(_0x251417,_0x258e55,_0x108e5b){var _0x2d0f4b={'raw':!![],'where':{}};var _0x56b3a3={};var _0x354ea7={'count':0x0,'rows':[]};return db[_0xbb10('0x2e')][_0xbb10('0x57')]({'where':{'id':_0x251417[_0xbb10('0x45')]['id']}})[_0xbb10('0x25')](handleEntityNotFound(_0x258e55,null))[_0xbb10('0x25')](function(_0x1e4694){if(_0x1e4694){_0x56b3a3['model']=_['keys'](db['JscriptySessionReport'][_0xbb10('0x58')]);_0x56b3a3[_0xbb10('0x30')]=_[_0xbb10('0x46')](_0x251417['query']);_0x56b3a3['filters']=_[_0xbb10('0x32')](_0x56b3a3[_0xbb10('0x2f')],_0x56b3a3[_0xbb10('0x30')]);_0x2d0f4b[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0x56b3a3[_0xbb10('0x2f')],qs['fields'](_0x251417[_0xbb10('0x30')][_0xbb10('0x34')]));_0x2d0f4b[_0xbb10('0x33')]=_0x2d0f4b[_0xbb10('0x33')][_0xbb10('0x35')]?_0x2d0f4b['attributes']:_0x56b3a3['model'];if(!_0x251417['query'][_0xbb10('0x36')](_0xbb10('0x37'))){_0x2d0f4b[_0xbb10('0x1d')]=qs[_0xbb10('0x1d')](_0x251417[_0xbb10('0x30')][_0xbb10('0x1d')]);_0x2d0f4b['offset']=qs[_0xbb10('0x1c')](_0x251417['query']['offset']);}_0x2d0f4b['order']=qs[_0xbb10('0x39')](_0x251417[_0xbb10('0x30')][_0xbb10('0x39')]);_0x2d0f4b[_0xbb10('0x3a')]=qs['filters'](_[_0xbb10('0x59')](_0x251417['query'],_0x56b3a3['filters']));_0x2d0f4b[_0xbb10('0x3a')][_0xbb10('0x5a')]=_0x1e4694['id'];if(_0x251417[_0xbb10('0x30')][_0xbb10('0x3b')]){_0x2d0f4b[_0xbb10('0x3a')]=_['merge'](_0x2d0f4b[_0xbb10('0x3a')],{'$or':_[_0xbb10('0x3d')](_0x2d0f4b[_0xbb10('0x33')],function(_0x3f3d38){var _0x43cdb7={};_0x43cdb7[_0x3f3d38]={'$like':'%'+_0x251417[_0xbb10('0x30')][_0xbb10('0x3b')]+'%'};return _0x43cdb7;})});}_0x2d0f4b=_['merge']({},_0x2d0f4b,_0x251417[_0xbb10('0x3f')]);return db[_0xbb10('0x5b')][_0xbb10('0x40')]({'where':_0x2d0f4b[_0xbb10('0x3a')]})[_0xbb10('0x25')](function(_0x172be3){_0x354ea7[_0xbb10('0x40')]=_0x172be3;if(_0x251417[_0xbb10('0x30')]['includeAll']){_0x2d0f4b[_0xbb10('0x47')]=[{'all':!![]}];}return db[_0xbb10('0x5b')][_0xbb10('0x42')](_0x2d0f4b);})['then'](function(_0x4ee101){_0x354ea7['rows']=_0x4ee101;return _0x354ea7;});}})[_0xbb10('0x25')](respondWithFilteredResult(_0x258e55,_0x2d0f4b))['catch'](handleError(_0x258e55,null));};exports['getAnswers']=function(_0x1701c5,_0x3ee56b,_0x33ff06){var _0x12ed63={'raw':!![],'where':{}};var _0x32ec27={};var _0x24dca6={'count':0x0,'rows':[]};return db[_0xbb10('0x2e')][_0xbb10('0x57')]({'where':{'id':_0x1701c5[_0xbb10('0x45')]['id']}})['then'](handleEntityNotFound(_0x3ee56b,null))[_0xbb10('0x25')](function(_0x1351eb){if(_0x1351eb){_0x32ec27[_0xbb10('0x2f')]=_[_0xbb10('0x46')](db['JscriptyAnswerReport']['rawAttributes']);_0x32ec27[_0xbb10('0x30')]=_[_0xbb10('0x46')](_0x1701c5[_0xbb10('0x30')]);_0x32ec27[_0xbb10('0x31')]=_['intersection'](_0x32ec27[_0xbb10('0x2f')],_0x32ec27[_0xbb10('0x30')]);_0x12ed63[_0xbb10('0x33')]=_[_0xbb10('0x32')](_0x32ec27[_0xbb10('0x2f')],qs['fields'](_0x1701c5['query'][_0xbb10('0x34')]));_0x12ed63[_0xbb10('0x33')]=_0x12ed63[_0xbb10('0x33')]['length']?_0x12ed63[_0xbb10('0x33')]:_0x32ec27[_0xbb10('0x2f')];if(!_0x1701c5['query']['hasOwnProperty'](_0xbb10('0x37'))){_0x12ed63[_0xbb10('0x1d')]=qs[_0xbb10('0x1d')](_0x1701c5['query'][_0xbb10('0x1d')]);_0x12ed63[_0xbb10('0x1c')]=qs[_0xbb10('0x1c')](_0x1701c5[_0xbb10('0x30')][_0xbb10('0x1c')]);}_0x12ed63[_0xbb10('0x38')]=qs[_0xbb10('0x39')](_0x1701c5[_0xbb10('0x30')][_0xbb10('0x39')]);_0x12ed63['where']=qs[_0xbb10('0x31')](_[_0xbb10('0x59')](_0x1701c5[_0xbb10('0x30')],_0x32ec27[_0xbb10('0x31')]));_0x12ed63[_0xbb10('0x3a')][_0xbb10('0x5a')]=_0x1351eb['id'];if(_0x1701c5[_0xbb10('0x30')][_0xbb10('0x3b')]){_0x12ed63[_0xbb10('0x3a')]=_[_0xbb10('0x3c')](_0x12ed63[_0xbb10('0x3a')],{'$or':_[_0xbb10('0x3d')](_0x12ed63['attributes'],function(_0x51f106){var _0xe1fc51={};_0xe1fc51[_0x51f106]={'$like':'%'+_0x1701c5[_0xbb10('0x30')][_0xbb10('0x3b')]+'%'};return _0xe1fc51;})});}_0x12ed63=_[_0xbb10('0x3c')]({},_0x12ed63,_0x1701c5[_0xbb10('0x3f')]);return db['JscriptyAnswerReport'][_0xbb10('0x40')]({'where':_0x12ed63[_0xbb10('0x3a')]})[_0xbb10('0x25')](function(_0x1a51d3){_0x24dca6[_0xbb10('0x40')]=_0x1a51d3;if(_0x1701c5[_0xbb10('0x30')]['includeAll']){_0x12ed63[_0xbb10('0x47')]=[{'all':!![]}];}return db[_0xbb10('0x5c')]['findAll'](_0x12ed63);})[_0xbb10('0x25')](function(_0x55e58b){_0x24dca6[_0xbb10('0x43')]=_0x55e58b;return _0x24dca6;});}})[_0xbb10('0x25')](respondWithFilteredResult(_0x3ee56b,_0x12ed63))[_0xbb10('0x49')](handleError(_0x3ee56b,null));};function char(_0xa99bf5){return _0xbb10('0x5d')===typeof _0xa99bf5?String['fromCharCode'][_0xbb10('0x20')](null,arguments):_0xa99bf5;}function needsEncapsulation(_0x5238bc){return!!_0x5238bc&&(_0x5238bc[_0xbb10('0x5e')]()[_0xbb10('0x5f')](char(0xd))>=0x0||_0x5238bc['toString']()['indexOf'](char(0xa))>=0x0||_0x5238bc[_0xbb10('0x5e')]()[_0xbb10('0x5f')](char(0x2c))>=0x0||_0x5238bc[_0xbb10('0x5e')]()[_0xbb10('0x5f')](char(0x22))>=0x0);}function encapsulate(_0x18d18d){var _0x1cb22f=char(0x22),_0x1b6ebc='\x5c'+char(0x22),_0x25b4ef=_0x18d18d[_0xbb10('0x5e')]()[_0xbb10('0x60')](new RegExp(_0x1cb22f,'g'),_0x1b6ebc);return _0x1cb22f+_0x25b4ef+_0x1cb22f;}exports[_0xbb10('0x61')]=function(_0x4c0b83,_0x2b9a50,_0x3eeceb){var _0x1b0a6c,_0xcd5d35;var _0xfe02f5={'where':{'ProjectId':_0x4c0b83[_0xbb10('0x45')]['id']}};if(_0x4c0b83[_0xbb10('0x30')][_0xbb10('0x62')]){_0xfe02f5[_0xbb10('0x3a')][_0xbb10('0x63')]=JSON[_0xbb10('0x64')](_0x4c0b83[_0xbb10('0x30')]['startTime']);}return db[_0xbb10('0x5b')]['findAll'](_0xfe02f5)[_0xbb10('0x25')](handleEntityNotFound(_0x2b9a50,null))[_0xbb10('0x25')](function(_0x3b2b54){if(_0x3b2b54){_0x1b0a6c=_0x3b2b54;return db[_0xbb10('0x65')][_0xbb10('0x42')]({'where':{'SessionId':{'$in':_['map'](_0x1b0a6c,'id')},'ProjectId':_0x4c0b83[_0xbb10('0x45')]['id']},'order':_0xbb10('0x66')});}})[_0xbb10('0x25')](handleEntityNotFound(_0x2b9a50,null))[_0xbb10('0x25')](function(_0x315b55){if(_0x315b55){_0xcd5d35=_0x315b55;var _0x41380b={};for(var _0x4970fe=0x0,_0x4bd470=_0xcd5d35[_0xbb10('0x35')];_0x4970fe<_0x4bd470;_0x4970fe++){if(!_0x41380b[_0xbb10('0x36')](_0xcd5d35[_0x4970fe][_0xbb10('0x67')])){_0x41380b[_0xcd5d35[_0x4970fe]['questionId']]=needsEncapsulation(_0xcd5d35[_0x4970fe][_0xbb10('0x68')])?encapsulate(_0xcd5d35[_0x4970fe][_0xbb10('0x68')]):_0xcd5d35[_0x4970fe]['question'];}}var _0x2831de=[],_0xaede56={};for(var _0x5642c3=0x0,_0xdd3c7e=_0x1b0a6c['length'];_0x5642c3<_0xdd3c7e;_0x5642c3++){_0xaede56={'ProjectId':_0x4c0b83[_0xbb10('0x45')]['id'],'SessionId':_0x1b0a6c[_0x5642c3]['id'],'StartTime':moment(_0x1b0a6c[_0x5642c3][_0xbb10('0x63')])['format'](_0xbb10('0x69'))};for(var _0x28cc74=0x0,_0x4bac29=_0xcd5d35['length'];_0x28cc74<_0x4bac29;_0x28cc74++){if(_0xcd5d35[_0x28cc74][_0xbb10('0x6a')]==_0x1b0a6c[_0x5642c3]['id']&&_0x41380b[_0xbb10('0x36')](_0xcd5d35[_0x28cc74][_0xbb10('0x67')])){_0xaede56[_0x41380b[_0xcd5d35[_0x28cc74][_0xbb10('0x67')]]]=_0xcd5d35[_0x28cc74][_0xbb10('0x6b')];}}for(var _0x4c3bdc in _0x41380b){if(!_0xaede56[_0xbb10('0x36')](_0x41380b[_0x4c3bdc])){_0xaede56[_0x41380b[_0x4c3bdc]]=null;}}_0x2831de[_0xbb10('0x6c')](_0xaede56);}return _0x2831de;}})[_0xbb10('0x25')](function(_0x59e020){if(!_[_0xbb10('0x6d')](_0x59e020)){var _0x4f90e6=toCsv(_0x59e020);var _0x248887=Date[_0xbb10('0x6e')]();fs[_0xbb10('0x6f')](util[_0xbb10('0x70')](_0xbb10('0x71'),_0x4c0b83[_0xbb10('0x45')]['id'],_0x248887),_0x4f90e6);_0x2b9a50[_0xbb10('0x72')]('Content-disposition','attachment;\x20filename='+util[_0xbb10('0x70')](_0xbb10('0x73'),_0x4c0b83[_0xbb10('0x45')]['id'],_0x248887));_0x2b9a50[_0xbb10('0x72')](_0xbb10('0x74'),_0xbb10('0x75'));return _0x2b9a50[_0xbb10('0x76')](util[_0xbb10('0x70')](_0xbb10('0x71'),_0x4c0b83[_0xbb10('0x45')]['id'],_0x248887));}else{return _0x2b9a50[_0xbb10('0x18')](0xcc);}})[_0xbb10('0x49')](handleError(_0x2b9a50,null));};