diff --git a/azure-pipelines-eu.yml b/azure-pipelines-eu.yml index 39b12b1b5..3b6c4c0b6 100644 --- a/azure-pipelines-eu.yml +++ b/azure-pipelines-eu.yml @@ -115,7 +115,6 @@ stages: inputs: targetType: 'inline' script: | - cd /home/azureuser/azagent/_work/2/japp pm2 restart index sudo systemctl restart nginx diff --git a/backend/modules/registration/controller.js b/backend/modules/registration/controller.js index c355ca616..9f7152855 100644 --- a/backend/modules/registration/controller.js +++ b/backend/modules/registration/controller.js @@ -295,45 +295,71 @@ controller.updateTravelGrantStatus = (user, event, status) => { }) } -controller.getRegistrationsForEvent = eventId => { +controller.getRegistrationsForEvent = (eventId, getFullStrings = false) => { return Registration.find({ event: eventId, }).then(registrations => { /** Do some minor optimisation here to cut down on size */ + console.log('Registrations', registrations) return registrations.map(document => { const reg = document.toObject() - reg.answers = _.mapValues(reg.answers, (answer, field) => { - const fieldType = RegistrationFields.getFieldType(field) - if (answer === null) { - console.log('Null answer in ', field) - } - switch (fieldType) { - case FieldTypes.LONG_TEXT.id: - if (answer && answer.length > 10) { - return `${answer.slice(0, 10)}...` - } - return answer - default: { - if ( - answer && - typeof answer === 'object' && - !Array.isArray(answer) && - Object.keys(answer).length > 0 - ) { - return _.mapValues(answer, subAnswer => { - if ( - typeof subAnswer === 'string' && - subAnswer.length > 50 - ) { - return subAnswer.slice(0, 10) - } - return subAnswer - }) + if (!getFullStrings) { + reg.answers = _.mapValues(reg.answers, (answer, field) => { + const fieldType = RegistrationFields.getFieldType(field) + if (answer === null) { + console.log('Null answer in ', field) + } + switch (fieldType) { + case FieldTypes.LONG_TEXT.id: + if (answer && answer.length > 10) { + return `${answer.slice(0, 10)}...` + } + return answer + default: { + if (field === 'CustomAnswers') { + answer = answer.map(customAnswer => { + if ( + typeof customAnswer.value === + 'string' && + customAnswer.value.length > 20 + ) { + customAnswer.value = `${customAnswer.value.slice( + 0, + 10, + )}...` + } + return customAnswer + }) + } + // TODO This code seems to be returning a value tht is not assigned to anything, it can be removed + // else if ( + // answer && + // typeof answer === 'object' && + // !Array.isArray(answer) && + // Object.keys(answer).length > 0 + // ) { + // console.log('answer begin inner mapValues') + // console.log(answer) + // console.log(Object.keys(answer)) + // console.log(Object.values(answer)) + // return _.mapValues(answer, subAnswer => { + // console.log('answer for inner mapValues') + // console.log(answer) + // console.log(subAnswer) + // if ( + // typeof subAnswer === 'string' && + // subAnswer.length > 50 + // ) { + // return subAnswer.slice(0, 10) + // } + // return subAnswer + // }) + // } + return answer } - return answer } - } - }) + }) + } return reg }) }) @@ -549,7 +575,7 @@ controller.addGavelLoginToRegistrations = async (eventId, gavelData) => { console.log('Registrations found', registrations.length) console.log('Registrations data', registrations) const registrationCount = registrations.length - + console.log( 'Modified counts, updated/total', updateCount, diff --git a/backend/modules/registration/routes.js b/backend/modules/registration/routes.js index 5706d9e93..0a0948969 100644 --- a/backend/modules/registration/routes.js +++ b/backend/modules/registration/routes.js @@ -144,9 +144,17 @@ const editRegistration = asyncHandler(async (req, res) => { }) const getRegistrationsForEvent = asyncHandler(async (req, res) => { - const registrations = await RegistrationController.getRegistrationsForEvent( - req.event._id.toString(), - ) + let registrations + if (req.query.getFullStrings) { + registrations = await RegistrationController.getRegistrationsForEvent( + req.event._id.toString(), + req.query.getFullStrings, + ) + } else { + registrations = await RegistrationController.getRegistrationsForEvent( + req.event._id.toString(), + ) + } return res.status(200).json(registrations) }) diff --git a/frontend/src/components/tables/AttendeeTable/index.js b/frontend/src/components/tables/AttendeeTable/index.js index b2679f526..049f2f1cf 100644 --- a/frontend/src/components/tables/AttendeeTable/index.js +++ b/frontend/src/components/tables/AttendeeTable/index.js @@ -72,13 +72,22 @@ export default ({ ) // TODO move somewhere else const skipArray = ['_id', '__v', 'section', 'key', 'id', 'checklist'] + const stringEscapeArray = [ + 'firstName', + 'lastName', + 'motivation', + 'headline', + 'cityOfResidence', + 'biography', + 'cityOfTravel', + ] function flattenObject(ob) { let toReturn = {} for (let i in ob) { if (!ob.hasOwnProperty(i) || skipArray.some(val => val === i)) continue - if (i === 'firstName' || i === 'lastName') { + if (stringEscapeArray.some(val => val === i)) { toReturn[i] = ob[i].replace(/"/g, '""') continue } else if (typeof ob[i] === 'object' && ob[i] !== null) { @@ -295,6 +304,7 @@ export default ({ color: 'inherit', }} data={selected.map(item => { + console.log(item.original) const returnObject = { ...flattenObject(item.original), registrationId: item.original._id, diff --git a/frontend/src/components/tables/ProjectsTable/index.js b/frontend/src/components/tables/ProjectsTable/index.js index 37ef19a6b..cfb7ecf71 100644 --- a/frontend/src/components/tables/ProjectsTable/index.js +++ b/frontend/src/components/tables/ProjectsTable/index.js @@ -14,13 +14,14 @@ const ProjectsTable = ({ projects }) => { const event = useSelector(OrganiserSelectors.event) const skipArray = ['_id', '__v', 'id', 'key', 'section'] + const stringEscapeArray = ['description', 'name', 'punchline'] const flattenObject = ob => { let toReturn = {} for (let i in ob) { if (!ob.hasOwnProperty(i) || skipArray.some(val => val === i)) continue - if (i === 'description' || i === 'name' || i === 'punchline') { + if (stringEscapeArray.some(val => val === i)) { toReturn[i] = ob[i].replace(/"/g, '""') continue } else if (typeof ob[i] === 'object' && ob[i] !== null) { diff --git a/frontend/src/pages/_dashboard/renderDashboard/organiser/participants/index.js b/frontend/src/pages/_dashboard/renderDashboard/organiser/participants/index.js index de34b94aa..5f0c9c14f 100644 --- a/frontend/src/pages/_dashboard/renderDashboard/organiser/participants/index.js +++ b/frontend/src/pages/_dashboard/renderDashboard/organiser/participants/index.js @@ -22,7 +22,9 @@ export default () => { useEffect(() => { if (event) { - dispatch(OrganiserActions.updateRegistrationsForEvent(event.slug)) + dispatch( + OrganiserActions.updateRegistrationsForEvent(event.slug, true), + ) dispatch(OrganiserActions.updateTeamsForEvent(event.slug)) } }, [event, location]) diff --git a/frontend/src/redux/organiser/actions.js b/frontend/src/redux/organiser/actions.js index 4b29b08a0..65783dee3 100644 --- a/frontend/src/redux/organiser/actions.js +++ b/frontend/src/redux/organiser/actions.js @@ -57,7 +57,6 @@ export const updateEventStats = slug => async (dispatch, getState) => { /** Update event organisers with loading/error data */ export const updateOrganisersForEvent = (owner, organisers) => async (dispatch, getState) => { - const userIds = [owner].concat(organisers) dispatch({ @@ -107,18 +106,18 @@ export const addOrganiserToEvent = /** Update event recruiters with loading/error data */ export const updateRecruitersForEvent = - (recruiters) => async (dispatch, getState) => { + recruiters => async (dispatch, getState) => { const idToken = AuthSelectors.getIdToken(getState()) const userIds = recruiters?.map(rec => { return rec.recruiterId }) - dispatch({ type: ActionTypes.UPDATE_EVENT_RECRUITERS, promise: UserProfilesService.getPublicUserProfiles(userIds), meta: { - onFailure: e => console.log('Error updating recruiters for this event', e), + onFailure: e => + console.log('Error updating recruiters for this event', e), }, }) } @@ -158,7 +157,7 @@ export const removeRecruiterFromEvent = /** Update event registrations with loading/error data */ export const updateRegistrationsForEvent = - slug => async (dispatch, getState) => { + (slug, getFullStrings) => async (dispatch, getState) => { const idToken = AuthSelectors.getIdToken(getState()) if (!slug) return @@ -168,6 +167,7 @@ export const updateRegistrationsForEvent = promise: RegistrationsService.getRegistrationsForEvent( idToken, slug, + getFullStrings, ), meta: { onFailure: e => console.log('Error updating registrations', e), diff --git a/frontend/src/services/registrations.js b/frontend/src/services/registrations.js index 36f0f019a..5ac53fff7 100644 --- a/frontend/src/services/registrations.js +++ b/frontend/src/services/registrations.js @@ -64,8 +64,17 @@ RegistrationsService.cancelRegistration = (idToken, slug) => { /** Get all registrations for event * GET /:slug/all */ -RegistrationsService.getRegistrationsForEvent = (idToken, slug) => { - return _axios.get(`${BASE_ROUTE}/${slug}/all`, config(idToken)) +RegistrationsService.getRegistrationsForEvent = ( + idToken, + slug, + getFullStrings, +) => { + return _axios.get( + `${BASE_ROUTE}/${slug}/all${ + getFullStrings ? '?getFullStrings=true' : '' + }`, + config(idToken), + ) } /** Edit registrations in bulk