rework PR comments

This commit is contained in:
Claus-Peter Hübner 2022-09-15 02:40:59 +02:00
parent 13d79fd8b7
commit 411e03c843
6 changed files with 184 additions and 171 deletions

View File

@ -41,7 +41,7 @@ import Paginated from '@arg/Paginated'
import TransactionLinkFilters from '@arg/TransactionLinkFilters' import TransactionLinkFilters from '@arg/TransactionLinkFilters'
import { Order } from '@enum/Order' import { Order } from '@enum/Order'
import { communityUser } from '@/util/communityUser' import { communityUser } from '@/util/communityUser'
import { activationLink, printTimeDuration } from './UserResolver' import { findUserByEmail, activationLink, printTimeDuration } from './UserResolver'
import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail'
import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver' import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver'
import CONFIG from '@/config' import CONFIG from '@/config'
@ -403,6 +403,7 @@ export class AdminResolver {
throw new Error('Contribution not found for given id.') throw new Error('Contribution not found for given id.')
} }
contribution.contributionStatus = ContributionStatus.DELETED contribution.contributionStatus = ContributionStatus.DELETED
await contribution.save()
const res = await contribution.softRemove() const res = await contribution.softRemove()
return !!res return !!res
} }
@ -514,16 +515,21 @@ export class AdminResolver {
@Mutation(() => Boolean) @Mutation(() => Boolean)
async sendActivationEmail(@Arg('email') email: string): Promise<boolean> { async sendActivationEmail(@Arg('email') email: string): Promise<boolean> {
email = email.trim().toLowerCase() email = email.trim().toLowerCase()
const emailContact = await UserContact.findOne({ email: email }) // const user = await dbUser.findOne({ id: emailContact.userId })
if (!emailContact) { const user = await findUserByEmail(email)
logger.error(`Could not find UserContact with email: ${email}`)
throw new Error(`Could not find UserContact with email: ${email}`)
}
const user = await dbUser.findOne({ id: emailContact.userId })
if (!user) { if (!user) {
logger.error(`Could not find User to emailContact: ${email}`) logger.error(`Could not find User to emailContact: ${email}`)
throw new Error(`Could not find User to emailContact: ${email}`) throw new Error(`Could not find User to emailContact: ${email}`)
} }
if (user.deletedAt) {
logger.error(`User with emailContact: ${email} is deleted.`)
throw new Error(`User with emailContact: ${email} is deleted.`)
}
const emailContact = user.emailContact
if (emailContact.deletedAt) {
logger.error(`The emailContact: ${email} of htis User is deleted.`)
throw new Error(`The emailContact: ${email} of htis User is deleted.`)
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const emailSent = await sendAccountActivationEmail({ const emailSent = await sendAccountActivationEmail({

View File

@ -283,7 +283,10 @@ export class TransactionLinkResolver {
return true return true
} else { } else {
const transactionLink = await dbTransactionLink.findOneOrFail({ code }) const transactionLink = await dbTransactionLink.findOneOrFail({ code })
const linkedUser = await dbUser.findOneOrFail({ id: transactionLink.userId }) const linkedUser = await dbUser.findOneOrFail(
{ id: transactionLink.userId },
{ relations: ['user'] },
)
if (user.id === linkedUser.id) { if (user.id === linkedUser.id) {
throw new Error('Cannot redeem own transaction link.') throw new Error('Cannot redeem own transaction link.')

View File

@ -36,6 +36,7 @@ import Decimal from 'decimal.js-light'
import { BalanceResolver } from './BalanceResolver' import { BalanceResolver } from './BalanceResolver'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
import { UserContact } from '@entity/UserContact' import { UserContact } from '@entity/UserContact'
import { findUserByEmail } from './UserResolver'
export const executeTransaction = async ( export const executeTransaction = async (
amount: Decimal, amount: Decimal,
@ -294,13 +295,15 @@ export class TransactionResolver {
} }
// validate recipient user // validate recipient user
const recipientUser = await findUserByEmail(email)
/*
const emailContact = await UserContact.findOne({ email }, { withDeleted: true }) const emailContact = await UserContact.findOne({ email }, { withDeleted: true })
if (!emailContact) { if (!emailContact) {
logger.error(`Could not find UserContact with email: ${email}`) logger.error(`Could not find UserContact with email: ${email}`)
throw new Error(`Could not find UserContact with email: ${email}`) throw new Error(`Could not find UserContact with email: ${email}`)
} }
*/
const recipientUser = await dbUser.findOne({ id: emailContact.userId }) // const recipientUser = await dbUser.findOne({ id: emailContact.userId })
if (!recipientUser) { if (!recipientUser) {
logger.error(`unknown recipient to UserContact: email=${email}`) logger.error(`unknown recipient to UserContact: email=${email}`)
throw new Error('unknown recipient') throw new Error('unknown recipient')
@ -309,6 +312,7 @@ export class TransactionResolver {
logger.error(`The recipient account was deleted: recipientUser=${recipientUser}`) logger.error(`The recipient account was deleted: recipientUser=${recipientUser}`)
throw new Error('The recipient account was deleted') throw new Error('The recipient account was deleted')
} }
const emailContact = recipientUser.emailContact
if (!emailContact.emailChecked) { if (!emailContact.emailChecked) {
logger.error(`The recipient account is not activated: recipientUser=${recipientUser}`) logger.error(`The recipient account is not activated: recipientUser=${recipientUser}`)
throw new Error('The recipient account is not activated') throw new Error('The recipient account is not activated')

View File

@ -873,7 +873,7 @@ export class UserResolver {
} }
} }
async function findUserByEmail(email: string): Promise<DbUser> { export async function findUserByEmail(email: string): Promise<DbUser> {
const dbUserContact = await DbUserContact.findOneOrFail( const dbUserContact = await DbUserContact.findOneOrFail(
{ email: email }, { email: email },
{ withDeleted: true, relations: ['user'] }, { withDeleted: true, relations: ['user'] },

View File

@ -40,7 +40,7 @@ export const userFactory = async (
} }
// get last changes of user from database // get last changes of user from database
dbUser = await User.findOneOrFail({ id }, { withDeleted: true }) // dbUser = await User.findOneOrFail({ id }, { withDeleted: true })
return dbUser return dbUser
} }