fix: No Creations for Deleted Users

This commit is contained in:
Moriz Wahl 2022-02-24 11:08:30 +01:00
parent 6de3136613
commit ec143bd18f

View File

@ -263,7 +263,7 @@ export class AdminResolver {
const userIds = pendingCreations.map((p) => p.userId) const userIds = pendingCreations.map((p) => p.userId)
const userCreations = await getUserCreations(userIds) const userCreations = await getUserCreations(userIds)
const users = await User.find({ id: In(userIds) }) const users = await User.find({ where: { id: In(userIds) }, withDeleted: true })
return pendingCreations.map((pendingCreation) => { return pendingCreations.map((pendingCreation) => {
const user = users.find((u) => u.id === pendingCreation.userId) const user = users.find((u) => u.id === pendingCreation.userId)
@ -297,6 +297,9 @@ export class AdminResolver {
if (moderatorUser.id === pendingCreation.userId) if (moderatorUser.id === pendingCreation.userId)
throw new Error('Moderator can not confirm own pending creation') throw new Error('Moderator can not confirm own pending creation')
const user = await User.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true })
if (user.deletedAt) throw new Error('This user was deleted. Cannot confirm a creation.')
const creations = await getUserCreation(pendingCreation.userId, false) const creations = await getUserCreation(pendingCreation.userId, false)
if (!isCreationValid(creations, Number(pendingCreation.amount) / 10000, pendingCreation.date)) { if (!isCreationValid(creations, Number(pendingCreation.amount) / 10000, pendingCreation.date)) {
throw new Error('Creation is not valid!!') throw new Error('Creation is not valid!!')