Built motion from commit (unavailable).|2.5.0
[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 _0x0f59=['map','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','nolimit','order','filter','merge','where','VIRTUAL','JscriptyProject','findAll','rows','catch','show','params','includeAll','include','options','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','clone','omit','createdAt','updatedAt','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getSessions','findOne','JscriptySessionReport','hasOwnProperty','sort','pick','getAnswers','JscriptyAnswerReport','number','toString','indexOf','getSummary','startTime','starttime','parse','questionId','question','format','YYYY-MM-DD\x20HH:mm:ss','push','isEmpty','now','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','Content-disposition','Jscripty_Project_%d_Summary_%s.csv','Content-type','text/csv','download','sendStatus','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','status','end','json','count','offset','limit','Content-Range','apply','reject','update','then','destroy','Projects','UserProfileResource','error','stack','name','index'];(function(_0x51b0c8,_0x3cbf0d){var _0x50908c=function(_0x33a4df){while(--_0x33a4df){_0x51b0c8['push'](_0x51b0c8['shift']());}};_0x50908c(++_0x3cbf0d);}(_0x0f59,0x131));var _0x90f5=function(_0x95411e,_0x38b4c3){_0x95411e=_0x95411e-0x0;var _0x2c8718=_0x0f59[_0x95411e];return _0x2c8718;};'use strict';var pdf=require(_0x90f5('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x90f5('0x1'));var zipdir=require(_0x90f5('0x2'));var jsonpatch=require(_0x90f5('0x3'));var rp=require(_0x90f5('0x4'));var moment=require(_0x90f5('0x5'));var BPromise=require(_0x90f5('0x6'));var Mustache=require(_0x90f5('0x7'));var util=require(_0x90f5('0x8'));var path=require(_0x90f5('0x9'));var sox=require(_0x90f5('0xa'));var csv=require(_0x90f5('0xb'));var ejs=require(_0x90f5('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0x90f5('0xd'));var crypto=require('crypto');var jsforce=require(_0x90f5('0xe'));var deskjs=require(_0x90f5('0xf'));var toCsv=require(_0x90f5('0xb'));var querystring=require(_0x90f5('0x10'));var Papa=require(_0x90f5('0x11'));var Redis=require(_0x90f5('0x12'));var authService=require(_0x90f5('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x90f5('0x14'));var logger=require(_0x90f5('0x15'))('api');var utils=require(_0x90f5('0x16'));var config=require(_0x90f5('0x17'));var db=require(_0x90f5('0x18'))['db'];function respondWithStatusCode(_0x4e46f4,_0x202aaf){_0x202aaf=_0x202aaf||0xcc;return function(_0x5588c2){if(_0x5588c2){return _0x4e46f4['sendStatus'](_0x202aaf);}return _0x4e46f4[_0x90f5('0x19')](_0x202aaf)[_0x90f5('0x1a')]();};}function respondWithResult(_0x6271a0,_0x180984){_0x180984=_0x180984||0xc8;return function(_0x1756d7){if(_0x1756d7){return _0x6271a0[_0x90f5('0x19')](_0x180984)[_0x90f5('0x1b')](_0x1756d7);}};}function respondWithFilteredResult(_0x3e459c,_0x552516){return function(_0x285d48){if(_0x285d48){var _0x36f7a0=_0x285d48[_0x90f5('0x1c')],_0x1ad3ce=_0x552516[_0x90f5('0x1d')],_0x103b72=_0x552516[_0x90f5('0x1d')]+_0x552516[_0x90f5('0x1e')],_0x5957e9;if(_0x103b72>=_0x36f7a0){_0x103b72=_0x36f7a0;_0x5957e9=0xc8;}else{_0x5957e9=0xce;}_0x3e459c[_0x90f5('0x19')](_0x5957e9);return _0x3e459c['set'](_0x90f5('0x1f'),_0x1ad3ce+'-'+_0x103b72+'/'+_0x36f7a0)[_0x90f5('0x1b')](_0x285d48);}return null;};}function patchUpdates(_0xbe3cdb){return function(_0x282359){try{jsonpatch[_0x90f5('0x20')](_0x282359,_0xbe3cdb,!![]);}catch(_0x1ac4dd){return BPromise[_0x90f5('0x21')](_0x1ac4dd);}return _0x282359['save']();};}function saveUpdates(_0x11d30f,_0x178e3a){return function(_0x32dc01){if(_0x32dc01){return _0x32dc01[_0x90f5('0x22')](_0x11d30f)[_0x90f5('0x23')](function(_0x1cb935){return _0x1cb935;});}return null;};}function removeEntity(_0x5cbabb,_0x42ed59){return function(_0x5e0165){if(_0x5e0165){return _0x5e0165[_0x90f5('0x24')]()[_0x90f5('0x23')](function(){var _0x570494=_0x5e0165['get']({'plain':!![]});var _0x3fa336=_0x90f5('0x25');return db[_0x90f5('0x26')][_0x90f5('0x24')]({'where':{'type':_0x3fa336,'resourceId':_0x570494['id']}})[_0x90f5('0x23')](function(){return _0x5e0165;});})[_0x90f5('0x23')](function(){_0x5cbabb['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x307816,_0x169ffb){return function(_0x36bd0e){if(!_0x36bd0e){_0x307816['sendStatus'](0x194);}return _0x36bd0e;};}function handleError(_0x583b7f,_0x7dab61){_0x7dab61=_0x7dab61||0x1f4;return function(_0x546430){logger[_0x90f5('0x27')](_0x546430[_0x90f5('0x28')]);if(_0x546430[_0x90f5('0x29')]){delete _0x546430[_0x90f5('0x29')];}_0x583b7f[_0x90f5('0x19')](_0x7dab61)['send'](_0x546430);};}exports[_0x90f5('0x2a')]=function(_0x452e4a,_0x13c9b1){var _0x335496={},_0x957dc3={},_0x3b6ca8={'count':0x0,'rows':[]};var _0xb7497b=_[_0x90f5('0x2b')](db['JscriptyProject'][_0x90f5('0x2c')],function(_0x48b45b){return{'name':_0x48b45b[_0x90f5('0x2d')],'type':_0x48b45b[_0x90f5('0x2e')][_0x90f5('0x2f')]};});_0x957dc3['model']=_['map'](_0xb7497b,_0x90f5('0x29'));_0x957dc3['query']=_[_0x90f5('0x30')](_0x452e4a[_0x90f5('0x31')]);_0x957dc3[_0x90f5('0x32')]=_[_0x90f5('0x33')](_0x957dc3[_0x90f5('0x34')],_0x957dc3['query']);_0x335496[_0x90f5('0x35')]=_[_0x90f5('0x33')](_0x957dc3[_0x90f5('0x34')],qs[_0x90f5('0x36')](_0x452e4a[_0x90f5('0x31')][_0x90f5('0x36')]));_0x335496[_0x90f5('0x35')]=_0x335496[_0x90f5('0x35')][_0x90f5('0x37')]?_0x335496[_0x90f5('0x35')]:_0x957dc3['model'];if(!_0x452e4a[_0x90f5('0x31')]['hasOwnProperty'](_0x90f5('0x38'))){_0x335496[_0x90f5('0x1e')]=qs[_0x90f5('0x1e')](_0x452e4a[_0x90f5('0x31')][_0x90f5('0x1e')]);_0x335496[_0x90f5('0x1d')]=qs[_0x90f5('0x1d')](_0x452e4a[_0x90f5('0x31')]['offset']);}_0x335496[_0x90f5('0x39')]=qs['sort'](_0x452e4a[_0x90f5('0x31')]['sort']);_0x335496['where']=qs['filters'](_['pick'](_0x452e4a['query'],_0x957dc3[_0x90f5('0x32')]));if(_0x452e4a['query'][_0x90f5('0x3a')]){_0x335496['where']=_[_0x90f5('0x3b')](_0x335496[_0x90f5('0x3c')],{'$or':_['map'](_0xb7497b,function(_0x4e9c32){if(_0x4e9c32[_0x90f5('0x2e')]!==_0x90f5('0x3d')){var _0x298380={};_0x298380[_0x4e9c32[_0x90f5('0x29')]]={'$like':'%'+_0x452e4a['query'][_0x90f5('0x3a')]+'%'};return _0x298380;}})});}_0x335496=_[_0x90f5('0x3b')]({},_0x335496,_0x452e4a['options']);var _0x138aff={'where':_0x335496[_0x90f5('0x3c')]};return db[_0x90f5('0x3e')][_0x90f5('0x1c')](_0x138aff)[_0x90f5('0x23')](function(_0x2226a6){_0x3b6ca8['count']=_0x2226a6;if(_0x452e4a[_0x90f5('0x31')]['includeAll']){_0x335496['include']=[{'all':!![]}];}return db[_0x90f5('0x3e')][_0x90f5('0x3f')](_0x335496);})[_0x90f5('0x23')](function(_0x521f24){_0x3b6ca8[_0x90f5('0x40')]=_0x521f24;return _0x3b6ca8;})[_0x90f5('0x23')](respondWithFilteredResult(_0x13c9b1,_0x335496))[_0x90f5('0x41')](handleError(_0x13c9b1,null));};exports[_0x90f5('0x42')]=function(_0x5325d0,_0x38dffb){var _0x1b6032={'raw':![],'where':{'id':_0x5325d0[_0x90f5('0x43')]['id']}},_0x413d40={};_0x413d40[_0x90f5('0x34')]=_[_0x90f5('0x30')](db[_0x90f5('0x3e')][_0x90f5('0x2c')]);_0x413d40[_0x90f5('0x31')]=_[_0x90f5('0x30')](_0x5325d0[_0x90f5('0x31')]);_0x413d40['filters']=_['intersection'](_0x413d40['model'],_0x413d40[_0x90f5('0x31')]);_0x1b6032[_0x90f5('0x35')]=_[_0x90f5('0x33')](_0x413d40[_0x90f5('0x34')],qs[_0x90f5('0x36')](_0x5325d0[_0x90f5('0x31')][_0x90f5('0x36')]));_0x1b6032[_0x90f5('0x35')]=_0x1b6032[_0x90f5('0x35')]['length']?_0x1b6032[_0x90f5('0x35')]:_0x413d40[_0x90f5('0x34')];if(_0x5325d0[_0x90f5('0x31')][_0x90f5('0x44')]){_0x1b6032[_0x90f5('0x45')]=[{'all':!![]}];}_0x1b6032=_['merge']({},_0x1b6032,_0x5325d0[_0x90f5('0x46')]);return db[_0x90f5('0x3e')]['find'](_0x1b6032)[_0x90f5('0x23')](handleEntityNotFound(_0x38dffb,null))[_0x90f5('0x23')](respondWithResult(_0x38dffb,null))[_0x90f5('0x41')](handleError(_0x38dffb,null));};exports[_0x90f5('0x47')]=function(_0x72099f,_0x299533){return db[_0x90f5('0x3e')][_0x90f5('0x47')](_0x72099f[_0x90f5('0x48')],{})[_0x90f5('0x23')](function(_0x5417e9){var _0x1e3362=_0x72099f[_0x90f5('0x49')][_0x90f5('0x4a')]({'plain':!![]});if(!_0x1e3362)throw new Error(_0x90f5('0x4b'));if(_0x1e3362[_0x90f5('0x4c')]===_0x90f5('0x49')){var _0x11f71e=_0x5417e9[_0x90f5('0x4a')]({'plain':!![]});var _0x142a62='Projects';return db[_0x90f5('0x4d')][_0x90f5('0x4e')]({'where':{'name':_0x142a62,'userProfileId':_0x1e3362[_0x90f5('0x4f')]},'raw':!![]})[_0x90f5('0x23')](function(_0x29daa3){if(_0x29daa3&&_0x29daa3[_0x90f5('0x50')]===0x0){return db[_0x90f5('0x26')][_0x90f5('0x47')]({'name':_0x11f71e[_0x90f5('0x29')],'resourceId':_0x11f71e['id'],'type':_0x29daa3[_0x90f5('0x29')],'sectionId':_0x29daa3['id']},{})['then'](function(){return _0x5417e9;});}else{return _0x5417e9;}})['catch'](function(_0xe4ddc9){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xe4ddc9);throw _0xe4ddc9;});}return _0x5417e9;})[_0x90f5('0x23')](respondWithResult(_0x299533,0xc9))['catch'](handleError(_0x299533,null));};exports[_0x90f5('0x51')]=function(_0x2d1484,_0x82fe1d){var _0x39fa3c={'where':{'id':_0x2d1484[_0x90f5('0x43')]['id']}},_0x15f38b={};_0x15f38b[_0x90f5('0x34')]=_[_0x90f5('0x30')](db[_0x90f5('0x3e')][_0x90f5('0x2c')]);_0x39fa3c[_0x90f5('0x35')]=_[_0x90f5('0x33')](_0x15f38b[_0x90f5('0x34')],qs[_0x90f5('0x36')](_0x2d1484[_0x90f5('0x31')][_0x90f5('0x36')]));_0x39fa3c['attributes']=_0x39fa3c['attributes'][_0x90f5('0x37')]?_0x39fa3c['attributes']:_0x15f38b['model'];if(_0x2d1484[_0x90f5('0x31')][_0x90f5('0x44')]){_0x39fa3c[_0x90f5('0x45')]=[{'all':!![]}];}_0x39fa3c=_[_0x90f5('0x3b')]({},_0x39fa3c,_0x2d1484[_0x90f5('0x46')]);return db[_0x90f5('0x3e')]['find'](_0x39fa3c)[_0x90f5('0x23')](handleEntityNotFound(_0x82fe1d,null))[_0x90f5('0x23')](function(_0x35d2e0){if(_0x35d2e0){var _0x49f95c=_0x35d2e0['get']({'plain':!![]});_0x49f95c=qs[_0x90f5('0x52')](_0x49f95c,['id',_0x90f5('0x53'),_0x90f5('0x54')]);_0x2d1484[_0x90f5('0x48')]=_[_0x90f5('0x52')](_0x2d1484['body'],['id',_0x90f5('0x53'),_0x90f5('0x54')]);return db[_0x90f5('0x3e')][_0x90f5('0x47')](_[_0x90f5('0x3b')](_0x49f95c,_0x2d1484[_0x90f5('0x48')]),{'include':_0x2d1484[_0x90f5('0x31')][_0x90f5('0x44')]?[{'all':!![]}]:undefined})[_0x90f5('0x23')](function(_0x644df5){var _0x503d8d=_0x2d1484[_0x90f5('0x49')]['get']({'plain':!![]});if(!_0x503d8d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x503d8d[_0x90f5('0x4c')]==='user'){var _0x531d93=_0x644df5[_0x90f5('0x4a')]({'plain':!![]});var _0x2f2fff=_0x90f5('0x25');return db['UserProfileSection'][_0x90f5('0x4e')]({'where':{'name':_0x2f2fff,'userProfileId':_0x503d8d[_0x90f5('0x4f')]},'raw':!![]})[_0x90f5('0x23')](function(_0x35786a){if(_0x35786a&&_0x35786a['autoAssociation']===0x0){return db['UserProfileResource'][_0x90f5('0x47')]({'name':_0x531d93['name'],'resourceId':_0x531d93['id'],'type':_0x35786a[_0x90f5('0x29')],'sectionId':_0x35786a['id']},{})[_0x90f5('0x23')](function(){return _0x644df5;});}else{return _0x644df5;}})[_0x90f5('0x41')](function(_0x1729b4){logger[_0x90f5('0x27')](_0x90f5('0x55'),_0x1729b4);throw _0x1729b4;});}return _0x644df5;});}})[_0x90f5('0x23')](respondWithResult(_0x82fe1d,0xc9))[_0x90f5('0x41')](handleError(_0x82fe1d,null));};exports['update']=function(_0x1fa0a4,_0x3a3ef9){if(_0x1fa0a4[_0x90f5('0x48')]['id']){delete _0x1fa0a4[_0x90f5('0x48')]['id'];}return db['JscriptyProject'][_0x90f5('0x4e')]({'where':{'id':_0x1fa0a4[_0x90f5('0x43')]['id']}})[_0x90f5('0x23')](handleEntityNotFound(_0x3a3ef9,null))[_0x90f5('0x23')](saveUpdates(_0x1fa0a4['body'],null))[_0x90f5('0x23')](respondWithResult(_0x3a3ef9,null))[_0x90f5('0x41')](handleError(_0x3a3ef9,null));};exports['destroy']=function(_0x1ef9f2,_0x230088){return db[_0x90f5('0x3e')][_0x90f5('0x4e')]({'where':{'id':_0x1ef9f2['params']['id']}})['then'](handleEntityNotFound(_0x230088,null))['then'](removeEntity(_0x230088,null))['catch'](handleError(_0x230088,null));};exports[_0x90f5('0x56')]=function(_0x299304,_0x6c47ea,_0x3ac859){var _0x11fb76={'raw':!![],'where':{}};var _0x1b7176={};var _0x37d906={'count':0x0,'rows':[]};return db[_0x90f5('0x3e')][_0x90f5('0x57')]({'where':{'id':_0x299304[_0x90f5('0x43')]['id']}})[_0x90f5('0x23')](handleEntityNotFound(_0x6c47ea,null))[_0x90f5('0x23')](function(_0x40589a){if(_0x40589a){_0x1b7176['model']=_[_0x90f5('0x30')](db[_0x90f5('0x58')][_0x90f5('0x2c')]);_0x1b7176[_0x90f5('0x31')]=_[_0x90f5('0x30')](_0x299304['query']);_0x1b7176[_0x90f5('0x32')]=_['intersection'](_0x1b7176[_0x90f5('0x34')],_0x1b7176['query']);_0x11fb76[_0x90f5('0x35')]=_[_0x90f5('0x33')](_0x1b7176['model'],qs[_0x90f5('0x36')](_0x299304[_0x90f5('0x31')][_0x90f5('0x36')]));_0x11fb76['attributes']=_0x11fb76[_0x90f5('0x35')]['length']?_0x11fb76[_0x90f5('0x35')]:_0x1b7176[_0x90f5('0x34')];if(!_0x299304[_0x90f5('0x31')][_0x90f5('0x59')](_0x90f5('0x38'))){_0x11fb76[_0x90f5('0x1e')]=qs['limit'](_0x299304[_0x90f5('0x31')]['limit']);_0x11fb76['offset']=qs[_0x90f5('0x1d')](_0x299304[_0x90f5('0x31')][_0x90f5('0x1d')]);}_0x11fb76[_0x90f5('0x39')]=qs[_0x90f5('0x5a')](_0x299304[_0x90f5('0x31')][_0x90f5('0x5a')]);_0x11fb76['where']=qs[_0x90f5('0x32')](_[_0x90f5('0x5b')](_0x299304[_0x90f5('0x31')],_0x1b7176[_0x90f5('0x32')]));_0x11fb76['where']['ProjectId']=_0x40589a['id'];if(_0x299304[_0x90f5('0x31')][_0x90f5('0x3a')]){_0x11fb76[_0x90f5('0x3c')]=_[_0x90f5('0x3b')](_0x11fb76['where'],{'$or':_['map'](_0x11fb76[_0x90f5('0x35')],function(_0x9714c4){var _0x260afd={};_0x260afd[_0x9714c4]={'$like':'%'+_0x299304[_0x90f5('0x31')][_0x90f5('0x3a')]+'%'};return _0x260afd;})});}_0x11fb76=_[_0x90f5('0x3b')]({},_0x11fb76,_0x299304['options']);return db['JscriptySessionReport'][_0x90f5('0x1c')]({'where':_0x11fb76[_0x90f5('0x3c')]})[_0x90f5('0x23')](function(_0x4b04a1){_0x37d906['count']=_0x4b04a1;if(_0x299304[_0x90f5('0x31')]['includeAll']){_0x11fb76[_0x90f5('0x45')]=[{'all':!![]}];}return db['JscriptySessionReport'][_0x90f5('0x3f')](_0x11fb76);})[_0x90f5('0x23')](function(_0x597bb9){_0x37d906[_0x90f5('0x40')]=_0x597bb9;return _0x37d906;});}})[_0x90f5('0x23')](respondWithFilteredResult(_0x6c47ea,_0x11fb76))[_0x90f5('0x41')](handleError(_0x6c47ea,null));};exports[_0x90f5('0x5c')]=function(_0x5b0fef,_0x16b966,_0x5d72f3){var _0x12e37c={'raw':!![],'where':{}};var _0x2d00be={};var _0x2f1119={'count':0x0,'rows':[]};return db['JscriptyProject'][_0x90f5('0x57')]({'where':{'id':_0x5b0fef[_0x90f5('0x43')]['id']}})[_0x90f5('0x23')](handleEntityNotFound(_0x16b966,null))[_0x90f5('0x23')](function(_0x2a1492){if(_0x2a1492){_0x2d00be[_0x90f5('0x34')]=_[_0x90f5('0x30')](db['JscriptyAnswerReport'][_0x90f5('0x2c')]);_0x2d00be[_0x90f5('0x31')]=_[_0x90f5('0x30')](_0x5b0fef['query']);_0x2d00be[_0x90f5('0x32')]=_[_0x90f5('0x33')](_0x2d00be[_0x90f5('0x34')],_0x2d00be[_0x90f5('0x31')]);_0x12e37c[_0x90f5('0x35')]=_[_0x90f5('0x33')](_0x2d00be[_0x90f5('0x34')],qs[_0x90f5('0x36')](_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x36')]));_0x12e37c['attributes']=_0x12e37c[_0x90f5('0x35')][_0x90f5('0x37')]?_0x12e37c[_0x90f5('0x35')]:_0x2d00be[_0x90f5('0x34')];if(!_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x59')](_0x90f5('0x38'))){_0x12e37c[_0x90f5('0x1e')]=qs[_0x90f5('0x1e')](_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x1e')]);_0x12e37c[_0x90f5('0x1d')]=qs[_0x90f5('0x1d')](_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x1d')]);}_0x12e37c[_0x90f5('0x39')]=qs[_0x90f5('0x5a')](_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x5a')]);_0x12e37c[_0x90f5('0x3c')]=qs[_0x90f5('0x32')](_[_0x90f5('0x5b')](_0x5b0fef[_0x90f5('0x31')],_0x2d00be['filters']));_0x12e37c[_0x90f5('0x3c')]['ProjectId']=_0x2a1492['id'];if(_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x3a')]){_0x12e37c['where']=_[_0x90f5('0x3b')](_0x12e37c[_0x90f5('0x3c')],{'$or':_[_0x90f5('0x2b')](_0x12e37c['attributes'],function(_0x3ea600){var _0x5a6017={};_0x5a6017[_0x3ea600]={'$like':'%'+_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x3a')]+'%'};return _0x5a6017;})});}_0x12e37c=_[_0x90f5('0x3b')]({},_0x12e37c,_0x5b0fef[_0x90f5('0x46')]);return db[_0x90f5('0x5d')]['count']({'where':_0x12e37c['where']})[_0x90f5('0x23')](function(_0x260037){_0x2f1119[_0x90f5('0x1c')]=_0x260037;if(_0x5b0fef[_0x90f5('0x31')][_0x90f5('0x44')]){_0x12e37c[_0x90f5('0x45')]=[{'all':!![]}];}return db[_0x90f5('0x5d')][_0x90f5('0x3f')](_0x12e37c);})[_0x90f5('0x23')](function(_0x20184d){_0x2f1119[_0x90f5('0x40')]=_0x20184d;return _0x2f1119;});}})[_0x90f5('0x23')](respondWithFilteredResult(_0x16b966,_0x12e37c))[_0x90f5('0x41')](handleError(_0x16b966,null));};function char(_0x2d49b9){return _0x90f5('0x5e')===typeof _0x2d49b9?String['fromCharCode'][_0x90f5('0x20')](null,arguments):_0x2d49b9;}function needsEncapsulation(_0x19f633){return!!_0x19f633&&(_0x19f633[_0x90f5('0x5f')]()[_0x90f5('0x60')](char(0xd))>=0x0||_0x19f633['toString']()[_0x90f5('0x60')](char(0xa))>=0x0||_0x19f633[_0x90f5('0x5f')]()[_0x90f5('0x60')](char(0x2c))>=0x0||_0x19f633['toString']()[_0x90f5('0x60')](char(0x22))>=0x0);}function encapsulate(_0x34497e){var _0x24c9d8=char(0x22),_0x3dd947='\x5c'+char(0x22),_0x14c2f3=_0x34497e[_0x90f5('0x5f')]()['replace'](new RegExp(_0x24c9d8,'g'),_0x3dd947);return _0x24c9d8+_0x14c2f3+_0x24c9d8;}exports[_0x90f5('0x61')]=function(_0x5c47c5,_0x6eeea4,_0x3df13f){var _0x12a4e,_0x1ee8ee;var _0x1a6659={'where':{'ProjectId':_0x5c47c5[_0x90f5('0x43')]['id']}};if(_0x5c47c5[_0x90f5('0x31')][_0x90f5('0x62')]){_0x1a6659[_0x90f5('0x3c')][_0x90f5('0x63')]=JSON[_0x90f5('0x64')](_0x5c47c5[_0x90f5('0x31')][_0x90f5('0x62')]);}return db[_0x90f5('0x58')][_0x90f5('0x3f')](_0x1a6659)[_0x90f5('0x23')](handleEntityNotFound(_0x6eeea4,null))[_0x90f5('0x23')](function(_0x1f1721){if(_0x1f1721){_0x12a4e=_0x1f1721;return db['JscriptyQuestionReport'][_0x90f5('0x3f')]({'where':{'SessionId':{'$in':_['map'](_0x12a4e,'id')},'ProjectId':_0x5c47c5['params']['id']},'order':'-createdAt'});}})[_0x90f5('0x23')](handleEntityNotFound(_0x6eeea4,null))[_0x90f5('0x23')](function(_0xd87b66){if(_0xd87b66){_0x1ee8ee=_0xd87b66;var _0x4d95ac={};for(var _0x1bd2ae=0x0,_0x54f43b=_0x1ee8ee['length'];_0x1bd2ae<_0x54f43b;_0x1bd2ae++){if(!_0x4d95ac[_0x90f5('0x59')](_0x1ee8ee[_0x1bd2ae][_0x90f5('0x65')])){_0x4d95ac[_0x1ee8ee[_0x1bd2ae]['questionId']]=needsEncapsulation(_0x1ee8ee[_0x1bd2ae][_0x90f5('0x66')])?encapsulate(_0x1ee8ee[_0x1bd2ae][_0x90f5('0x66')]):_0x1ee8ee[_0x1bd2ae][_0x90f5('0x66')];}}var _0x23bfbc=[],_0x125bb7={};for(var _0x4b4331=0x0,_0x2fd380=_0x12a4e[_0x90f5('0x37')];_0x4b4331<_0x2fd380;_0x4b4331++){_0x125bb7={'ProjectId':_0x5c47c5[_0x90f5('0x43')]['id'],'SessionId':_0x12a4e[_0x4b4331]['id'],'StartTime':moment(_0x12a4e[_0x4b4331][_0x90f5('0x63')])[_0x90f5('0x67')](_0x90f5('0x68'))};for(var _0x3f554e=0x0,_0x5eb593=_0x1ee8ee[_0x90f5('0x37')];_0x3f554e<_0x5eb593;_0x3f554e++){if(_0x1ee8ee[_0x3f554e]['SessionId']==_0x12a4e[_0x4b4331]['id']&&_0x4d95ac[_0x90f5('0x59')](_0x1ee8ee[_0x3f554e][_0x90f5('0x65')])){_0x125bb7[_0x4d95ac[_0x1ee8ee[_0x3f554e][_0x90f5('0x65')]]]=_0x1ee8ee[_0x3f554e]['answer'];}}for(var _0x22af19 in _0x4d95ac){if(!_0x125bb7[_0x90f5('0x59')](_0x4d95ac[_0x22af19])){_0x125bb7[_0x4d95ac[_0x22af19]]=null;}}_0x23bfbc[_0x90f5('0x69')](_0x125bb7);}return _0x23bfbc;}})[_0x90f5('0x23')](function(_0x23a048){if(!_[_0x90f5('0x6a')](_0x23a048)){var _0x28c4cd=toCsv(_0x23a048);var _0x5b1c66=Date[_0x90f5('0x6b')]();fs['writeFileSync'](util[_0x90f5('0x67')](_0x90f5('0x6c'),_0x5c47c5['params']['id'],_0x5b1c66),_0x28c4cd);_0x6eeea4[_0x90f5('0x6d')](_0x90f5('0x6e'),'attachment;\x20filename='+util['format'](_0x90f5('0x6f'),_0x5c47c5[_0x90f5('0x43')]['id'],_0x5b1c66));_0x6eeea4['setHeader'](_0x90f5('0x70'),_0x90f5('0x71'));return _0x6eeea4[_0x90f5('0x72')](util[_0x90f5('0x67')](_0x90f5('0x6c'),_0x5c47c5['params']['id'],_0x5b1c66));}else{return _0x6eeea4[_0x90f5('0x73')](0xcc);}})[_0x90f5('0x41')](handleError(_0x6eeea4,null));};