Skip to content

Commit 2d21780

Browse files
Fix minor bugs (#116)
1 parent 050bbe2 commit 2d21780

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

app/lib/generators/participant-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// app/lib/generators/people-generator.js
1+
// app/lib/generators/participant-generator.js
22

33
const { faker } = require('@faker-js/faker')
44
const generateId = require('../utils/id-generator')

app/lib/utils/reading.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,13 @@ const getPreviousEvent = (events, currentEventId, wrap = true) => {
855855
// Get read for a specific user
856856
const getReadForUser = function(event, userId = null) {
857857
const currentUserId = userId || this?.ctx?.data?.currentUser?.id
858-
return event.imageReading?.reads?.[currentUserId] || null;
859-
};
858+
859+
if (!currentUserId) {
860+
return null
861+
}
862+
863+
return event.imageReading?.reads?.[currentUserId] || null
864+
}
860865

861866
/**
862867
* Get first event from an array that a user can read
@@ -865,7 +870,7 @@ const getReadForUser = function(event, userId = null) {
865870
* @param {Object} options - Additional options for eligibility
866871
* @returns {Object|null} First event user can read or null if none
867872
*/
868-
const getFirstUserReadableEvent = (events, userId = null) => {
873+
const getFirstUserReadableEvent = function(events, userId = null) {
869874
// Get user ID from context if not provided and we're in a template context
870875
const currentUserId = userId || (this?.ctx?.data?.currentUser?.id)
871876

@@ -886,8 +891,13 @@ const getFirstUserReadableEvent = (events, userId = null) => {
886891
const userHasReadEvent = function(event, userId) {
887892
const currentUserId = userId || (this?.ctx?.data?.currentUser?.id)
888893

889-
return !!getReadForUser(event, currentUserId);
890-
};
894+
if (!currentUserId) {
895+
console.warn('userHasReadEvent: No userId provided and no context available')
896+
return false
897+
}
898+
899+
return !!getReadForUser(event, currentUserId)
900+
}
891901

892902
/**
893903
* Check if current user can read an event
@@ -898,26 +908,30 @@ const userHasReadEvent = function(event, userId) {
898908
*/
899909
const canUserReadEvent = function(event, userId = null, options = {}) {
900910
const {
901-
maxReadsPerEvent = 2 // Default max reads per event
902-
} = options;
911+
maxReadsPerEvent = 2
912+
} = options
903913

904914
const currentUserId = userId || (this?.ctx?.data?.currentUser?.id)
905915

906-
const metadata = getReadingMetadata(event);
916+
if (!currentUserId) {
917+
console.warn('canUserReadEvent: No userId provided and no context available')
918+
return false
919+
}
920+
921+
const metadata = getReadingMetadata(event)
907922

908923
// If we already have enough unique readers, no more reads needed
909924
if (metadata.uniqueReaderCount >= maxReadsPerEvent) {
910-
return false;
925+
return false
911926
}
912927

913928
// User can't read if they've already read it
914929
if (userHasReadEvent(event, currentUserId)) {
915-
return false;
930+
return false
916931
}
917932

918-
// User can read if we haven't reached max readers and they haven't already read it
919-
return true;
920-
};
933+
return true
934+
}
921935

922936
/**
923937
* Check if an event has any reads

app/lib/utils/referrers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const appendReferrer = (existingReferrerChain, newUrl) => {
7575
if (!newUrl) return existingReferrerChain
7676
if (!existingReferrerChain) return newUrl
7777

78-
const chain = parseReferrerChain(existingReferrer)
78+
const chain = parseReferrerChain(existingReferrerChain)
7979
chain.push(newUrl)
8080
return chain.join(',')
8181
}

app/routes/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ module.exports = router => {
341341
if (mammogram.dateType === 'dateKnown' && mammogram.dateTaken) {
342342
const date = mammogram.dateTaken
343343
if (date.year && date.month && date.day) {
344-
const mammogramDate = dayjs(`${date.year}-${date.month}-${date.day}`)
344+
const mammogramDate = dayjs(`${date.year}-${String(date.month).padStart(2, '0')}-${String(date.day).padStart(2, '0')}`)
345345
return mammogramDate.isAfter(sixMonthsAgo)
346346
}
347347
} else if (mammogram.dateType === 'approximateDate' && mammogram.approximateDate) {
@@ -420,7 +420,7 @@ module.exports = router => {
420420
else if (['Less than 3 months', '3 months to a year', '1 to 3 years', 'Over 3 years'].includes(symptomTemp.dateType)) {
421421
symptom.approximateDuration = symptomTemp.dateType
422422
}
423-
else if (symptomTemp.dateTtype === 'notSure') {
423+
else if (symptomTemp.dateType === 'notSure') {
424424
delete symptom.approximateDuration
425425
}
426426

0 commit comments

Comments
 (0)