admin resolver

- use entity instead of repository
- include deleted users in our query for pending transactions
- throw an error when trying to add or confirm a pending transaction for a deleted user
This commit is contained in:
Ulf Gebhardt 2022-02-18 12:44:35 +01:00
parent 185c38c12a
commit 4a51231bf9
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9

View File

@ -23,6 +23,7 @@ import { calculateDecay } from '../../util/decay'
import { AdminPendingCreation } from '@entity/AdminPendingCreation'
import { hasElopageBuys } from '../../util/hasElopageBuys'
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
import { User } from '@entity/User'
// const EMAIL_OPT_IN_REGISTER = 1
// const EMAIL_OPT_UNKNOWN = 3 // elopage?
@ -82,8 +83,10 @@ export class AdminResolver {
async createPendingCreation(
@Args() { email, amount, memo, creationDate, moderator }: CreatePendingCreationArgs,
): Promise<number[]> {
const userRepository = getCustomRepository(UserRepository)
const user = await userRepository.findByEmail(email)
const user = await User.findOne({ email })
if (!user) {
throw new Error(`Could not find user with email: ${email}`)
}
if (!user.emailChecked) {
throw new Error('Creation could not be saved, Email is not activated')
}
@ -134,8 +137,13 @@ export class AdminResolver {
async updatePendingCreation(
@Args() { id, email, amount, memo, creationDate, moderator }: UpdatePendingCreationArgs,
): Promise<UpdatePendingCreation> {
const userRepository = getCustomRepository(UserRepository)
const user = await userRepository.findByEmail(email)
const user = await User.findOne({ email }, { withDeleted: true })
if (!user) {
throw new Error(`Could not find user with email: ${email}`)
}
if (user.deletedAt) {
throw new Error(`User was deleted (${email})`)
}
const pendingCreationToUpdate = await AdminPendingCreation.findOneOrFail({ id })