transaction lists are working

This commit is contained in:
Moriz Wahl 2021-08-03 13:16:29 +02:00
parent ca4998318f
commit 68d46edcf6
10 changed files with 118 additions and 174 deletions

View File

@ -82,23 +82,23 @@ export class UpdateUserInfosArgs {
@Field(() => String)
email!: string
@Field({ nullable: true })
firstName?: string | null
@Field(() => String)
firstName?: string
@Field({ nullable: true })
lastName?: string | null
@Field(() => String)
lastName?: string
@Field({ nullable: true })
username?: string | null
@Field(() => String)
username?: string
@Field({ nullable: true })
language?: string | null
@Field(() => String)
language?: string
@Field({ nullable: true })
password?: string | null
@Field(() => String)
password?: string
@Field({ nullable: true })
passwordNew?: string | null
@Field(() => String)
passwordNew?: string
}
@ArgsType()

View File

@ -1,7 +1,7 @@
import { ArgsType, Field } from 'type-graphql'
@ArgsType()
export class TransactionInput {
export class TransactionListInput {
@Field(() => Number)
sessionId: number

View File

@ -1,3 +1,5 @@
/* 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'

View File

@ -1,11 +1,10 @@
import { Entity, BaseEntity, Column } from 'typeorm'
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType()
export class Decay extends BaseEntity {
export class Decay {
constructor(json: any) {
super()
this.balance = Number(json.balance)
this.decayStart = json.decay_start
this.decayEnd = json.decay_end
@ -13,18 +12,14 @@ export class Decay extends BaseEntity {
}
@Field(() => Number)
@Column()
balance: number
@Field(() => Number)
@Column()
decayStart: number
@Field({ nullable: true })
decayStart?: number
@Field(() => Number)
@Column()
decayEnd: number
@Field({ nullable: true })
decayEnd?: number
@Field(() => String)
@Column()
decayDuration: string
}

View File

@ -1,11 +1,66 @@
import { Entity, BaseEntity, Column } from 'typeorm'
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ObjectType, Field } from 'type-graphql'
import { Decay } from './Decay'
// we need a better solution for the decay block:
// the first transaction on the first page shows the decay since the last transaction
// the format is actually a Decay and not a Transaction.
// Therefore we have a lot of nullable fields, which should be always present
@Entity()
@ObjectType()
export class TransactionList extends BaseEntity {
export class Transaction {
constructor(json: any) {
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.memo = 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)
type: string
@Field(() => Number)
balance: number
@Field({ nullable: true })
decayStart?: number
@Field({ nullable: true })
decayEnd?: number
@Field({ nullable: true })
decayDuration?: string
@Field(() => String)
memo: string
@Field(() => Number)
transactionId: number
@Field({ nullable: true })
name?: string
@Field({ nullable: true })
email?: string
@Field({ nullable: true })
date?: string
@Field({ nullable: true })
decay?: Decay
}
@ObjectType()
export class TransactionList {
constructor(json: any) {
super()
this.gdtSum = Number(json.gdtSum)
this.count = json.count
this.balance = Number(json.balance)
@ -15,88 +70,20 @@ export class TransactionList extends BaseEntity {
}
@Field(() => Number)
@Column()
gdtSum: number
@Field(() => Number)
@Column()
count: number
@Field(() => Number)
@Column()
balance: number
@Field(() => Number)
@Column()
decay: number
@Field(() => 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
}

View File

@ -1,4 +1,4 @@
import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql'
import { Resolver, Query, /* Mutation, */ Arg } from 'type-graphql'
import CONFIG from '../../config'
import { Balance } from '../models/Balance'
import { apiGet } from '../../apis/loginAPI'
@ -8,9 +8,7 @@ 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)
if (!result.success) throw new Error(result.data)
return new Balance(result.data)
}
}

View File

@ -1,57 +0,0 @@
import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql'
import CONFIG from '../../config'
import {} from '../models/Transaction'
import { Balance } from '../models/Balance'
import {
TransactionCreateArgs,
TransactionInput,
TransactionSendArgs,
} from '../inputs/TransactionInput'
import { apiPost, apiGet } from '../../apis/loginAPI'
@Resolver()
export class CommunityTransactionResolver {
@Query(() => Balance)
async balance(@Arg('sessionId') sessionId: number): Promise<Balance> {
// eslint-disable-next-line no-console
console.log('IN BALANCE: URL: ' + CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId)
const result = await apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId)
return new Balance(result.result.data)
}
@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 createCoins(
@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

@ -0,0 +1,19 @@
import { Resolver, Query, /* Mutation, */ Args } from 'type-graphql'
import CONFIG from '../../config'
import { TransactionList } from '../models/Transaction'
import { TransactionListInput } from '../inputs/TransactionInput'
import { apiGet } from '../../apis/loginAPI'
@Resolver()
export class TransactionResolver {
@Query(() => TransactionList)
async transactionList(
@Args() { sessionId, firstPage = 1, items = 25, order = 'DESC' }: TransactionListInput,
): Promise<TransactionList> {
const result = await apiGet(
`${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${sessionId}`,
)
if (!result.success) throw new Error(result.data)
return new TransactionList(result.data)
}
}

View File

@ -23,7 +23,6 @@ import { apiPost, apiGet } from '../../apis/loginAPI'
@Resolver()
export class UserResolver {
@Query(() => LoginResponse)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async login(@Args() { email, password }: UnsecureLoginArgs): Promise<LoginResponse> {
email = email.trim().toLowerCase()
const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password })
@ -51,7 +50,6 @@ export class UserResolver {
}
@Query(() => LoginViaVerificationCode)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async loginViaEmailVerificationCode(
@Arg('optin') optin: string,
): Promise<LoginViaVerificationCode> {
@ -112,6 +110,7 @@ export class UserResolver {
}
@Query(() => GetUserInfoResponse)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async getUserInfos(@Args() { sessionId, email }: GetUserInfoArgs): Promise<any> {
const payload = {
session_id: sessionId,
@ -142,24 +141,24 @@ export class UserResolver {
{
sessionId,
email,
firstName = null,
lastName = null,
username = null,
language = null,
password = null,
passwordNew = null,
firstName = '',
lastName = '',
username = '',
language = '',
password = '',
passwordNew = '',
}: UpdateUserInfosArgs,
): Promise<UpdateUserInfosResponse> {
const payload = {
session_id: sessionId,
email,
update: {
'User.first_name': firstName !== null ? firstName : undefined,
'User.last_name': lastName !== null ? lastName : undefined,
'User.username': username !== null ? username : undefined,
'User.language': language !== null ? language : undefined,
'User.password': passwordNew !== null ? passwordNew : undefined,
'User.password_old': password !== null ? password : undefined,
'User.first_name': firstName !== '' ? firstName : undefined,
'User.last_name': lastName !== '' ? lastName : undefined,
'User.username': username !== '' ? username : undefined,
'User.language': language !== '' ? language : undefined,
'User.password': passwordNew !== '' ? passwordNew : undefined,
'User.password_old': password !== '' ? password : undefined,
},
}
const result = await apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)

View File

@ -9,14 +9,15 @@ import CONFIG from './config'
// import { BookResolver } from './graphql/resolvers/BookResolver'
import { UserResolver } from './graphql/resolvers/UserResolver'
import { BalanceResolver } from './graphql/resolvers/BalanceResolver'
// import { GroupResolver } from './graphql/resolvers/GroupResolver'
import { TransactionResolver } from './graphql/resolvers/TransactionResolver'
// TODO implement
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
async function main() {
// const connection = await createConnection()
const schema = await buildSchema({
resolvers: [UserResolver, BalanceResolver],
resolvers: [UserResolver, BalanceResolver, TransactionResolver],
})
// Graphiql interface