mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
transaction lists are working
This commit is contained in:
parent
ca4998318f
commit
68d46edcf6
@ -82,23 +82,23 @@ export class UpdateUserInfosArgs {
|
|||||||
@Field(() => String)
|
@Field(() => String)
|
||||||
email!: string
|
email!: string
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field(() => String)
|
||||||
firstName?: string | null
|
firstName?: string
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field(() => String)
|
||||||
lastName?: string | null
|
lastName?: string
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field(() => String)
|
||||||
username?: string | null
|
username?: string
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field(() => String)
|
||||||
language?: string | null
|
language?: string
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field(() => String)
|
||||||
password?: string | null
|
password?: string
|
||||||
|
|
||||||
@Field({ nullable: true })
|
@Field(() => String)
|
||||||
passwordNew?: string | null
|
passwordNew?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgsType()
|
@ArgsType()
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { ArgsType, Field } from 'type-graphql'
|
import { ArgsType, Field } from 'type-graphql'
|
||||||
|
|
||||||
@ArgsType()
|
@ArgsType()
|
||||||
export class TransactionInput {
|
export class TransactionListInput {
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
sessionId: number
|
sessionId: number
|
||||||
|
|
||||||
|
|||||||
@ -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 { Entity, BaseEntity, Column } from 'typeorm'
|
||||||
import { ObjectType, Field } from 'type-graphql'
|
import { ObjectType, Field } from 'type-graphql'
|
||||||
|
|
||||||
|
|||||||
@ -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'
|
import { ObjectType, Field } from 'type-graphql'
|
||||||
|
|
||||||
@Entity()
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class Decay extends BaseEntity {
|
export class Decay {
|
||||||
constructor(json: any) {
|
constructor(json: any) {
|
||||||
super()
|
|
||||||
this.balance = Number(json.balance)
|
this.balance = Number(json.balance)
|
||||||
this.decayStart = json.decay_start
|
this.decayStart = json.decay_start
|
||||||
this.decayEnd = json.decay_end
|
this.decayEnd = json.decay_end
|
||||||
@ -13,18 +12,14 @@ export class Decay extends BaseEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
@Column()
|
|
||||||
balance: number
|
balance: number
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field({ nullable: true })
|
||||||
@Column()
|
decayStart?: number
|
||||||
decayStart: number
|
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field({ nullable: true })
|
||||||
@Column()
|
decayEnd?: number
|
||||||
decayEnd: number
|
|
||||||
|
|
||||||
@Field(() => String)
|
@Field(() => String)
|
||||||
@Column()
|
|
||||||
decayDuration: string
|
decayDuration: string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { 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()
|
@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) {
|
constructor(json: any) {
|
||||||
super()
|
|
||||||
this.gdtSum = Number(json.gdtSum)
|
this.gdtSum = Number(json.gdtSum)
|
||||||
this.count = json.count
|
this.count = json.count
|
||||||
this.balance = Number(json.balance)
|
this.balance = Number(json.balance)
|
||||||
@ -15,88 +70,20 @@ export class TransactionList extends BaseEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
@Column()
|
|
||||||
gdtSum: number
|
gdtSum: number
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
@Column()
|
|
||||||
count: number
|
count: number
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
@Column()
|
|
||||||
balance: number
|
balance: number
|
||||||
|
|
||||||
@Field(() => Number)
|
@Field(() => Number)
|
||||||
@Column()
|
|
||||||
decay: number
|
decay: number
|
||||||
|
|
||||||
@Field(() => String)
|
@Field(() => String)
|
||||||
@Column()
|
|
||||||
decayDate: string
|
decayDate: string
|
||||||
|
|
||||||
@Field(() => [Transaction])
|
@Field(() => [Transaction])
|
||||||
transactions: 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
|
|
||||||
}
|
|
||||||
|
|||||||
@ -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 CONFIG from '../../config'
|
||||||
import { Balance } from '../models/Balance'
|
import { Balance } from '../models/Balance'
|
||||||
import { apiGet } from '../../apis/loginAPI'
|
import { apiGet } from '../../apis/loginAPI'
|
||||||
@ -8,9 +8,7 @@ export class BalanceResolver {
|
|||||||
@Query(() => Balance)
|
@Query(() => Balance)
|
||||||
async balance(@Arg('sessionId') sessionId: number): Promise<Balance> {
|
async balance(@Arg('sessionId') sessionId: number): Promise<Balance> {
|
||||||
const result = await apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId)
|
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)
|
return new Balance(result.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
19
backend/src/graphql/resolvers/TransactionResolver.ts
Normal file
19
backend/src/graphql/resolvers/TransactionResolver.ts
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,7 +23,6 @@ import { apiPost, apiGet } from '../../apis/loginAPI'
|
|||||||
@Resolver()
|
@Resolver()
|
||||||
export class UserResolver {
|
export class UserResolver {
|
||||||
@Query(() => LoginResponse)
|
@Query(() => LoginResponse)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
async login(@Args() { email, password }: UnsecureLoginArgs): Promise<LoginResponse> {
|
async login(@Args() { email, password }: UnsecureLoginArgs): Promise<LoginResponse> {
|
||||||
email = email.trim().toLowerCase()
|
email = email.trim().toLowerCase()
|
||||||
const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password })
|
const result = await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', { email, password })
|
||||||
@ -51,7 +50,6 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => LoginViaVerificationCode)
|
@Query(() => LoginViaVerificationCode)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
async loginViaEmailVerificationCode(
|
async loginViaEmailVerificationCode(
|
||||||
@Arg('optin') optin: string,
|
@Arg('optin') optin: string,
|
||||||
): Promise<LoginViaVerificationCode> {
|
): Promise<LoginViaVerificationCode> {
|
||||||
@ -112,6 +110,7 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => GetUserInfoResponse)
|
@Query(() => GetUserInfoResponse)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
async getUserInfos(@Args() { sessionId, email }: GetUserInfoArgs): Promise<any> {
|
async getUserInfos(@Args() { sessionId, email }: GetUserInfoArgs): Promise<any> {
|
||||||
const payload = {
|
const payload = {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
@ -142,24 +141,24 @@ export class UserResolver {
|
|||||||
{
|
{
|
||||||
sessionId,
|
sessionId,
|
||||||
email,
|
email,
|
||||||
firstName = null,
|
firstName = '',
|
||||||
lastName = null,
|
lastName = '',
|
||||||
username = null,
|
username = '',
|
||||||
language = null,
|
language = '',
|
||||||
password = null,
|
password = '',
|
||||||
passwordNew = null,
|
passwordNew = '',
|
||||||
}: UpdateUserInfosArgs,
|
}: UpdateUserInfosArgs,
|
||||||
): Promise<UpdateUserInfosResponse> {
|
): Promise<UpdateUserInfosResponse> {
|
||||||
const payload = {
|
const payload = {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
email,
|
email,
|
||||||
update: {
|
update: {
|
||||||
'User.first_name': firstName !== null ? firstName : undefined,
|
'User.first_name': firstName !== '' ? firstName : undefined,
|
||||||
'User.last_name': lastName !== null ? lastName : undefined,
|
'User.last_name': lastName !== '' ? lastName : undefined,
|
||||||
'User.username': username !== null ? username : undefined,
|
'User.username': username !== '' ? username : undefined,
|
||||||
'User.language': language !== null ? language : undefined,
|
'User.language': language !== '' ? language : undefined,
|
||||||
'User.password': passwordNew !== null ? passwordNew : undefined,
|
'User.password': passwordNew !== '' ? passwordNew : undefined,
|
||||||
'User.password_old': password !== null ? password : undefined,
|
'User.password_old': password !== '' ? password : undefined,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const result = await apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
|
const result = await apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
|
||||||
|
|||||||
@ -9,14 +9,15 @@ import CONFIG from './config'
|
|||||||
// import { BookResolver } from './graphql/resolvers/BookResolver'
|
// import { BookResolver } from './graphql/resolvers/BookResolver'
|
||||||
import { UserResolver } from './graphql/resolvers/UserResolver'
|
import { UserResolver } from './graphql/resolvers/UserResolver'
|
||||||
import { BalanceResolver } from './graphql/resolvers/BalanceResolver'
|
import { BalanceResolver } from './graphql/resolvers/BalanceResolver'
|
||||||
// import { GroupResolver } from './graphql/resolvers/GroupResolver'
|
import { TransactionResolver } from './graphql/resolvers/TransactionResolver'
|
||||||
|
|
||||||
// TODO implement
|
// TODO implement
|
||||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
// const connection = await createConnection()
|
// const connection = await createConnection()
|
||||||
const schema = await buildSchema({
|
const schema = await buildSchema({
|
||||||
resolvers: [UserResolver, BalanceResolver],
|
resolvers: [UserResolver, BalanceResolver, TransactionResolver],
|
||||||
})
|
})
|
||||||
|
|
||||||
// Graphiql interface
|
// Graphiql interface
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user