mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
send emails after x-com-tx
This commit is contained in:
parent
5a6cb94bb3
commit
bb88048a25
@ -20,4 +20,7 @@ export class SendCoinsResult {
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
recipAlias: string | null
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
recipEmail: string | null
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ import { fullName } from '../../util/utilities'
|
||||
import { settlePendingSenderTransaction } from './settlePendingSenderTransaction'
|
||||
import { storeForeignUser } from './storeForeignUser'
|
||||
import { storeLinkAsRedeemed } from './storeLinkAsRedeemed'
|
||||
import { sendTransactionLinkRedeemedEmail, sendTransactionReceivedEmail } from '../../emails'
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.graphql.resolver.util.processXComSendCoins.${method}`)
|
||||
@ -167,6 +168,34 @@ export async function processXComCompleteTransaction(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await sendTransactionReceivedEmail({
|
||||
firstName: foreignUser.firstName,
|
||||
lastName: foreignUser.lastName,
|
||||
email: foreignUser.emailContact.email,
|
||||
language: foreignUser.language,
|
||||
memo,
|
||||
senderFirstName: senderUser.firstName,
|
||||
senderLastName: senderUser.lastName,
|
||||
senderEmail: senderUser.emailContact.email,
|
||||
transactionAmount: new Decimal(amount),
|
||||
})
|
||||
if (dbTransactionLink) {
|
||||
await sendTransactionLinkRedeemedEmail({
|
||||
firstName: senderUser.firstName,
|
||||
lastName: senderUser.lastName,
|
||||
email: senderUser.emailContact.email,
|
||||
language: senderUser.language,
|
||||
senderFirstName: foreignUser.firstName,
|
||||
senderLastName: foreignUser.lastName,
|
||||
senderEmail: foreignUser.emailContact.email,
|
||||
transactionAmount: new Decimal(amount),
|
||||
transactionMemo: memo,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (err) {
|
||||
const errmsg =
|
||||
@ -483,6 +512,7 @@ export async function processXComCommittingSendCoins(
|
||||
}
|
||||
sendCoinsResult.recipGradidoID = pendingTx.linkedUserGradidoID
|
||||
sendCoinsResult.recipAlias = recipient.recipAlias
|
||||
sendCoinsResult.recipEmail = recipient.recipEmail
|
||||
}
|
||||
} catch (err) {
|
||||
methodLogger.error(
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import { Community as DbCommunity, User as DbUser, findForeignUserByUuids } from 'database'
|
||||
import { Community as DbCommunity,
|
||||
User as DbUser,
|
||||
UserContact as DbUserContact,
|
||||
findForeignUserByUuids } from 'database'
|
||||
import { getLogger } from 'log4js'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const'
|
||||
import { SendCoinsResult } from '../../federation/client/1_0/model/SendCoinsResult'
|
||||
@ -35,16 +38,28 @@ export async function storeForeignUser(
|
||||
}
|
||||
foreignUser.gradidoID = committingResult.recipGradidoID
|
||||
foreignUser = await DbUser.save(foreignUser)
|
||||
|
||||
logger.debug('new foreignUser inserted:', foreignUser)
|
||||
let foreignUserEmail = DbUserContact.create()
|
||||
foreignUserEmail.email = committingResult.recipEmail!
|
||||
foreignUserEmail.emailChecked = true
|
||||
foreignUserEmail.user = foreignUser
|
||||
foreignUserEmail = await DbUserContact.save(foreignUserEmail)
|
||||
logger.debug('new foreignUserEmail inserted:', foreignUserEmail)
|
||||
|
||||
foreignUser.emailContact = foreignUserEmail
|
||||
foreignUser.emailId = foreignUserEmail.id
|
||||
foreignUser = await DbUser.save(foreignUser)
|
||||
|
||||
return foreignUser
|
||||
} else if (
|
||||
user.firstName !== committingResult.recipFirstName ||
|
||||
user.lastName !== committingResult.recipLastName ||
|
||||
user.alias !== committingResult.recipAlias
|
||||
user.alias !== committingResult.recipAlias ||
|
||||
user.emailContact.email !== committingResult.recipEmail
|
||||
) {
|
||||
logger.warn(
|
||||
'foreignUser still exists, but with different name or alias:',
|
||||
'foreignUser still exists, but with different name, alias or email:',
|
||||
user,
|
||||
committingResult,
|
||||
)
|
||||
@ -57,6 +72,11 @@ export async function storeForeignUser(
|
||||
if (committingResult.recipAlias !== null) {
|
||||
user.alias = committingResult.recipAlias
|
||||
}
|
||||
if (committingResult.recipEmail != null) {
|
||||
let userContact = user.emailContact
|
||||
userContact.email = committingResult.recipEmail
|
||||
user.emailContact = await DbUserContact.save(userContact)
|
||||
}
|
||||
await DbUser.save(user)
|
||||
logger.debug('update recipient successful.', user)
|
||||
return user
|
||||
|
||||
@ -128,6 +128,7 @@ export class SendCoinsResolver {
|
||||
receiverUser.firstName,
|
||||
receiverUser.lastName,
|
||||
receiverUser.alias,
|
||||
receiverUser.emailContact.email
|
||||
)
|
||||
const responseJwt = await encryptAndSign(
|
||||
responseArgs,
|
||||
|
||||
@ -8,6 +8,7 @@ export class SendCoinsResponseJwtPayloadType extends JwtPayloadType {
|
||||
recipFirstName: string | null
|
||||
recipLastName: string | null
|
||||
recipAlias: string | null
|
||||
recipEmail: string | null
|
||||
|
||||
constructor(
|
||||
handshakeID: string,
|
||||
@ -16,6 +17,7 @@ export class SendCoinsResponseJwtPayloadType extends JwtPayloadType {
|
||||
recipFirstName: string | null,
|
||||
recipLastName: string | null,
|
||||
recipAlias: string | null,
|
||||
recipEmail: string | null,
|
||||
) {
|
||||
super(handshakeID)
|
||||
this.tokentype = SendCoinsResponseJwtPayloadType.SEND_COINS_RESPONSE_TYPE
|
||||
@ -24,5 +26,6 @@ export class SendCoinsResponseJwtPayloadType extends JwtPayloadType {
|
||||
this.recipFirstName = recipFirstName
|
||||
this.recipLastName = recipLastName
|
||||
this.recipAlias = recipAlias
|
||||
this.recipEmail = recipEmail
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user