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 {
|
return {
|
||||||
radioSelected: '',
|
radioSelected: '',
|
||||||
text: !this.creationUserData.memo ? '' : this.creationUserData.memo,
|
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,
|
rangeMin: 0,
|
||||||
rangeMax: 1000,
|
rangeMax: 1000,
|
||||||
currentMonth: {
|
currentMonth: {
|
||||||
|
|||||||
@ -186,7 +186,7 @@ export default {
|
|||||||
throw new Error('Something went wrong')
|
throw new Error('Something went wrong')
|
||||||
}
|
}
|
||||||
this.selectedOpenCreationAmount[this.createdIndex] =
|
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]
|
this.rangeMax = this.selectedOpenCreationAmount[this.createdIndex]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -194,7 +194,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
radioSelected: '',
|
radioSelected: '',
|
||||||
text: !this.creationUserData.memo ? '' : this.creationUserData.memo,
|
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,
|
rangeMin: 0,
|
||||||
rangeMax: 1000,
|
rangeMax: 1000,
|
||||||
currentMonth: {
|
currentMonth: {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export class PendingCreation {
|
|||||||
memo: string
|
memo: string
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
amount: BigInt
|
amount: number
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
moderator: number
|
moderator: number
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Resolver, Query, Arg, Args, Authorized, Mutation, Int } from 'type-graphql'
|
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 { UserAdmin } from '../model/UserAdmin'
|
||||||
import { PendingCreation } from '../model/PendingCreation'
|
import { PendingCreation } from '../model/PendingCreation'
|
||||||
import { UpdatePendingCreation } from '../model/UpdatePendingCreation'
|
import { UpdatePendingCreation } from '../model/UpdatePendingCreation'
|
||||||
@ -13,6 +13,8 @@ import UpdatePendingCreationArgs from '../arg/UpdatePendingCreationArgs'
|
|||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { Transaction } from '@entity/Transaction'
|
import { Transaction } from '@entity/Transaction'
|
||||||
import { TransactionCreation } from '@entity/TransactionCreation'
|
import { TransactionCreation } from '@entity/TransactionCreation'
|
||||||
|
import { UserTransaction } from '@entity/UserTransaction'
|
||||||
|
import { UserTransactionRepository } from '../../typeorm/repository/UserTransaction'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class AdminResolver {
|
export class AdminResolver {
|
||||||
@ -115,8 +117,11 @@ export class AdminResolver {
|
|||||||
const userRepository = getCustomRepository(UserRepository)
|
const userRepository = getCustomRepository(UserRepository)
|
||||||
const user = await userRepository.findOneOrFail({ id: pendingCreation.userId })
|
const user = await userRepository.findOneOrFail({ id: pendingCreation.userId })
|
||||||
|
|
||||||
|
const parsedAmount = Number(parseInt(pendingCreation.amount.toString()) / 10000)
|
||||||
|
// pendingCreation.amount = parsedAmount
|
||||||
const newPendingCreation = {
|
const newPendingCreation = {
|
||||||
...pendingCreation,
|
...pendingCreation,
|
||||||
|
amount: parsedAmount,
|
||||||
firstName: user.firstName,
|
firstName: user.firstName,
|
||||||
lastName: user.lastName,
|
lastName: user.lastName,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
@ -159,11 +164,36 @@ export class AdminResolver {
|
|||||||
transactionCreation.transactionId = transaction.id
|
transactionCreation.transactionId = transaction.id
|
||||||
transactionCreation.userId = pendingCreation.userId
|
transactionCreation.userId = pendingCreation.userId
|
||||||
transactionCreation.amount = parseInt(pendingCreation.amount.toString())
|
transactionCreation.amount = parseInt(pendingCreation.amount.toString())
|
||||||
// transactionCreation.targetDate = new Timestamp(pendingCreation.date.getTime())
|
transactionCreation.targetDate = pendingCreation.date
|
||||||
transactionCreation = await transactionCreationRepository.save(transactionCreation)
|
transactionCreation = await transactionCreationRepository.save(transactionCreation)
|
||||||
console.log('transactionCreation', transactionCreation)
|
console.log('transactionCreation', transactionCreation)
|
||||||
if (!transactionCreation) throw new Error('Could not create 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
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,4 @@
|
|||||||
import {
|
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm'
|
||||||
BaseEntity,
|
|
||||||
Entity,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
Column,
|
|
||||||
Timestamp,
|
|
||||||
OneToOne,
|
|
||||||
JoinColumn,
|
|
||||||
} from 'typeorm'
|
|
||||||
import { Transaction } from './Transaction'
|
import { Transaction } from './Transaction'
|
||||||
|
|
||||||
@Entity('transaction_creations')
|
@Entity('transaction_creations')
|
||||||
@ -24,7 +16,7 @@ export class TransactionCreation extends BaseEntity {
|
|||||||
amount: number
|
amount: number
|
||||||
|
|
||||||
@Column({ name: 'target_date', type: 'timestamp' })
|
@Column({ name: 'target_date', type: 'timestamp' })
|
||||||
targetDate: Timestamp
|
targetDate: Date
|
||||||
|
|
||||||
@OneToOne(() => Transaction)
|
@OneToOne(() => Transaction)
|
||||||
@JoinColumn({ name: 'transaction_id' })
|
@JoinColumn({ name: 'transaction_id' })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user