Merge pull request #686 from gradido/apollo_gdt

Apollo gdt
This commit is contained in:
einhornimmond 2021-08-05 15:51:43 +02:00 committed by GitHub
commit 57a1a39a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 146 additions and 2 deletions

View File

@ -1,4 +1,5 @@
PORT=4000
GRAPHIQL=false
// LOGIN_API_URL=http://login-server:1201/
// COMMUNITY_API_URL=http://nginx/api/
// COMMUNITY_API_URL=http://nginx/api/
// GDT_API_URL=https://gdt.gradido.net

View File

@ -10,6 +10,7 @@ const server = {
GRAPHIQL: process.env.GRAPHIQL === 'true' || false,
LOGIN_API_URL: process.env.LOGIN_API_URL || 'http://login-server:1201/',
COMMUNITY_API_URL: process.env.COMMUNITY_API_URL || 'http://ngninx/api/',
GDT_API_URL: process.env.GDT_API_URL || 'https://gdt.gradido.net',
}
// This is needed by graphql-directive-auth

View File

@ -0,0 +1,16 @@
import { ArgsType, Field } from 'type-graphql'
@ArgsType()
export class GdtTransactionInput {
@Field(() => String)
email: string
@Field(() => Number)
firstPage?: number
@Field(() => Number)
items?: number
@Field(() => String)
order?: string
}

View File

@ -0,0 +1,57 @@
import { ObjectType, Field } from 'type-graphql'
export enum GdtEntryType {
FORM = 1,
CVS = 2,
ELOPAGE = 3,
ELOPAGE_PUBLISHER = 4,
DIGISTORE = 5,
CVS2 = 6,
GLOBAL_MODIFICATOR = 7,
}
@ObjectType()
export class GdtEntry {
constructor(json: any) {
this.amount = json.amount
this.date = json.date
this.email = json.email
this.comment = json.comment
this.couponCode = json.coupon_code
this.gdtEntryType = json.gdt_entry_type_id
this.factor = json.factor
this.amount2 = json.amount2
this.factor2 = json.factor2
this.gdt = json.gdt
}
@Field(() => Number)
amount: number
@Field(() => String)
date: string
@Field(() => String)
email: string
@Field(() => String)
comment: string
@Field(() => String)
couponCode: string
@Field(() => Number)
gdtEntryType: GdtEntryType
@Field(() => Number)
factor: number
@Field(() => Number)
amount2: number
@Field(() => Number)
factor2: number
@Field(() => Number)
gdt: number
}

View File

@ -0,0 +1,42 @@
import { GdtEntry } from './GdtEntry'
import { ObjectType, Field } from 'type-graphql'
@ObjectType()
export class GdtSumPerEmail {
constructor(email: string, summe: number) {
this.email = email
this.summe = summe
}
@Field(() => String)
email: string
@Field(() => Number)
summe: number
}
@ObjectType()
export class GdtEntryList {
constructor(json: any) {
this.state = json.state
this.count = json.count
this.gdtEntries = json.gdtEntries ? json.gdtEntries.map((json: any) => new GdtEntry(json)) : []
this.gdtSum = json.gdtSum
this.timeUsed = json.timeUsed
}
@Field(() => String)
state: string
@Field(() => Number)
count: number
@Field(() => [GdtEntry])
gdtEntries: GdtEntry[]
@Field(() => Number)
gdtSum: number
@Field(() => Number)
timeUsed: number
}

View File

@ -0,0 +1,26 @@
// import jwt from 'jsonwebtoken'
import { Resolver, Query, /* Mutation, */ Args } from 'type-graphql'
import CONFIG from '../../config'
import { GdtEntryList } from '../models/GdtEntryList'
import { GdtTransactionInput } from '../inputs/GdtInputs'
import { apiGet } from '../../apis/loginAPI'
@Resolver()
export class GdtResolver {
@Query(() => GdtEntryList)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async listGDTEntries(
@Args() { email, firstPage = 1, items = 5, order = 'DESC' }: GdtTransactionInput,
): Promise<GdtEntryList> {
email = email.trim().toLowerCase()
const result = await apiGet(
`${CONFIG.GDT_API_URL}/GdtEntries/listPerEmailApi/${email}/${firstPage}/${items}/${order}`,
)
if (!result.success) {
throw new Error(result.data)
}
return new GdtEntryList(result.data)
}
}

View File

@ -9,6 +9,7 @@ import CONFIG from './config'
// import { BookResolver } from './graphql/resolvers/BookResolver'
import { UserResolver } from './graphql/resolvers/UserResolver'
import { BalanceResolver } from './graphql/resolvers/BalanceResolver'
import { GdtResolver } from './graphql/resolvers/GdtResolver'
import { TransactionResolver } from './graphql/resolvers/TransactionResolver'
// TODO implement
@ -17,7 +18,7 @@ import { TransactionResolver } from './graphql/resolvers/TransactionResolver'
async function main() {
// const connection = await createConnection()
const schema = await buildSchema({
resolvers: [UserResolver, BalanceResolver, TransactionResolver],
resolvers: [UserResolver, BalanceResolver, TransactionResolver, GdtResolver],
})
// Graphiql interface