Skip to content

Commit 6e0fb58

Browse files
authored
Release/v1.4.0 [dev] (#73)
2 parents eb7bb34 + f97d768 commit 6e0fb58

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/models/activity.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,26 @@ export class ActivityEntity {
122122
const subscaleTableData = subscaleItem.subscaleTableData
123123

124124
const subscaleTableDataItem = subscaleTableData.find(({ sex, age, rawScore }) => {
125-
let reportedAge: number | null = null
125+
let reportedAge: string | null = null
126126
if (typeof ageAnswer === 'string') {
127-
reportedAge = Number(ageAnswer)
128-
} else if ('value' in ageAnswer && typeof ageAnswer.value === 'number') {
129-
reportedAge = ageAnswer.value
127+
reportedAge = ageAnswer
128+
} else if (ageAnswer && 'value' in ageAnswer && ['number', 'string'].includes(typeof ageAnswer.value)) {
129+
reportedAge = String(ageAnswer.value)
130+
}
131+
132+
const hasAgeInterval = age && typeof age === 'string' && age.includes(INTERVAL_SYMBOL)
133+
let withAge = true
134+
135+
if (age) {
136+
if (!hasAgeInterval) {
137+
withAge = String(age) === reportedAge
138+
} else {
139+
const [minAge, maxAge] = age.replace(/\s/g, '').split(INTERVAL_SYMBOL)
140+
const reportedAgeNum = Number(reportedAge)
141+
withAge = Number(minAge) <= reportedAgeNum && reportedAgeNum <= Number(maxAge)
142+
}
130143
}
131144

132-
const withAge = age === reportedAge
133145
const withSex = parseSex(sex) === String(genderAnswer?.value)
134146

135147
if (!withSex || !withAge) return false

0 commit comments

Comments
 (0)