Merge pull request #931 from gradido/bug_fixes_recent_changes

Bug fixes recent changes
This commit is contained in:
einhornimmond 2021-10-02 13:05:46 +02:00 committed by GitHub
commit 232e28a413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 23 deletions

View File

@ -20,23 +20,23 @@ export class BalanceResolver {
const userEntity = await userRepository.findByPubkeyHex(context.pubKey) const userEntity = await userRepository.findByPubkeyHex(context.pubKey)
const balanceEntity = await balanceRepository.findByUser(userEntity.id) const balanceEntity = await balanceRepository.findByUser(userEntity.id)
let balance: Balance
const now = new Date() const now = new Date()
if (balanceEntity) {
balance = new Balance({ // No balance found
balance: roundFloorFrom4(balanceEntity.amount), if (!balanceEntity) {
decay: roundFloorFrom4( return new Balance({
await calculateDecay(balanceEntity.amount, balanceEntity.recordDate, now),
),
decay_date: now.toString(),
})
} else {
balance = new Balance({
balance: 0, balance: 0,
decay: 0, decay: 0,
decay_date: now.toString(), decay_date: now.toString(),
}) })
} }
return balance
return new Balance({
balance: roundFloorFrom4(balanceEntity.amount),
decay: roundFloorFrom4(
await calculateDecay(balanceEntity.amount, balanceEntity.recordDate, now),
),
decay_date: now.toString(),
})
} }
} }

View File

@ -50,7 +50,7 @@ async function calculateAndAddDecayTransactions(
const transactionIndiced: dbTransaction[] = [] const transactionIndiced: dbTransaction[] = []
transactions.forEach((transaction: dbTransaction) => { transactions.forEach((transaction: dbTransaction) => {
transactionIndiced[transaction.id] = transaction transactionIndiced[transaction.id] = transaction
if (transaction.transactionTypeId === 2) { if (transaction.transactionTypeId === TransactionTypeId.SEND) {
involvedUserIds.push(transaction.transactionSendCoin.userId) involvedUserIds.push(transaction.transactionSendCoin.userId)
involvedUserIds.push(transaction.transactionSendCoin.recipiantUserId) involvedUserIds.push(transaction.transactionSendCoin.recipiantUserId)
} }
@ -97,7 +97,7 @@ async function calculateAndAddDecayTransactions(
} }
} }
// sender or receiver when user has sended money // sender or receiver when user has sent money
// group name if creation // group name if creation
// type: gesendet / empfangen / geschöpft // type: gesendet / empfangen / geschöpft
// transaktion nr / id // transaktion nr / id
@ -231,7 +231,7 @@ export class TransactionResolver {
email: userEntity.email, email: userEntity.email,
}) })
if (!resultGDTSum.success) throw new Error(resultGDTSum.data) if (!resultGDTSum.success) throw new Error(resultGDTSum.data)
transactions.gdtSum = resultGDTSum.data.sum transactions.gdtSum = resultGDTSum.data.sum || 0
// get balance // get balance
const balanceRepository = getCustomRepository(BalanceRepository) const balanceRepository = getCustomRepository(BalanceRepository)

View File

@ -4,8 +4,6 @@ import { Balance } from '../entity/Balance'
@EntityRepository(Balance) @EntityRepository(Balance)
export class BalanceRepository extends Repository<Balance> { export class BalanceRepository extends Repository<Balance> {
findByUser(userId: number): Promise<Balance | undefined> { findByUser(userId: number): Promise<Balance | undefined> {
return this.createQueryBuilder('balance') return this.createQueryBuilder('balance').where('balance.userId = :userId', { userId }).getOne()
.where('balance.userId = :userId', { userId })
.getOneOrFail()
} }
} }

View File

@ -43,11 +43,13 @@ services:
# DATABASE ############################################## # DATABASE ##############################################
######################################################## ########################################################
database: database:
# we always run on prouction here since else the service lingers # we always run on production here since else the service lingers
# feel free to change this behaviour if it seems useful # feel free to change this behaviour if it seems useful
#image: gradido/database:test_up # Due to problems with the volume caching the built files
#build: # we changed this to test build. This keeps the service running.
# target: test_up image: gradido/database:test_up
build:
target: test_up
#networks: #networks:
# - external-net # - external-net
# - internal-net # - internal-net

View File

@ -32,7 +32,7 @@ export const loginViaEmailVerificationCode = gql`
` `
export const transactionsQuery = gql` export const transactionsQuery = gql`
query($currentPage: Int = 1, $pageSize: Int = 25, $order: String = "DESC") { query($currentPage: Int = 1, $pageSize: Int = 25, $order: Order = DESC) {
transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) { transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
gdtSum gdtSum
count count