Change Error message formating.

This commit is contained in:
elweyn 2022-03-15 08:19:27 +01:00
parent ce0cc2c1b7
commit 09c215bd50

View File

@ -159,11 +159,7 @@ const createEmailOptIn = async (
if (emailOptIn) { if (emailOptIn) {
const timeElapsed = Date.now() - new Date(emailOptIn.updatedAt).getTime() const timeElapsed = Date.now() - new Date(emailOptIn.updatedAt).getTime()
if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
throw new Error( throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
'email already sent less than ' +
parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) +
' minutes ago',
)
} else { } else {
emailOptIn.updatedAt = new Date() emailOptIn.updatedAt = new Date()
emailOptIn.resendCount++ emailOptIn.resendCount++
@ -192,9 +188,7 @@ const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
if (optInCode) { if (optInCode) {
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
if (timeElapsed < parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { if (timeElapsed < parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
throw new Error( throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`
)
} else { } else {
optInCode.updatedAt = new Date() optInCode.updatedAt = new Date()
optInCode.resendCount++ optInCode.resendCount++
@ -489,9 +483,7 @@ export class UserResolver {
// Code is only valid for 10minutes // Code is only valid for 10minutes
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
throw new Error( throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
'Code is older than ' + parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) + ' minutes',
)
} }
// load user // load user
@ -569,9 +561,7 @@ export class UserResolver {
// Code is only valid for 10minutes // Code is only valid for 10minutes
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) {
throw new Error( throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
'Code is older than ' + parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) + ' minutes',
)
} }
return true return true
} }