Added the Resolver that takes care about the Transactions in a Community.

This commit is contained in:
Hannes Heine 2021-07-29 07:30:00 +02:00
parent 68c0e7894d
commit 36c97b9089
4 changed files with 117 additions and 1 deletions

View File

@ -0,0 +1,50 @@
import { ObjectType, ArgsType, Field, Int, Float } from 'type-graphql'
import { Entity, BaseEntity, Column, Double } from 'typeorm'
@ArgsType()
export class TransactionInput {
@Field(() => Number)
sessionId: number
@Field(() => Number)
firstPage: number
@Field(() => Number)
items: number
@Field(() => String)
order: string
}
@ArgsType()
export class TransactionSendArgs {
@Field(() => Number)
sessionId: number
@Field(() => String)
email: string
@Field(() => Number)
amount: number
@Field(() => String)
memo: string
}
@ArgsType()
export class TransactionCreateArgs {
@Field(() => Number)
sessionId: number
@Field(() => String)
email: string
@Field(() => Number)
amount: number
@Field(() => String)
memo: string
@Field(() => Date)
targetDate: Date
}

View File

@ -0,0 +1,10 @@
import { Entity, BaseEntity, Column } from 'typeorm'
import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType()
export class Transaction extends BaseEntity {
@Field(() => String)
@Column({ length: 191 })
email: string
}

View File

@ -0,0 +1,55 @@
import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql'
import CONFIG from '../../config'
import {} from '../models/Transaction'
import {
TransactionCreateArgs,
TransactionInput,
TransactionSendArgs,
} from '../inputs/TransactionInput'
import { apiPost, apiGet } from '../../apis/loginAPI'
@Resolver()
export class CommunityTransactionResolver {
@Query(() => String)
async balance(@Arg('sessionId') sessionId: number): Promise<any> {
// eslint-disable-next-line no-console
console.log('IN BALANCE: URL: ' + CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId)
return apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId)
}
@Query(() => String)
async transactions(
@Args() { sessionId, firstPage = 1, items = 5, order = 'DESC' }: TransactionInput,
): Promise<any> {
return apiGet(
`${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${sessionId}`,
)
}
@Query(() => String)
async send(@Args() { sessionId, email, amount, memo }: TransactionSendArgs): Promise<any> {
const payload = {
session_id: sessionId,
auto_sign: true,
email: email,
amount: amount,
memo: memo,
}
return apiPost(CONFIG.COMMUNITY_API_URL + 'sendCoins/', payload)
}
@Query(() => String)
async create(
@Args() { sessionId, email, amount, memo, targetDate = new Date() }: TransactionCreateArgs,
): Promise<any> {
const payload = {
sessionId,
email,
amount,
targetDate,
memo,
auto_sign: true,
}
return apiPost(CONFIG.COMMUNITY_API_URL + 'createCoins/', payload)
}
}

View File

@ -8,6 +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 { GroupResolver } from './graphql/resolvers/GroupResolver'
// TODO implement
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
@ -15,7 +16,7 @@ import { UserResolver } from './graphql/resolvers/UserResolver'
async function main() {
// const connection = await createConnection()
const schema = await buildSchema({
resolvers: [/* BookResolver , GroupResolver, */ UserResolver],
resolvers: [/* BookResolver , GroupResolver, */ UserResolver, CommunityTransactionResolver],
})
// Graphiql interface