mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #935 from gradido/clean_graphql_structure
Clean graphql structure
This commit is contained in:
commit
9e0618e0f1
@ -1,13 +1,16 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import { AuthChecker } from 'type-graphql'
|
||||
import decode from '../jwt/decode'
|
||||
import { apiGet } from '../apis/HttpRequest'
|
||||
import CONFIG from '../config'
|
||||
import encode from '../jwt/encode'
|
||||
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
||||
export const isAuthorized: AuthChecker<any> = async ({ root, args, context, info }, roles) => {
|
||||
import CONFIG from '../../config'
|
||||
import { apiGet } from '../../apis/HttpRequest'
|
||||
|
||||
import decode from '../../jwt/decode'
|
||||
import encode from '../../jwt/encode'
|
||||
|
||||
const isAuthorized: AuthChecker<any> = async (
|
||||
{ /* root, args, */ context /*, info */ } /*, roles */,
|
||||
) => {
|
||||
if (context.token) {
|
||||
const decoded = decode(context.token)
|
||||
if (decoded.sessionId && decoded.sessionId !== 0) {
|
||||
@ -22,3 +25,5 @@ export const isAuthorized: AuthChecker<any> = async ({ root, args, context, info
|
||||
}
|
||||
throw new Error('401 Unauthorized')
|
||||
}
|
||||
|
||||
export default isAuthorized
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
import { Resolver, Query, Ctx, Authorized } from 'type-graphql'
|
||||
import { getCustomRepository } from 'typeorm'
|
||||
import { Balance } from '../models/Balance'
|
||||
import { Balance } from '../model/Balance'
|
||||
import { BalanceRepository } from '../../typeorm/repository/Balance'
|
||||
import { UserRepository } from '../../typeorm/repository/User'
|
||||
import { calculateDecay } from '../../util/decay'
|
||||
@ -4,8 +4,8 @@
|
||||
import { Resolver, Query, Args, Ctx, Authorized } from 'type-graphql'
|
||||
import { getCustomRepository } from 'typeorm'
|
||||
import CONFIG from '../../config'
|
||||
import { GdtEntryList } from '../models/GdtEntryList'
|
||||
import Paginated from '../args/Paginated'
|
||||
import { GdtEntryList } from '../model/GdtEntryList'
|
||||
import Paginated from '../arg/Paginated'
|
||||
import { apiGet } from '../../apis/HttpRequest'
|
||||
import { UserRepository } from '../../typeorm/repository/User'
|
||||
import { Order } from '../enum/Order'
|
||||
@ -8,7 +8,7 @@ import {
|
||||
unsubscribe,
|
||||
signIn,
|
||||
} from '../../apis/KlicktippController'
|
||||
import SubscribeNewsletterArgs from '../args/SubscribeNewsletterArgs'
|
||||
import SubscribeNewsletterArgs from '../arg/SubscribeNewsletterArgs'
|
||||
|
||||
@Resolver()
|
||||
export class KlicktippResolver {
|
||||
@ -6,11 +6,11 @@ import { getCustomRepository } from 'typeorm'
|
||||
|
||||
import CONFIG from '../../config'
|
||||
|
||||
import { Transaction } from '../models/Transaction'
|
||||
import { TransactionList } from '../models/TransactionList'
|
||||
import { Transaction } from '../model/Transaction'
|
||||
import { TransactionList } from '../model/TransactionList'
|
||||
|
||||
import TransactionSendArgs from '../args/TransactionSendArgs'
|
||||
import Paginated from '../args/Paginated'
|
||||
import TransactionSendArgs from '../arg/TransactionSendArgs'
|
||||
import Paginated from '../arg/Paginated'
|
||||
|
||||
import { Order } from '../enum/Order'
|
||||
|
||||
@ -3,26 +3,26 @@
|
||||
|
||||
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
|
||||
import CONFIG from '../../config'
|
||||
import { CheckUsernameResponse } from '../models/CheckUsernameResponse'
|
||||
import { LoginViaVerificationCode } from '../models/LoginViaVerificationCode'
|
||||
import { SendPasswordResetEmailResponse } from '../models/SendPasswordResetEmailResponse'
|
||||
import { UpdateUserInfosResponse } from '../models/UpdateUserInfosResponse'
|
||||
import { User } from '../models/User'
|
||||
import { CheckUsernameResponse } from '../model/CheckUsernameResponse'
|
||||
import { LoginViaVerificationCode } from '../model/LoginViaVerificationCode'
|
||||
import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse'
|
||||
import { UpdateUserInfosResponse } from '../model/UpdateUserInfosResponse'
|
||||
import { User } from '../model/User'
|
||||
import encode from '../../jwt/encode'
|
||||
import ChangePasswordArgs from '../args/ChangePasswordArgs'
|
||||
import CheckUsernameArgs from '../args/CheckUsernameArgs'
|
||||
import CreateUserArgs from '../args/CreateUserArgs'
|
||||
import UnsecureLoginArgs from '../args/UnsecureLoginArgs'
|
||||
import UpdateUserInfosArgs from '../args/UpdateUserInfosArgs'
|
||||
import ChangePasswordArgs from '../arg/ChangePasswordArgs'
|
||||
import CheckUsernameArgs from '../arg/CheckUsernameArgs'
|
||||
import CreateUserArgs from '../arg/CreateUserArgs'
|
||||
import UnsecureLoginArgs from '../arg/UnsecureLoginArgs'
|
||||
import UpdateUserInfosArgs from '../arg/UpdateUserInfosArgs'
|
||||
import { apiPost, apiGet } from '../../apis/HttpRequest'
|
||||
import {
|
||||
klicktippRegistrationMiddleware,
|
||||
klicktippNewsletterStateMiddleware,
|
||||
} from '../../middleware/klicktippMiddleware'
|
||||
import { CheckEmailResponse } from '../models/CheckEmailResponse'
|
||||
import { CheckEmailResponse } from '../model/CheckEmailResponse'
|
||||
import { getCustomRepository } from 'typeorm'
|
||||
import { UserSettingRepository } from '../../typeorm/repository/UserSettingRepository'
|
||||
import { Setting } from '../../graphql/enum/Setting'
|
||||
import { Setting } from '../enum/Setting'
|
||||
import { UserRepository } from '../../typeorm/repository/User'
|
||||
|
||||
@Resolver()
|
||||
@ -1,19 +0,0 @@
|
||||
import { UserResolver } from './UserResolver'
|
||||
import { BalanceResolver } from './BalanceResolver'
|
||||
import { GdtResolver } from './GdtResolver'
|
||||
import { TransactionResolver } from './TransactionResolver'
|
||||
import { KlicktippResolver } from './KlicktippResolver'
|
||||
import { NonEmptyArray } from 'type-graphql'
|
||||
|
||||
export { UserResolver, BalanceResolver, GdtResolver, TransactionResolver, KlicktippResolver }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
const resolvers = (): NonEmptyArray<Function> => [
|
||||
UserResolver,
|
||||
BalanceResolver,
|
||||
GdtResolver,
|
||||
TransactionResolver,
|
||||
KlicktippResolver,
|
||||
]
|
||||
|
||||
export default resolvers
|
||||
@ -1,12 +1,12 @@
|
||||
import { GraphQLSchema } from 'graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
import path from 'path'
|
||||
|
||||
import resolvers from './resolvers'
|
||||
import { isAuthorized } from '../auth/auth'
|
||||
import isAuthorized from './directive/isAuthorized'
|
||||
|
||||
const schema = async (): Promise<GraphQLSchema> => {
|
||||
return buildSchema({
|
||||
resolvers: resolvers(),
|
||||
resolvers: [path.join(__dirname, 'resolver', `*.{js,ts}`)],
|
||||
authChecker: isAuthorized,
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { MiddlewareFn } from 'type-graphql'
|
||||
import { signIn, getKlickTippUser } from '../apis/KlicktippController'
|
||||
import { KlickTipp } from '../graphql/models/KlickTipp'
|
||||
import { KlickTipp } from '../graphql/model/KlickTipp'
|
||||
import CONFIG from '../config/index'
|
||||
|
||||
export const klicktippRegistrationMiddleware: MiddlewareFn = async (
|
||||
|
||||
@ -1,6 +1,29 @@
|
||||
import { calculateDecay } from './decay'
|
||||
import { decayFormula, calculateDecay } from './decay'
|
||||
|
||||
describe('utils/decay', () => {
|
||||
describe('decayFormula', () => {
|
||||
it('has base 0.99999997802044727', async () => {
|
||||
const amount = 1.0
|
||||
const seconds = 1
|
||||
expect(await decayFormula(amount, seconds)).toBe(0.99999997802044727)
|
||||
})
|
||||
// Not sure if the following skiped tests make sence!?
|
||||
it.skip('has negative decay?', async () => {
|
||||
const amount = -1.0
|
||||
const seconds = 1
|
||||
expect(await decayFormula(amount, seconds)).toBe(-0.99999997802044727)
|
||||
})
|
||||
it.skip('has correct backward calculation', async () => {
|
||||
const amount = 1.0
|
||||
const seconds = -1
|
||||
expect(await decayFormula(amount, seconds)).toBe(1.0000000219795533)
|
||||
})
|
||||
it.skip('has correct forward calculation', async () => {
|
||||
const amount = 1.000000219795533
|
||||
const seconds = 1
|
||||
expect(await decayFormula(amount, seconds)).toBe(1.0)
|
||||
})
|
||||
})
|
||||
it.skip('has base 0.99999997802044727', async () => {
|
||||
const now = new Date()
|
||||
now.setSeconds(1)
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { getCustomRepository } from 'typeorm'
|
||||
import { Decay } from '../graphql/models/Decay'
|
||||
import { Decay } from '../graphql/model/Decay'
|
||||
import { TransactionRepository } from '../typeorm/repository/Transaction'
|
||||
|
||||
function decayFormula(amount: number, durationInSeconds: number): number {
|
||||
return amount * Math.pow(0.99999997802044727, durationInSeconds)
|
||||
function decayFormula(amount: number, seconds: number): number {
|
||||
return amount * Math.pow(0.99999997802044727, seconds) // This number represents 50% decay a year
|
||||
}
|
||||
|
||||
async function calculateDecay(amount: number, from: Date, to: Date): Promise<number> {
|
||||
@ -56,4 +56,4 @@ async function calculateDecayWithInterval(
|
||||
return result
|
||||
}
|
||||
|
||||
export { calculateDecay, calculateDecayWithInterval }
|
||||
export { decayFormula, calculateDecay, calculateDecayWithInterval }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user