Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (R.isNil(rawCheckForm)) {
return this.updateReceivedCheckWithMarkingError(validatedCheck, 'associated checkForm could not be found by checkCode')
}
let checkForm: any
try {
checkForm = JSON.parse(rawCheckForm)
} catch (error) {
logger.error(error)
return this.updateReceivedCheckWithMarkingError(validatedCheck, 'associated checkForm data is not valid JSON')
}
if (!RA.isArray(checkForm) || RA.isEmptyArray(checkForm)) {
return this.updateReceivedCheckWithMarkingError(validatedCheck, 'check form data is either empty or not an array')
}
const toReturn: MarkingData = {
answers: parsedAnswersJson,
formQuestions: checkForm,
results: []
}
return toReturn
}
if (R.isNil(rawCheckForm)) {
await this.updateReceivedCheckWithMarkingError(validatedCheck, 'associated checkForm could not be found by checkCode')
return
}
let checkForm: any
try {
checkForm = JSON.parse(rawCheckForm)
} catch (error) {
await this.updateReceivedCheckWithMarkingError(validatedCheck, 'associated checkForm data is not valid JSON')
return
}
if (!RA.isArray(checkForm) || RA.isEmptyArray(checkForm)) {
await this.updateReceivedCheckWithMarkingError(validatedCheck, 'check form data is either empty or not an array')
return
}
const toReturn: MarkingData = {
answers: parsedAnswersJson,
formQuestions: checkForm,
results: []
}
return toReturn
}
private findValidatedCheck (receivedCheckRef: Array): ReceivedCheckTableEntity {
if (RA.isEmptyArray(receivedCheckRef)) {
throw new Error('received check reference is empty')
}
return receivedCheckRef[0]
}
private findValidatedCheck (receivedCheckRef: Array): ValidatedCheck {
if (RA.isEmptyArray(receivedCheckRef)) {
throw new Error('received check reference is empty')
}
return receivedCheckRef[0]
}
private validateCheckStructure (check: object) {
const errorMessagePrefix = 'submitted check is missing the following properties:'
const missingProperties: string[] = []
for (let index = 0; index < requiredSubmittedCheckProperties.length; index++) {
const propertyName = requiredSubmittedCheckProperties[index]
if (!check.hasOwnProperty(propertyName)) {
missingProperties.push(propertyName)
}
}
const missingPropertyNames = missingProperties.join()
if (!RA.isEmptyArray(missingProperties)) {
throw new Error(`${errorMessagePrefix} ${missingPropertyNames}`)
}
}
}