mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Model for transactions and decay
This commit is contained in:
parent
aa22d9154d
commit
873996487d
@ -33,7 +33,7 @@ export const apiGet = async (url: string): Promise<any> => {
|
||||
})
|
||||
.catch((error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('IN apiGet.ERROR: ' + JSON.stringify({ success: false, result: error }))
|
||||
console.log('IN apiGet.ERROR: ', { success: false, result: error })
|
||||
return { success: false, data: error.message }
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import { Entity, BaseEntity, Column } from 'typeorm'
|
||||
import { ObjectType, Field } from 'type-graphql'
|
||||
|
||||
@ -8,8 +6,8 @@ import { ObjectType, Field } from 'type-graphql'
|
||||
export class Balance extends BaseEntity {
|
||||
constructor(json: any) {
|
||||
super()
|
||||
this.balance = json.balance
|
||||
this.decay = json.decay
|
||||
this.balance = Number(json.balance)
|
||||
this.decay = Number(json.decay)
|
||||
this.decayDate = json.decay_date
|
||||
}
|
||||
|
||||
|
||||
30
backend/src/graphql/models/Decay.ts
Normal file
30
backend/src/graphql/models/Decay.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Entity, BaseEntity, Column } from 'typeorm'
|
||||
import { ObjectType, Field } from 'type-graphql'
|
||||
|
||||
@Entity()
|
||||
@ObjectType()
|
||||
export class Decay extends BaseEntity {
|
||||
constructor(json: any) {
|
||||
super()
|
||||
this.balance = Number(json.balance)
|
||||
this.decayStart = json.decay_start
|
||||
this.decayEnd = json.decay_end
|
||||
this.decayDuration = json.decay_duration
|
||||
}
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
balance: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
decayStart: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
decayEnd: number
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
decayDuration: string
|
||||
}
|
||||
@ -3,8 +3,100 @@ import { ObjectType, Field } from 'type-graphql'
|
||||
|
||||
@Entity()
|
||||
@ObjectType()
|
||||
export class Transaction extends BaseEntity {
|
||||
export class TransactionList extends BaseEntity {
|
||||
constructor(json: any) {
|
||||
super()
|
||||
this.gdtSum = Number(json.gdtSum)
|
||||
this.count = json.count
|
||||
this.balance = Number(json.balance)
|
||||
this.decay = Number(json.decay)
|
||||
this.decayDate = json.decay_date
|
||||
this.transactions = json.transactions
|
||||
}
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
gdtSum: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
count: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
balance: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
decay: number
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ length: 191 })
|
||||
email: string
|
||||
@Column()
|
||||
decayDate: string
|
||||
|
||||
@Field(() => [Transaction])
|
||||
transactions: Transaction[]
|
||||
}
|
||||
|
||||
@Entity()
|
||||
@ObjectType()
|
||||
export class Transaction extends BaseEntity {
|
||||
constructor(json: any) {
|
||||
super()
|
||||
this.type = json.type
|
||||
this.balance = Number(json.balance)
|
||||
this.decayStart = json.decay_start
|
||||
this.decayEnd = json.decay_end
|
||||
this.decayDuration = json.decay_duration
|
||||
this.meno = json.memo
|
||||
this.transactionId = json.transaction_id
|
||||
this.name = json.name
|
||||
this.email = json.email
|
||||
this.date = json.date
|
||||
this.decay = json.decay
|
||||
}
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
type: string
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
balance: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
decayStart: number
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
decayEnd: number
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
decayDuration: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
memo: string
|
||||
|
||||
@Field(() => Number)
|
||||
@Column()
|
||||
transactionId: number
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
email: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
date: string
|
||||
|
||||
@Field(() => Decay)
|
||||
@Column()
|
||||
decay: Decay
|
||||
}
|
||||
|
||||
16
backend/src/graphql/resolvers/BalanceResolver.ts
Normal file
16
backend/src/graphql/resolvers/BalanceResolver.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql'
|
||||
import CONFIG from '../../config'
|
||||
import { Balance } from '../models/Balance'
|
||||
import { apiGet } from '../../apis/loginAPI'
|
||||
|
||||
@Resolver()
|
||||
export class BalanceResolver {
|
||||
@Query(() => Balance)
|
||||
async balance(@Arg('sessionId') sessionId: number): Promise<Balance> {
|
||||
const result = await apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId)
|
||||
console.log(result)
|
||||
if (!result.success)
|
||||
throw new Error(result.data)
|
||||
return new Balance(result.data)
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ import CONFIG from './config'
|
||||
// TODO move to extern
|
||||
// import { BookResolver } from './graphql/resolvers/BookResolver'
|
||||
import { UserResolver } from './graphql/resolvers/UserResolver'
|
||||
import { CommunityTransactionResolver } from './graphql/resolvers/CommunityTransactionResolver'
|
||||
import { BalanceResolver } from './graphql/resolvers/BalanceResolver'
|
||||
// import { GroupResolver } from './graphql/resolvers/GroupResolver'
|
||||
// TODO implement
|
||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||
@ -16,7 +16,7 @@ import { CommunityTransactionResolver } from './graphql/resolvers/CommunityTrans
|
||||
async function main() {
|
||||
// const connection = await createConnection()
|
||||
const schema = await buildSchema({
|
||||
resolvers: [/* BookResolver , GroupResolver, */ UserResolver, CommunityTransactionResolver],
|
||||
resolvers: [UserResolver, BalanceResolver],
|
||||
})
|
||||
|
||||
// Graphiql interface
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user