Created
November 2, 2018 10:52
-
-
Save Aziaev/26cbb50079f57d6df4fd0c1019dd95e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const asyncValidate = (values) => { | |
if (values.lmsCourseGeneralInfo.productISBN && !ISBN_REGEXP.test(values.lmsCourseGeneralInfo.productISBN)) { | |
return sleep(100).then(() => { | |
// eslint-disable-next-line no-throw-literal | |
throw { | |
lmsCourseGeneralInfo: { | |
productISBN: VALIDATION_ERR_MESSAGE_PRODUCT_ID_FORMAT, | |
}, | |
}; | |
}); | |
} else if (values.lmsCourseGeneralInfo.productISBN) { | |
const url = getProductSearchApiUrl(); | |
const request = HTTPAsync.getRequest(url, { productIsbn: values.lmsCourseGeneralInfo.productISBN.toUpperCase() }); | |
return request | |
.then(response => { | |
if ( | |
response && | |
response.body && | |
response.body.isbn && | |
response.body.isbn.toUpperCase() !== values.lmsCourseGeneralInfo.productISBN.toUpperCase()) { | |
// eslint-disable-next-line no-throw-literal | |
throw { | |
lmsCourseGeneralInfo: { | |
productISBN: VALIDATION_ERR_MESSAGE_PRODUCT_ID_FORMAT, | |
}, | |
}; | |
} | |
}) | |
.catch(() => { | |
// eslint-disable-next-line no-throw-literal | |
throw { | |
lmsCourseGeneralInfo: { | |
productISBN: VALIDATION_ERR_MESSAGE_PRODUCT_ID_NOT_EXISTS, | |
}, | |
}; | |
}); | |
} else { | |
return sleep(100).then(() => { | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working test