From 403826a6d9ad5e512ce29b1b2f2cb4ac43c3caa8 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 4 Aug 2021 11:51:50 +0200 Subject: [PATCH] final changes before merge --- backend/src/apis/loginAPI.ts | 2 - backend/src/graphql/inputs/LoginUserInput.ts | 31 +------------- .../src/graphql/inputs/TransactionInput.ts | 24 ++--------- backend/src/graphql/models/Decay.ts | 10 ++--- backend/src/graphql/models/Server.ts | 16 -------- backend/src/graphql/models/Transaction.ts | 7 +++- backend/src/graphql/models/UserInfoData.ts | 40 ------------------- backend/src/graphql/resolvers/UserResolver.ts | 9 ++--- 8 files changed, 17 insertions(+), 122 deletions(-) delete mode 100644 backend/src/graphql/models/Server.ts delete mode 100644 backend/src/graphql/models/UserInfoData.ts diff --git a/backend/src/apis/loginAPI.ts b/backend/src/apis/loginAPI.ts index 965b1ccfc..c1f99dc46 100644 --- a/backend/src/apis/loginAPI.ts +++ b/backend/src/apis/loginAPI.ts @@ -32,8 +32,6 @@ export const apiGet = async (url: string): Promise => { return { success: true, data: result.data } }) .catch((error) => { - // eslint-disable-next-line no-console - console.log('IN apiGet.ERROR: ', { success: false, result: error }) return { success: false, data: error.message } }) } diff --git a/backend/src/graphql/inputs/LoginUserInput.ts b/backend/src/graphql/inputs/LoginUserInput.ts index 1668c5191..3d5299d84 100644 --- a/backend/src/graphql/inputs/LoginUserInput.ts +++ b/backend/src/graphql/inputs/LoginUserInput.ts @@ -1,22 +1,5 @@ import { ArgsType, Field } from 'type-graphql' -/* -@InputType() -export class LoginUserInput { - @Field({ nullable: true }) - username?: string - - @Field({ nullable: true }) - email?: string - - @Field({ nullable: true }) - pubkey?: string - - @Field() - password: string -} -*/ - @ArgsType() export class UnsecureLoginArgs { @Field(() => String) @@ -41,18 +24,6 @@ export class CreateUserArgs { password: string } -@ArgsType() -export class SendEmailArgs { - @Field(() => String) - email: string - - @Field(() => Number) - emailText: number - - @Field(() => String) - emailVerificationCodeType: string -} - @ArgsType() export class GetUserInfoArgs { @Field(() => Number) @@ -109,6 +80,6 @@ export class CheckUsernameArgs { @Field(() => String) username: string - @Field(() => Number) + @Field(() => Number, { nullable: true }) groupId?: number } diff --git a/backend/src/graphql/inputs/TransactionInput.ts b/backend/src/graphql/inputs/TransactionInput.ts index 049a9b2a9..7f83cd82d 100644 --- a/backend/src/graphql/inputs/TransactionInput.ts +++ b/backend/src/graphql/inputs/TransactionInput.ts @@ -1,14 +1,14 @@ -import { ArgsType, Field } from 'type-graphql' +import { ArgsType, Field, Int } from 'type-graphql' @ArgsType() export class TransactionListInput { @Field(() => Number) sessionId: number - @Field(() => Number) + @Field(() => Int) firstPage: number - @Field(() => Number) + @Field(() => Int) items: number @Field(() => String) @@ -29,21 +29,3 @@ export class TransactionSendArgs { @Field(() => String) memo: string } - -@ArgsType() -export class TransactionCreateArgs { - @Field(() => Number) - sessionId: number - - @Field(() => String) - email: string - - @Field(() => Number) - amount: number - - @Field(() => String) - memo: string - - @Field(() => Date) - targetDate: Date -} diff --git a/backend/src/graphql/models/Decay.ts b/backend/src/graphql/models/Decay.ts index 3d918ce7a..c6ce85548 100644 --- a/backend/src/graphql/models/Decay.ts +++ b/backend/src/graphql/models/Decay.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { ObjectType, Field } from 'type-graphql' +import { ObjectType, Field, Int } from 'type-graphql' @ObjectType() export class Decay { @@ -14,12 +14,12 @@ export class Decay { @Field(() => Number) balance: number - @Field({ nullable: true }) + @Field(() => Int, { nullable: true }) decayStart?: number - @Field({ nullable: true }) + @Field(() => Int, { nullable: true }) decayEnd?: number - @Field(() => String) - decayDuration: string + @Field(() => String, { nullable: true }) + decayDuration?: string } diff --git a/backend/src/graphql/models/Server.ts b/backend/src/graphql/models/Server.ts deleted file mode 100644 index 1b6f01627..000000000 --- a/backend/src/graphql/models/Server.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { Entity, BaseEntity } from 'typeorm' -import { ObjectType, Field } from 'type-graphql' - -@Entity() -@ObjectType() -export class Server extends BaseEntity { - constructor(json: any) { - super() - this.loginServerPath = json.login_server_path - } - - @Field(() => String) - loginServerPath: string -} diff --git a/backend/src/graphql/models/Transaction.ts b/backend/src/graphql/models/Transaction.ts index 61670b06a..fb17866c4 100644 --- a/backend/src/graphql/models/Transaction.ts +++ b/backend/src/graphql/models/Transaction.ts @@ -11,6 +11,7 @@ import { Decay } from './Decay' @ObjectType() export class Transaction { constructor(json: any) { + // console.log('Transaction constructor', json) this.type = json.type this.balance = Number(json.balance) this.decayStart = json.decay_start @@ -21,7 +22,7 @@ export class Transaction { this.name = json.name this.email = json.email this.date = json.date - this.decay = json.decay + this.decay = json.decay ? new Decay(json.decay) : undefined } @Field(() => String) @@ -66,7 +67,9 @@ export class TransactionList { this.balance = Number(json.balance) this.decay = Number(json.decay) this.decayDate = json.decay_date - this.transactions = json.transactions + this.transactions = json.transactions.map((el: any) => { + return new Transaction(el) + }) } @Field(() => Number) diff --git a/backend/src/graphql/models/UserInfoData.ts b/backend/src/graphql/models/UserInfoData.ts deleted file mode 100644 index 2e65aca82..000000000 --- a/backend/src/graphql/models/UserInfoData.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { Entity, BaseEntity } from 'typeorm' -import { ObjectType, Field } from 'type-graphql' -import { Server } from './Server' -import { User } from './User' - -@Entity() -@ObjectType() -export class UserInfoData extends BaseEntity { - constructor(json: any) { - super() - this.state = json.state - this.userData = new User(json.user_data) - this.server = new Server(json.server) - this.errors = json.errors - } - - @Field(() => String) - state: string - - @Field(() => User) - userData: User - - @Field(() => Server) - server: Server - - @Field(() => [String]) - errors: [string] -} - -@Entity() -@ObjectType() -export class GetUserInfoResponse extends BaseEntity { - @Field(() => Boolean) - success: boolean - - @Field(() => UserInfoData) - data: UserInfoData -} diff --git a/backend/src/graphql/resolvers/UserResolver.ts b/backend/src/graphql/resolvers/UserResolver.ts index c50b8d9f0..acd70ab5c 100644 --- a/backend/src/graphql/resolvers/UserResolver.ts +++ b/backend/src/graphql/resolvers/UserResolver.ts @@ -12,7 +12,6 @@ import { CheckUsernameArgs, CreateUserArgs, GetUserInfoArgs, - SendEmailArgs, UnsecureLoginArgs, UpdateUserInfosArgs, } from '../inputs/LoginUserInput' @@ -89,16 +88,14 @@ export class UserResolver { return 'success' } - // TODO @Query(() => SendPasswordResetEmailResponse) async sendResetPasswordEmail( - @Args() - { email, emailText = 7, emailVerificationCodeType = 'resetPassword' }: SendEmailArgs, + @Arg('email') email: string, ): Promise { const payload = { email, - email_text: emailText, - email_verification_code_type: emailVerificationCodeType, + email_text: 7, + email_verification_code_type: 'resetPassword', } const response = await apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload) if (!response.success) throw new Error(response.data)