mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
correct voteSendCoins graphql schema
This commit is contained in:
parent
513ccd2524
commit
7d8b97b861
@ -33,7 +33,7 @@ export class SendCoinsClient {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const { data } = await this.client.rawRequest(voteForSendCoins, { args })
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (!data?.voteForSendCoins?.vote) {
|
||||
if (!data?.voteForSendCoins) {
|
||||
logger.warn('X-Com: voteForSendCoins without response data from endpoint', this.endpoint)
|
||||
return false
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ export const voteForSendCoins = gql`
|
||||
mutation (
|
||||
$communityReceiverIdentifier: String!
|
||||
$userReceiverIdentifier: String!
|
||||
$creationDate: Date!
|
||||
$amount: Decimal!
|
||||
$memo: String!
|
||||
$communitySenderIdentifier: String!
|
||||
@ -13,13 +14,12 @@ export const voteForSendCoins = gql`
|
||||
voteForSendCoins(
|
||||
communityReceiverIdentifier: $communityReceiverIdentifier
|
||||
userReceiverIdentifier: $userReceiverIdentifier
|
||||
creationDate: $creationDate
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
communitySenderIdentifier: $communitySenderIdentifier
|
||||
userSenderIdentifier: $userSenderIdentifier
|
||||
userSenderName: $userSenderName
|
||||
) {
|
||||
vote
|
||||
}
|
||||
)
|
||||
}
|
||||
`
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { Mutation, Query, Resolver } from 'type-graphql'
|
||||
import { Args, Mutation, Query, Resolver } from 'type-graphql'
|
||||
import { federationLogger as logger } from '@/server/logger'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
import { PendingTransaction as DbPendingTransaction } from '@entity/PendingTransaction'
|
||||
@ -16,50 +16,61 @@ import { fullName } from '@/graphql/util/fullName'
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export class SendCoinsResolver {
|
||||
@Mutation(() => Boolean)
|
||||
async voteForSendCoins(args: SendCoinsArgs): Promise<boolean> {
|
||||
async voteForSendCoins(
|
||||
@Args()
|
||||
{
|
||||
communityReceiverIdentifier,
|
||||
userReceiverIdentifier,
|
||||
creationDate,
|
||||
amount,
|
||||
memo,
|
||||
communitySenderIdentifier,
|
||||
userSenderIdentifier,
|
||||
userSenderName,
|
||||
}: SendCoinsArgs,
|
||||
): Promise<boolean> {
|
||||
logger.debug(`voteForSendCoins() via apiVersion=1_0 ...`)
|
||||
try {
|
||||
// first check if receiver community is correct
|
||||
const homeCom = await DbCommunity.findOneBy({
|
||||
communityUuid: args.communityReceiverIdentifier,
|
||||
communityUuid: communityReceiverIdentifier,
|
||||
})
|
||||
if (!homeCom) {
|
||||
throw new LogError(`voteForSendCoins with wrong communityReceiverIdentifier`)
|
||||
throw new LogError(
|
||||
`voteForSendCoins with wrong communityReceiverIdentifier`,
|
||||
communityReceiverIdentifier,
|
||||
)
|
||||
}
|
||||
// second check if receiver user exists in this community
|
||||
const receiverUser = await DbUser.findOneBy({ gradidoID: args.userReceiverIdentifier })
|
||||
const receiverUser = await DbUser.findOneBy({ gradidoID: userReceiverIdentifier })
|
||||
if (!receiverUser) {
|
||||
throw new LogError(
|
||||
`voteForSendCoins with unknown userReceiverIdentifier in the community=`,
|
||||
homeCom.name,
|
||||
)
|
||||
}
|
||||
const receiveBalance = await calculateRecepientBalance(
|
||||
receiverUser.id,
|
||||
args.amount,
|
||||
args.creationDate,
|
||||
)
|
||||
const receiveBalance = await calculateRecepientBalance(receiverUser.id, amount, creationDate)
|
||||
const pendingTx = DbPendingTransaction.create()
|
||||
pendingTx.amount = args.amount
|
||||
pendingTx.amount = amount
|
||||
pendingTx.balance = receiveBalance ? receiveBalance.balance : new Decimal(0)
|
||||
pendingTx.balanceDate = args.creationDate
|
||||
pendingTx.balanceDate = creationDate
|
||||
pendingTx.decay = receiveBalance ? receiveBalance.decay.decay : new Decimal(0)
|
||||
pendingTx.decayStart = receiveBalance ? receiveBalance.decay.start : null
|
||||
pendingTx.linkedUserCommunityUuid = args.communitySenderIdentifier
|
||||
pendingTx.linkedUserGradidoID = args.userSenderIdentifier
|
||||
pendingTx.linkedUserName = args.userSenderName
|
||||
pendingTx.memo = args.memo
|
||||
pendingTx.linkedUserCommunityUuid = communitySenderIdentifier
|
||||
pendingTx.linkedUserGradidoID = userSenderIdentifier
|
||||
pendingTx.linkedUserName = userSenderName
|
||||
pendingTx.memo = memo
|
||||
pendingTx.previous = receiveBalance ? receiveBalance.lastTransactionId : null
|
||||
pendingTx.state = PendingTransactionState.NEW
|
||||
pendingTx.typeId = TransactionTypeId.RECEIVE
|
||||
pendingTx.userCommunityUuid = args.communityReceiverIdentifier
|
||||
pendingTx.userGradidoID = args.userReceiverIdentifier
|
||||
pendingTx.userCommunityUuid = communityReceiverIdentifier
|
||||
pendingTx.userGradidoID = userReceiverIdentifier
|
||||
pendingTx.userName = fullName(receiverUser.firstName, receiverUser.lastName)
|
||||
|
||||
await DbPendingTransaction.insert(pendingTx)
|
||||
logger.debug(`voteForSendCoins()-1_0... successfull`)
|
||||
} catch (err) {
|
||||
throw new LogError(`Error in voteForSendCoins with args=`, args)
|
||||
throw new LogError(`Error in voteForSendCoins: `, err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { GraphQLScalarType, Kind } from 'graphql'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
export default new GraphQLScalarType({
|
||||
export const DecimalScalar = new GraphQLScalarType({
|
||||
name: 'Decimal',
|
||||
description: 'The `Decimal` scalar type to represent currency values',
|
||||
|
||||
@ -2,15 +2,15 @@ import { GraphQLSchema } from 'graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
|
||||
// import isAuthorized from './directive/isAuthorized'
|
||||
// import DecimalScalar from './scalar/Decimal'
|
||||
// import Decimal from 'decimal.js-light'
|
||||
import { DecimalScalar } from './scalar/Decimal'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { getApiResolvers } from './api/schema'
|
||||
|
||||
const schema = async (): Promise<GraphQLSchema> => {
|
||||
return await buildSchema({
|
||||
resolvers: [getApiResolvers()],
|
||||
// authChecker: isAuthorized,
|
||||
// scalarsMap: [{ type: Decimal, scalar: DecimalScalar }],
|
||||
scalarsMap: [{ type: Decimal, scalar: DecimalScalar }],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user