emails resolver does not have logger in context, why?

This commit is contained in:
Moriz Wahl 2025-06-26 16:00:32 +02:00
parent 35f3840a1e
commit 269de2cf56
4 changed files with 38 additions and 19 deletions

View File

@ -62,7 +62,9 @@ export default {
try {
const { relation, user } = await writeTxResultPromise
if (!relation) {
context.logger.error('Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.')
context.logger.error(
'Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.',
)
throw new Error(
'Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.',
)
@ -72,7 +74,7 @@ export default {
context.logger.error('setVerificationBadge', error)
throw new Error(error)
} finally {
session.close()
await session.close()
}
},
@ -127,7 +129,9 @@ export default {
).records.map((record) => record.get('user'))
if (users.length !== 1) {
context.logger.error('Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.')
context.logger.error(
'Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.',
)
throw new Error(
'Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.',
)
@ -160,7 +164,7 @@ export default {
try {
return await writeTxResultPromise
} catch (error) {
context.logger.error('revokeBadge', error)
context.logger.error('revokeBadge', error)
throw new Error(error)
} finally {
session.close()

View File

@ -18,6 +18,12 @@ let user
let variables
const driver = getDriver()
const loggerErrorMock: (e) => void = jest.fn()
jest.mock('@src/logger', () => ({
error: (e) => loggerErrorMock(e),
}))
beforeAll(async () => {
await cleanDatabase()

View File

@ -7,6 +7,8 @@ import { UserInputError } from 'apollo-server'
// eslint-disable-next-line import/extensions
import Validator from 'neode/build/Services/Validator.js'
import { Context } from '@src/server'
import existingEmailAddress from './helpers/existingEmailAddress'
import generateNonce from './helpers/generateNonce'
import normalizeEmail from './helpers/normalizeEmail'
@ -36,13 +38,14 @@ export default {
},
},
Mutation: {
AddEmailAddress: async (_parent, args, context, _resolveInfo) => {
AddEmailAddress: async (_parent, args, context: Context, _resolveInfo) => {
let response
args.email = normalizeEmail(args.email)
try {
const { neode } = context
await new Validator(neode, neode.model('UnverifiedEmailAddress'), args)
} catch (e) {
// context.logger.error('must be a valid email')
throw new UserInputError('must be a valid email')
}
@ -77,11 +80,11 @@ export default {
const txResult = await writeTxResultPromise
response = txResult[0]
} finally {
session.close()
await session.close()
}
return response
},
VerifyEmailAddress: async (_parent, args, context, _resolveInfo) => {
VerifyEmailAddress: async (_parent, args, context: Context, _resolveInfo) => {
let response
const {
user: { id: userId },
@ -111,13 +114,19 @@ export default {
const txResult = await writeTxResultPromise
response = txResult[0]
} catch (e) {
if (e.code === 'Neo.ClientError.Schema.ConstraintValidationFailed')
if (e.code === 'Neo.ClientError.Schema.ConstraintValidationFailed') {
// context.logger.error('A user account with this email already exists.')
throw new UserInputError('A user account with this email already exists.')
}
context.logger.error('VerifyEmailAddress', e)
throw new Error(e)
} finally {
session.close()
await session.close()
}
if (!response) {
// context.logger.error('Invalid nonce or no email address found.')
throw new UserInputError('Invalid nonce or no email address found.')
}
if (!response) throw new UserInputError('Invalid nonce or no email address found.')
return response
},
},

View File

@ -60,7 +60,7 @@ export default {
throw new UserInputError(e.message)
}
},
blockedUsers: async (_object, _args, context, _resolveInfo) => {
blockedUsers: async (_object, _args, context: Context, _resolveInfo) => {
try {
return getBlockedUsers(context)
} catch (e) {
@ -122,7 +122,7 @@ export default {
const unmutedUser = await neode.find('User', params.id)
return unmutedUser.toJson()
},
blockUser: async (_object, args, context, _resolveInfo) => {
blockUser: async (_object, args, context: Context, _resolveInfo) => {
const { user: currentUser } = context
if (currentUser.id === args.id) return null
@ -147,10 +147,10 @@ export default {
context.logger.error('blockUser mutation', error.message)
throw new UserInputError(error.message)
} finally {
session.close()
await session.close()
}
},
unblockUser: async (_object, args, context, _resolveInfo) => {
unblockUser: async (_object, args, context: Context, _resolveInfo) => {
const { user: currentUser } = context
if (currentUser.id === args.id) return null
@ -172,10 +172,10 @@ export default {
context.logger.error('unblockUser mutation', error.message)
throw new UserInputError(error.message)
} finally {
session.close()
await session.close()
}
},
UpdateUser: async (_parent, params, context, _resolveInfo) => {
UpdateUser: async (_parent, params, context: Context, _resolveInfo) => {
const { avatar: avatarInput } = params
delete params.avatar
params.locationName = params.locationName === '' ? null : params.locationName
@ -228,7 +228,7 @@ export default {
context.logger.error('UpdateUser mutation', error.message)
throw new UserInputError(error.message)
} finally {
session.close()
await session.close()
}
},
DeleteUser: async (_object, params, context, _resolveInfo) => {
@ -297,7 +297,7 @@ export default {
session.close()
}
},
switchUserRole: async (_object, args, context, _resolveInfo) => {
switchUserRole: async (_object, args, context: Context, _resolveInfo) => {
const { role, id } = args
if (context.user.id === id) {
@ -322,7 +322,7 @@ export default {
const user = await writeTxResultPromise
return user
} finally {
session.close()
await session.close()
}
},
saveCategorySettings: async (_object, args, context, _resolveInfo) => {