Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion azure-pipelines-eu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ stages:
inputs:
targetType: 'inline'
script: |
cd /home/azureuser/azagent/_work/2/japp
pm2 restart index
sudo systemctl restart nginx

Expand Down
90 changes: 58 additions & 32 deletions backend/modules/registration/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions backend/modules/registration/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/tables/AttendeeTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/tables/ProjectsTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/redux/organiser/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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),
},
})
}
Expand Down Expand Up @@ -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
Expand All @@ -168,6 +167,7 @@ export const updateRegistrationsForEvent =
promise: RegistrationsService.getRegistrationsForEvent(
idToken,
slug,
getFullStrings,
),
meta: {
onFailure: e => console.log('Error updating registrations', e),
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/services/registrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down