mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Added a state_user_transaction row. withdrew / 10000 from frontend.
This commit is contained in:
parent
7b3096a88b
commit
a07d34d827
@ -159,7 +159,7 @@ export default {
|
||||
return {
|
||||
radioSelected: '',
|
||||
text: !this.creationUserData.memo ? '' : this.creationUserData.memo,
|
||||
value: !this.creationUserData.amount ? 0 : this.creationUserData.amount / 10000,
|
||||
value: !this.creationUserData.amount ? 0 : this.creationUserData.amount,
|
||||
rangeMin: 0,
|
||||
rangeMax: 1000,
|
||||
currentMonth: {
|
||||
|
||||
@ -186,7 +186,7 @@ export default {
|
||||
throw new Error('Something went wrong')
|
||||
}
|
||||
this.selectedOpenCreationAmount[this.createdIndex] =
|
||||
this.creation[this.createdIndex] + this.creationUserData.amount / 10000
|
||||
this.creation[this.createdIndex] + this.creationUserData.amount
|
||||
this.rangeMax = this.selectedOpenCreationAmount[this.createdIndex]
|
||||
}
|
||||
},
|
||||
@ -194,7 +194,7 @@ export default {
|
||||
return {
|
||||
radioSelected: '',
|
||||
text: !this.creationUserData.memo ? '' : this.creationUserData.memo,
|
||||
value: !this.creationUserData.amount ? 0 : this.creationUserData.amount / 10000,
|
||||
value: !this.creationUserData.amount ? 0 : this.creationUserData.amount,
|
||||
rangeMin: 0,
|
||||
rangeMax: 1000,
|
||||
currentMonth: {
|
||||
|
||||
@ -24,7 +24,7 @@ export class PendingCreation {
|
||||
memo: string
|
||||
|
||||
@Field(() => Number)
|
||||
amount: BigInt
|
||||
amount: number
|
||||
|
||||
@Field(() => Number)
|
||||
moderator: number
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Resolver, Query, Arg, Args, Authorized, Mutation, Int } from 'type-graphql'
|
||||
import { getCustomRepository, Raw } from 'typeorm'
|
||||
import { getCustomRepository, Raw, Timestamp } from 'typeorm'
|
||||
import { UserAdmin } from '../model/UserAdmin'
|
||||
import { PendingCreation } from '../model/PendingCreation'
|
||||
import { UpdatePendingCreation } from '../model/UpdatePendingCreation'
|
||||
@ -13,6 +13,8 @@ import UpdatePendingCreationArgs from '../arg/UpdatePendingCreationArgs'
|
||||
import moment from 'moment'
|
||||
import { Transaction } from '@entity/Transaction'
|
||||
import { TransactionCreation } from '@entity/TransactionCreation'
|
||||
import { UserTransaction } from '@entity/UserTransaction'
|
||||
import { UserTransactionRepository } from '../../typeorm/repository/UserTransaction'
|
||||
|
||||
@Resolver()
|
||||
export class AdminResolver {
|
||||
@ -115,8 +117,11 @@ export class AdminResolver {
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const user = await userRepository.findOneOrFail({ id: pendingCreation.userId })
|
||||
|
||||
const parsedAmount = Number(parseInt(pendingCreation.amount.toString()) / 10000)
|
||||
// pendingCreation.amount = parsedAmount
|
||||
const newPendingCreation = {
|
||||
...pendingCreation,
|
||||
amount: parsedAmount,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
email: user.email,
|
||||
@ -159,11 +164,36 @@ export class AdminResolver {
|
||||
transactionCreation.transactionId = transaction.id
|
||||
transactionCreation.userId = pendingCreation.userId
|
||||
transactionCreation.amount = parseInt(pendingCreation.amount.toString())
|
||||
// transactionCreation.targetDate = new Timestamp(pendingCreation.date.getTime())
|
||||
transactionCreation.targetDate = pendingCreation.date
|
||||
transactionCreation = await transactionCreationRepository.save(transactionCreation)
|
||||
console.log('transactionCreation', transactionCreation)
|
||||
if (!transactionCreation) throw new Error('Could not create transactionCreation')
|
||||
|
||||
const userTransactionRepository = getCustomRepository(UserTransactionRepository)
|
||||
const lastUserTransaction = await userTransactionRepository.findLastForUser(
|
||||
pendingCreation.userId,
|
||||
)
|
||||
let newBalance = 0
|
||||
if (!lastUserTransaction) {
|
||||
newBalance = 0
|
||||
} else {
|
||||
newBalance = lastUserTransaction.balance
|
||||
}
|
||||
const newUserTransaction = new UserTransaction()
|
||||
newUserTransaction.userId = pendingCreation.userId
|
||||
newUserTransaction.transactionId = transaction.id
|
||||
newUserTransaction.transactionTypeId = transaction.transactionTypeId
|
||||
newUserTransaction.balance = Number(
|
||||
newBalance + parseInt(pendingCreation.amount.toString()) / 10000,
|
||||
)
|
||||
newUserTransaction.balanceDate = transaction.received
|
||||
|
||||
console.log(newUserTransaction)
|
||||
|
||||
await userTransactionRepository.save(newUserTransaction).catch((error) => {
|
||||
throw new Error('Error saving user transaction: ' + error)
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
import {
|
||||
BaseEntity,
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
Timestamp,
|
||||
OneToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm'
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm'
|
||||
import { Transaction } from './Transaction'
|
||||
|
||||
@Entity('transaction_creations')
|
||||
@ -24,7 +16,7 @@ export class TransactionCreation extends BaseEntity {
|
||||
amount: number
|
||||
|
||||
@Column({ name: 'target_date', type: 'timestamp' })
|
||||
targetDate: Timestamp
|
||||
targetDate: Date
|
||||
|
||||
@OneToOne(() => Transaction)
|
||||
@JoinColumn({ name: 'transaction_id' })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user