diff --git a/backend/src/apis/loginAPI.ts b/backend/src/apis/loginAPI.ts index 7160db68c..965b1ccfc 100644 --- a/backend/src/apis/loginAPI.ts +++ b/backend/src/apis/loginAPI.ts @@ -33,7 +33,7 @@ export const apiGet = async (url: string): Promise => { }) .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 } }) } diff --git a/backend/src/graphql/models/Balance.ts b/backend/src/graphql/models/Balance.ts index ceb479b9c..e54bb3478 100644 --- a/backend/src/graphql/models/Balance.ts +++ b/backend/src/graphql/models/Balance.ts @@ -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 } diff --git a/backend/src/graphql/models/Decay.ts b/backend/src/graphql/models/Decay.ts new file mode 100644 index 000000000..af13ac193 --- /dev/null +++ b/backend/src/graphql/models/Decay.ts @@ -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 +} diff --git a/backend/src/graphql/models/Transaction.ts b/backend/src/graphql/models/Transaction.ts index b638e797e..732dd9ec4 100644 --- a/backend/src/graphql/models/Transaction.ts +++ b/backend/src/graphql/models/Transaction.ts @@ -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 } diff --git a/backend/src/graphql/resolvers/BalanceResolver.ts b/backend/src/graphql/resolvers/BalanceResolver.ts new file mode 100644 index 000000000..31bed076c --- /dev/null +++ b/backend/src/graphql/resolvers/BalanceResolver.ts @@ -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 { + 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) + } +} diff --git a/backend/src/index.ts b/backend/src/index.ts index b6e19f56d..d9a35fa40 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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