From 99a37ddb0aea0ec55854565adcd507fa6d24d2b4 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Tue, 3 Aug 2021 10:28:49 +0200 Subject: [PATCH 1/6] Implementation of the Response classes, and logic for the update user prozess. --- backend/src/graphql/inputs/LoginUserInput.ts | 12 +-- backend/src/graphql/models/BaseResponse.ts | 9 --- .../graphql/models/ChangePasswordResponse.ts | 9 --- .../graphql/models/CheckUsernameResponse.ts | 9 +++ backend/src/graphql/models/CreateResponse.ts | 2 + .../graphql/models/ResetPasswordResponse.ts | 16 ++++ ...e.ts => SendPasswordResetEmailResponse.ts} | 4 +- backend/src/graphql/models/Server.ts | 2 + .../graphql/models/UpdateUserInfosResponse.ts | 9 +++ backend/src/graphql/models/UserInfoData.ts | 2 + backend/src/graphql/resolvers/UserResolver.ts | 81 +++++++++++-------- .../helpers/MapVariableToColumnName.ts | 3 + 12 files changed, 99 insertions(+), 59 deletions(-) delete mode 100644 backend/src/graphql/models/BaseResponse.ts delete mode 100644 backend/src/graphql/models/ChangePasswordResponse.ts create mode 100644 backend/src/graphql/models/ResetPasswordResponse.ts rename backend/src/graphql/models/{SendEmailResponse.ts => SendPasswordResetEmailResponse.ts} (60%) diff --git a/backend/src/graphql/inputs/LoginUserInput.ts b/backend/src/graphql/inputs/LoginUserInput.ts index 68ddad628..1f786702f 100644 --- a/backend/src/graphql/inputs/LoginUserInput.ts +++ b/backend/src/graphql/inputs/LoginUserInput.ts @@ -82,22 +82,22 @@ export class UpdateUserInfosArgs { @Field(() => String) email!: string - @Field(() => String) + @Field({ nullable: true }) firstName?: string - @Field(() => String) + @Field({ nullable: true }) lastName?: string - @Field(() => String) + @Field({ nullable: true }) username?: string - @Field(() => String) + @Field({ nullable: true }) language?: string - @Field(() => String) + @Field({ nullable: true }) password?: string - @Field(() => String) + @Field({ nullable: true }) passwordNew?: string } diff --git a/backend/src/graphql/models/BaseResponse.ts b/backend/src/graphql/models/BaseResponse.ts deleted file mode 100644 index 712660bd3..000000000 --- a/backend/src/graphql/models/BaseResponse.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Entity, BaseEntity } from 'typeorm' -import { ObjectType, Field } from 'type-graphql' - -@Entity() -@ObjectType() -export class BaseResponse extends BaseEntity { - @Field(() => Boolean) - success: boolean -} diff --git a/backend/src/graphql/models/ChangePasswordResponse.ts b/backend/src/graphql/models/ChangePasswordResponse.ts deleted file mode 100644 index 1ba3247cd..000000000 --- a/backend/src/graphql/models/ChangePasswordResponse.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Entity, BaseEntity } from 'typeorm' -import { ObjectType, Field } from 'type-graphql' - -@Entity() -@ObjectType() -export class ChangePasswordResponse extends BaseEntity { - @Field(() => String) - state: string -} diff --git a/backend/src/graphql/models/CheckUsernameResponse.ts b/backend/src/graphql/models/CheckUsernameResponse.ts index ac51b64e1..de5724c8d 100644 --- a/backend/src/graphql/models/CheckUsernameResponse.ts +++ b/backend/src/graphql/models/CheckUsernameResponse.ts @@ -1,9 +1,18 @@ +/* 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 CheckUsernameResponse extends BaseEntity { + constructor(json: any) { + super() + this.state = json.state + this.msg = json.msg + this.groupId = json.group_id + } + @Field(() => String) state: string diff --git a/backend/src/graphql/models/CreateResponse.ts b/backend/src/graphql/models/CreateResponse.ts index 54276b031..144d6456c 100644 --- a/backend/src/graphql/models/CreateResponse.ts +++ b/backend/src/graphql/models/CreateResponse.ts @@ -1,3 +1,5 @@ +/* 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' diff --git a/backend/src/graphql/models/ResetPasswordResponse.ts b/backend/src/graphql/models/ResetPasswordResponse.ts new file mode 100644 index 000000000..aae209059 --- /dev/null +++ b/backend/src/graphql/models/ResetPasswordResponse.ts @@ -0,0 +1,16 @@ +/* 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 ResetPasswordResponse extends BaseEntity { + constructor(json: any) { + super() + this.state = json.state + } + + @Field(() => String) + state: string +} diff --git a/backend/src/graphql/models/SendEmailResponse.ts b/backend/src/graphql/models/SendPasswordResetEmailResponse.ts similarity index 60% rename from backend/src/graphql/models/SendEmailResponse.ts rename to backend/src/graphql/models/SendPasswordResetEmailResponse.ts index d8e163478..f426d5245 100644 --- a/backend/src/graphql/models/SendEmailResponse.ts +++ b/backend/src/graphql/models/SendPasswordResetEmailResponse.ts @@ -1,9 +1,11 @@ +/* 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 SendEmailResponse extends BaseEntity { +export class SendPasswordResetEmailResponse extends BaseEntity { constructor(json: any) { super() this.state = json.state diff --git a/backend/src/graphql/models/Server.ts b/backend/src/graphql/models/Server.ts index e722a2c97..1b6f01627 100644 --- a/backend/src/graphql/models/Server.ts +++ b/backend/src/graphql/models/Server.ts @@ -1,3 +1,5 @@ +/* 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' diff --git a/backend/src/graphql/models/UpdateUserInfosResponse.ts b/backend/src/graphql/models/UpdateUserInfosResponse.ts index 14f834932..820ee0011 100644 --- a/backend/src/graphql/models/UpdateUserInfosResponse.ts +++ b/backend/src/graphql/models/UpdateUserInfosResponse.ts @@ -1,9 +1,18 @@ +/* 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 UpdateUserInfosResponse extends BaseEntity { + constructor(json: any) { + super() + this.state = json.state + this.validValues = json.valid_values + this.errors = json.errors + } + @Field(() => String) state: string diff --git a/backend/src/graphql/models/UserInfoData.ts b/backend/src/graphql/models/UserInfoData.ts index 46b336d5e..2e65aca82 100644 --- a/backend/src/graphql/models/UserInfoData.ts +++ b/backend/src/graphql/models/UserInfoData.ts @@ -1,3 +1,5 @@ +/* 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' diff --git a/backend/src/graphql/resolvers/UserResolver.ts b/backend/src/graphql/resolvers/UserResolver.ts index d22dd49ac..5dc93f7bd 100644 --- a/backend/src/graphql/resolvers/UserResolver.ts +++ b/backend/src/graphql/resolvers/UserResolver.ts @@ -1,13 +1,13 @@ // import jwt from 'jsonwebtoken' -import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql' +import { Resolver, Query, /* Mutation, */ Args, Arg, Field } from 'type-graphql' import CONFIG from '../../config' -import { ChangePasswordResponse } from '../models/ChangePasswordResponse' +import { ResetPasswordResponse } from '../models/ResetPasswordResponse' import { CheckUsernameResponse } from '../models/CheckUsernameResponse' import { CreateResponse } from '../models/CreateResponse' import { GetUserInfoResponse } from '../models/UserInfoData' import { LoginResponse } from '../models/LoginResponse' import { LoginViaVerificationCode } from '../models/LoginViaVerificationCode' -import { SendEmailResponse } from '../models/SendEmailResponse' +import { SendPasswordResetEmailResponse } from '../models/SendPasswordResetEmailResponse' import { UpdateUserInfosResponse } from '../models/UpdateUserInfosResponse' import { ChangePasswordArgs, @@ -66,17 +66,16 @@ export class UserResolver { return new LoginViaVerificationCode(result.data) } - /* @Query(() => LogoutResponse) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - async logout(@Arg('sessionId') sessionId: number): Promise { + @Query(() => String) + async logout(@Arg('sessionId') sessionId: number): Promise { const payload = { session_id: sessionId } - const result = apiPost(CONFIG.LOGIN_API_URL + 'logout', payload) + const result = await apiPost(CONFIG.LOGIN_API_URL + 'logout', payload) if (!result.success) { throw new Error(result.data) } - return result.data + return 'success' } -*/ + @Query(() => CreateResponse) async create( @Args() { email, firstName, lastName, password }: CreateUserArgs, @@ -96,17 +95,20 @@ export class UserResolver { return new CreateResponse(result.data) } - @Query(() => SendEmailResponse) - async sendEmail( + // TODO + @Query(() => SendPasswordResetEmailResponse) + async sendResetPasswordEmail( @Args() { email, emailText = 7, emailVerificationCodeType = 'resetPassword' }: SendEmailArgs, - ): Promise { + ): Promise { const payload = { email, email_text: emailText, email_verification_code_type: emailVerificationCodeType, } - return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload) + const response = await apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload) + if (!response.success) throw new Error(response.data) + return new SendPasswordResetEmailResponse(response.data) } @Query(() => GetUserInfoResponse) @@ -119,16 +121,19 @@ export class UserResolver { return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload) } - @Query(() => ChangePasswordResponse) - async changePassword(@Args() { sessionId, email, password }: ChangePasswordArgs): Promise { + @Query(() => ResetPasswordResponse) + async resetPassword( + @Args() + { sessionId, email, password }: ChangePasswordArgs, + ): Promise { const payload = { session_id: sessionId, email, password, } const result = await apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload) - if (result.success) return result.result.data.state - return result.result + if (!result.success) throw new Error(result.data) + return new ResetPasswordResponse(result.data) } @Query(() => UpdateUserInfosResponse) @@ -137,32 +142,40 @@ export class UserResolver { { sessionId, email, - firstName, - lastName, - username, - language, - password, - passwordNew, + firstName = '', + lastName = '', + username = '', + language = '', + password = '', + passwordNew = '', }: UpdateUserInfosArgs, - ): Promise { + ): Promise { const payload = { session_id: sessionId, email, update: { - 'User.first_name': firstName, - 'User.last_name': lastName, - // 'User.description': data.description, - 'User.username': username, - 'User.language': language, - 'User.password_old': password, - 'User.password': passwordNew, + 'User.first_name': firstName.length > 0 ? firstName : undefined, + 'User.last_name': lastName.length > 0 ? lastName : undefined, + 'User.username': username.length > 0 ? username : undefined, + 'User.language': language.length > 0 ? language : undefined, + 'User.password': passwordNew.length > 0 ? passwordNew : undefined, + 'User.password_old': password.length > 0 ? password : undefined, }, } - return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) + const result = await apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) + if (!result.success) throw new Error(result.data) + return new UpdateUserInfosResponse(result.data) } + // TODO @Query(() => CheckUsernameResponse) - async checkUsername(@Args() { username, groupId = 1 }: CheckUsernameArgs): Promise { - return apiGet(CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`) + async checkUsername( + @Args() { username, groupId = 1 }: CheckUsernameArgs, + ): Promise { + const response = await apiGet( + CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`, + ) + if (!response.success) throw new Error(response.data) + return new CheckUsernameResponse(response.data) } } diff --git a/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts b/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts index e69de29bb..361b35d9d 100644 --- a/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts +++ b/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts @@ -0,0 +1,3 @@ +export const MapVariableToColumnName = (object) => { + return null +} From f757cd2b76e4baaeac7011074b8995dfd4e2d089 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Tue, 3 Aug 2021 10:47:21 +0200 Subject: [PATCH 2/6] Withdrew state and errors from the UpdateUserInfosResponse object. --- backend/src/graphql/inputs/LoginUserInput.ts | 12 ++++----- .../graphql/models/UpdateUserInfosResponse.ts | 8 ------ backend/src/graphql/resolvers/UserResolver.ts | 27 +++++++++---------- .../helpers/MapVariableToColumnName.ts | 3 --- 4 files changed, 19 insertions(+), 31 deletions(-) delete mode 100644 backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts diff --git a/backend/src/graphql/inputs/LoginUserInput.ts b/backend/src/graphql/inputs/LoginUserInput.ts index 1f786702f..66f35980f 100644 --- a/backend/src/graphql/inputs/LoginUserInput.ts +++ b/backend/src/graphql/inputs/LoginUserInput.ts @@ -83,22 +83,22 @@ export class UpdateUserInfosArgs { email!: string @Field({ nullable: true }) - firstName?: string + firstName?: string | null @Field({ nullable: true }) - lastName?: string + lastName?: string | null @Field({ nullable: true }) - username?: string + username?: string | null @Field({ nullable: true }) - language?: string + language?: string | null @Field({ nullable: true }) - password?: string + password?: string | null @Field({ nullable: true }) - passwordNew?: string + passwordNew?: string | null } @ArgsType() diff --git a/backend/src/graphql/models/UpdateUserInfosResponse.ts b/backend/src/graphql/models/UpdateUserInfosResponse.ts index 820ee0011..765da5208 100644 --- a/backend/src/graphql/models/UpdateUserInfosResponse.ts +++ b/backend/src/graphql/models/UpdateUserInfosResponse.ts @@ -8,17 +8,9 @@ import { ObjectType, Field } from 'type-graphql' export class UpdateUserInfosResponse extends BaseEntity { constructor(json: any) { super() - this.state = json.state this.validValues = json.valid_values - this.errors = json.errors } - @Field(() => String) - state: string - @Field(() => Number) validValues: number - - @Field(() => [String]) - errors: [string] } diff --git a/backend/src/graphql/resolvers/UserResolver.ts b/backend/src/graphql/resolvers/UserResolver.ts index 5dc93f7bd..43d83938c 100644 --- a/backend/src/graphql/resolvers/UserResolver.ts +++ b/backend/src/graphql/resolvers/UserResolver.ts @@ -1,5 +1,5 @@ // import jwt from 'jsonwebtoken' -import { Resolver, Query, /* Mutation, */ Args, Arg, Field } from 'type-graphql' +import { Resolver, Query, Args, Arg } from 'type-graphql' import CONFIG from '../../config' import { ResetPasswordResponse } from '../models/ResetPasswordResponse' import { CheckUsernameResponse } from '../models/CheckUsernameResponse' @@ -142,24 +142,24 @@ export class UserResolver { { sessionId, email, - firstName = '', - lastName = '', - username = '', - language = '', - password = '', - passwordNew = '', + firstName = null, + lastName = null, + username = null, + language = null, + password = null, + passwordNew = null, }: UpdateUserInfosArgs, ): Promise { const payload = { session_id: sessionId, email, update: { - 'User.first_name': firstName.length > 0 ? firstName : undefined, - 'User.last_name': lastName.length > 0 ? lastName : undefined, - 'User.username': username.length > 0 ? username : undefined, - 'User.language': language.length > 0 ? language : undefined, - 'User.password': passwordNew.length > 0 ? passwordNew : undefined, - 'User.password_old': password.length > 0 ? password : undefined, + '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, }, } const result = await apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) @@ -167,7 +167,6 @@ export class UserResolver { return new UpdateUserInfosResponse(result.data) } - // TODO @Query(() => CheckUsernameResponse) async checkUsername( @Args() { username, groupId = 1 }: CheckUsernameArgs, diff --git a/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts b/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts deleted file mode 100644 index 361b35d9d..000000000 --- a/backend/src/graphql/resolvers/helpers/MapVariableToColumnName.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const MapVariableToColumnName = (object) => { - return null -} From 873996487d7b5417fd5aa7ede40a32afe9be3380 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 3 Aug 2021 10:55:43 +0200 Subject: [PATCH 3/6] Model for transactions and decay --- backend/src/apis/loginAPI.ts | 2 +- backend/src/graphql/models/Balance.ts | 6 +- backend/src/graphql/models/Decay.ts | 30 ++++++ backend/src/graphql/models/Transaction.ts | 98 ++++++++++++++++++- .../src/graphql/resolvers/BalanceResolver.ts | 16 +++ backend/src/index.ts | 4 +- 6 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 backend/src/graphql/models/Decay.ts create mode 100644 backend/src/graphql/resolvers/BalanceResolver.ts diff --git a/backend/src/apis/loginAPI.ts b/backend/src/apis/loginAPI.ts index 7160db68c..965b1ccfc 100644 --- a/backend/src/apis/loginAPI.ts +++ b/backend/src/apis/loginAPI.ts @@ -33,7 +33,7 @@ export const apiGet = async (url: string): Promise => { }) .catch((error) => { // eslint-disable-next-line no-console - console.log('IN apiGet.ERROR: ' + JSON.stringify({ success: false, result: error })) + console.log('IN apiGet.ERROR: ', { success: false, result: error }) return { success: false, data: error.message } }) } diff --git a/backend/src/graphql/models/Balance.ts b/backend/src/graphql/models/Balance.ts index ceb479b9c..e54bb3478 100644 --- a/backend/src/graphql/models/Balance.ts +++ b/backend/src/graphql/models/Balance.ts @@ -1,5 +1,3 @@ -/* 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' @@ -8,8 +6,8 @@ import { ObjectType, Field } from 'type-graphql' export class Balance extends BaseEntity { constructor(json: any) { super() - this.balance = json.balance - this.decay = json.decay + this.balance = Number(json.balance) + this.decay = Number(json.decay) this.decayDate = json.decay_date } diff --git a/backend/src/graphql/models/Decay.ts b/backend/src/graphql/models/Decay.ts new file mode 100644 index 000000000..af13ac193 --- /dev/null +++ b/backend/src/graphql/models/Decay.ts @@ -0,0 +1,30 @@ +import { Entity, BaseEntity, Column } from 'typeorm' +import { ObjectType, Field } from 'type-graphql' + +@Entity() +@ObjectType() +export class Decay extends BaseEntity { + constructor(json: any) { + super() + this.balance = Number(json.balance) + this.decayStart = json.decay_start + this.decayEnd = json.decay_end + this.decayDuration = json.decay_duration + } + + @Field(() => Number) + @Column() + balance: number + + @Field(() => Number) + @Column() + decayStart: number + + @Field(() => Number) + @Column() + decayEnd: number + + @Field(() => String) + @Column() + decayDuration: string +} diff --git a/backend/src/graphql/models/Transaction.ts b/backend/src/graphql/models/Transaction.ts index b638e797e..732dd9ec4 100644 --- a/backend/src/graphql/models/Transaction.ts +++ b/backend/src/graphql/models/Transaction.ts @@ -3,8 +3,100 @@ import { ObjectType, Field } from 'type-graphql' @Entity() @ObjectType() -export class Transaction extends BaseEntity { +export class TransactionList extends BaseEntity { + constructor(json: any) { + super() + this.gdtSum = Number(json.gdtSum) + this.count = json.count + this.balance = Number(json.balance) + this.decay = Number(json.decay) + this.decayDate = json.decay_date + this.transactions = json.transactions + } + + @Field(() => Number) + @Column() + gdtSum: number + + @Field(() => Number) + @Column() + count: number + + @Field(() => Number) + @Column() + balance: number + + @Field(() => Number) + @Column() + decay: number + @Field(() => String) - @Column({ length: 191 }) - email: 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 } diff --git a/backend/src/graphql/resolvers/BalanceResolver.ts b/backend/src/graphql/resolvers/BalanceResolver.ts new file mode 100644 index 000000000..31bed076c --- /dev/null +++ b/backend/src/graphql/resolvers/BalanceResolver.ts @@ -0,0 +1,16 @@ +import { Resolver, Query, /* Mutation, */ Args, Arg } from 'type-graphql' +import CONFIG from '../../config' +import { Balance } from '../models/Balance' +import { apiGet } from '../../apis/loginAPI' + +@Resolver() +export class BalanceResolver { + @Query(() => Balance) + async balance(@Arg('sessionId') sessionId: number): Promise { + const result = await apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId) + console.log(result) + if (!result.success) + throw new Error(result.data) + return new Balance(result.data) + } +} diff --git a/backend/src/index.ts b/backend/src/index.ts index b6e19f56d..d9a35fa40 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -8,7 +8,7 @@ import CONFIG from './config' // TODO move to extern // import { BookResolver } from './graphql/resolvers/BookResolver' import { UserResolver } from './graphql/resolvers/UserResolver' -import { CommunityTransactionResolver } from './graphql/resolvers/CommunityTransactionResolver' +import { BalanceResolver } from './graphql/resolvers/BalanceResolver' // import { GroupResolver } from './graphql/resolvers/GroupResolver' // TODO implement // import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; @@ -16,7 +16,7 @@ import { CommunityTransactionResolver } from './graphql/resolvers/CommunityTrans async function main() { // const connection = await createConnection() const schema = await buildSchema({ - resolvers: [/* BookResolver , GroupResolver, */ UserResolver, CommunityTransactionResolver], + resolvers: [UserResolver, BalanceResolver], }) // Graphiql interface From 68d46edcf607d8241992a8284764447e0163b8e2 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 3 Aug 2021 13:16:29 +0200 Subject: [PATCH 4/6] transaction lists are working --- backend/src/graphql/inputs/LoginUserInput.ts | 24 ++-- .../src/graphql/inputs/TransactionInput.ts | 2 +- backend/src/graphql/models/Balance.ts | 2 + backend/src/graphql/models/Decay.ts | 19 +-- backend/src/graphql/models/Transaction.ts | 131 ++++++++---------- .../src/graphql/resolvers/BalanceResolver.ts | 6 +- .../resolvers/CommunityTransactionResolver.ts | 57 -------- .../graphql/resolvers/TransactionResolver.ts | 19 +++ backend/src/graphql/resolvers/UserResolver.ts | 27 ++-- backend/src/index.ts | 5 +- 10 files changed, 118 insertions(+), 174 deletions(-) delete mode 100644 backend/src/graphql/resolvers/CommunityTransactionResolver.ts create mode 100644 backend/src/graphql/resolvers/TransactionResolver.ts diff --git a/backend/src/graphql/inputs/LoginUserInput.ts b/backend/src/graphql/inputs/LoginUserInput.ts index 66f35980f..68ddad628 100644 --- a/backend/src/graphql/inputs/LoginUserInput.ts +++ b/backend/src/graphql/inputs/LoginUserInput.ts @@ -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() diff --git a/backend/src/graphql/inputs/TransactionInput.ts b/backend/src/graphql/inputs/TransactionInput.ts index db010390a..049a9b2a9 100644 --- a/backend/src/graphql/inputs/TransactionInput.ts +++ b/backend/src/graphql/inputs/TransactionInput.ts @@ -1,7 +1,7 @@ import { ArgsType, Field } from 'type-graphql' @ArgsType() -export class TransactionInput { +export class TransactionListInput { @Field(() => Number) sessionId: number diff --git a/backend/src/graphql/models/Balance.ts b/backend/src/graphql/models/Balance.ts index e54bb3478..4897f3265 100644 --- a/backend/src/graphql/models/Balance.ts +++ b/backend/src/graphql/models/Balance.ts @@ -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' diff --git a/backend/src/graphql/models/Decay.ts b/backend/src/graphql/models/Decay.ts index af13ac193..3d918ce7a 100644 --- a/backend/src/graphql/models/Decay.ts +++ b/backend/src/graphql/models/Decay.ts @@ -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 } diff --git a/backend/src/graphql/models/Transaction.ts b/backend/src/graphql/models/Transaction.ts index 732dd9ec4..61670b06a 100644 --- a/backend/src/graphql/models/Transaction.ts +++ b/backend/src/graphql/models/Transaction.ts @@ -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 -} diff --git a/backend/src/graphql/resolvers/BalanceResolver.ts b/backend/src/graphql/resolvers/BalanceResolver.ts index 31bed076c..c483ad5c9 100644 --- a/backend/src/graphql/resolvers/BalanceResolver.ts +++ b/backend/src/graphql/resolvers/BalanceResolver.ts @@ -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 { 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) } } diff --git a/backend/src/graphql/resolvers/CommunityTransactionResolver.ts b/backend/src/graphql/resolvers/CommunityTransactionResolver.ts deleted file mode 100644 index 1fcc214e7..000000000 --- a/backend/src/graphql/resolvers/CommunityTransactionResolver.ts +++ /dev/null @@ -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 { - // 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 { - return apiGet( - `${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${sessionId}`, - ) - } - - @Query(() => String) - async send(@Args() { sessionId, email, amount, memo }: TransactionSendArgs): Promise { - 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 { - const payload = { - sessionId, - email, - amount, - targetDate, - memo, - auto_sign: true, - } - return apiPost(CONFIG.COMMUNITY_API_URL + 'createCoins/', payload) - } -} diff --git a/backend/src/graphql/resolvers/TransactionResolver.ts b/backend/src/graphql/resolvers/TransactionResolver.ts new file mode 100644 index 000000000..9834b62f8 --- /dev/null +++ b/backend/src/graphql/resolvers/TransactionResolver.ts @@ -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 { + 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) + } +} diff --git a/backend/src/graphql/resolvers/UserResolver.ts b/backend/src/graphql/resolvers/UserResolver.ts index 43d83938c..5791ccd15 100644 --- a/backend/src/graphql/resolvers/UserResolver.ts +++ b/backend/src/graphql/resolvers/UserResolver.ts @@ -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 { 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 { @@ -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 { 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 { 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) diff --git a/backend/src/index.ts b/backend/src/index.ts index d9a35fa40..8bf6dbebc 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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 From 628f0a541f0e473364b6c5390b8a7d0045046ac6 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 3 Aug 2021 13:35:44 +0200 Subject: [PATCH 5/6] sendCoins implemented --- .../graphql/resolvers/TransactionResolver.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolvers/TransactionResolver.ts b/backend/src/graphql/resolvers/TransactionResolver.ts index 9834b62f8..a2853f08a 100644 --- a/backend/src/graphql/resolvers/TransactionResolver.ts +++ b/backend/src/graphql/resolvers/TransactionResolver.ts @@ -1,8 +1,8 @@ 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' +import { TransactionListInput, TransactionSendArgs } from '../inputs/TransactionInput' +import { apiGet, apiPost } from '../../apis/loginAPI' @Resolver() export class TransactionResolver { @@ -16,4 +16,22 @@ export class TransactionResolver { if (!result.success) throw new Error(result.data) return new TransactionList(result.data) } + + @Query(() => String) + async sendCoins( + @Args() { sessionId, email, amount, memo }: TransactionSendArgs, + ): Promise { + const payload = { + session_id: sessionId, + email, + amount, + memo, + auto_sign: true, + } + const result = await apiPost(CONFIG.COMMUNITY_API_URL + 'sendCoins', payload) + if (!result.success) { + throw new Error(result.data) + } + return 'success' + } } From 800e4e04fd42feae17815c1119f448bd3b4b5ff7 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 3 Aug 2021 13:59:22 +0200 Subject: [PATCH 6/6] remove eom directives --- backend/src/apis/loginAPI.ts.old | 184 ------------------ backend/src/graphql/models/Balance.ts | 8 +- .../graphql/models/CheckUsernameResponse.ts | 5 +- backend/src/graphql/models/CreateResponse.ts | 16 -- backend/src/graphql/models/LoginResponse.ts | 7 +- .../models/LoginViaVerificationCode.ts | 7 +- .../graphql/models/ResetPasswordResponse.ts | 16 -- .../models/SendPasswordResetEmailResponse.ts | 5 +- .../graphql/models/UpdateUserInfosResponse.ts | 5 +- backend/src/graphql/models/User.ts | 18 +- backend/src/graphql/resolvers/UserResolver.ts | 16 +- 11 files changed, 13 insertions(+), 274 deletions(-) delete mode 100644 backend/src/apis/loginAPI.ts.old delete mode 100644 backend/src/graphql/models/CreateResponse.ts delete mode 100644 backend/src/graphql/models/ResetPasswordResponse.ts diff --git a/backend/src/apis/loginAPI.ts.old b/backend/src/apis/loginAPI.ts.old deleted file mode 100644 index 8e4b5e040..000000000 --- a/backend/src/apis/loginAPI.ts.old +++ /dev/null @@ -1,184 +0,0 @@ -import axios from 'axios' -import { graphql } from 'graphql' -import CONFIG from '../config' -import { User } from '../graphql/models/User' -import { LoginUserInput } from '../graphql/inputs/LoginUserInput' -// eslint-disable-next-line no-unused-vars -// import regeneratorRuntime from 'regenerator-runtime' - -// control email-text sended with email verification code -const EMAIL_TYPE = { - DEFAULT: 2, // if user has registered directly - ADMIN: 5, // if user was registered by an admin -} - -const apiGet = async (url: string) => { - try { - const result = await axios.get(url) - if (result.status !== 200) { - throw new Error('HTTP Status Error ' + result.status) - } - if (!['success', 'warning'].includes(result.data.state)) { - throw new Error(result.data.msg) - } - return { success: true, result } - } catch (error) { - return { success: false, result: error } - } -} - -const apiPost = async (url: string, payload: any): Promise => { - try { - const result = await axios.post(url, payload) - if (result.status !== 200) { - throw new Error('HTTP Status Error ' + result.status) - } - if (result.data.state === 'warning') { - return { success: true, result: result.data.errors } - } - if (result.data.state !== 'success') { - throw new Error(result.data.msg) - } - return { success: true, result } - } catch (error) { - return { success: false, result: error } - } -} - -interface NetworkInfosResult { - state: string - msg?: string - errors: string[] - data: { - groups?: string[] - } -} - -interface LoginResult { - state: string - msg?: string - details?: number - info?: string - user?: User - // eslint-disable-next-line camelcase - session_id?: number -} - -const loginAPI = { - login: async (login: LoginUserInput): Promise => { - return (await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', login)).result.data - }, - logout: async (sessionId: number): Promise => { - const payload: any = { session_id: sessionId } - return apiPost(CONFIG.LOGIN_API_URL + 'logout', payload) - }, - create: async ( - email: string, - firstName: string, - lastName: string, - password: string, - ): Promise => { - const payload: any = { - email, - first_name: firstName, - last_name: lastName, - password, - emailType: EMAIL_TYPE.DEFAULT, - login_after_register: true, - } - return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload) - }, - sendEmail: async ( - email: string, - email_text = 7, - email_verification_code_type = 'resetPassword', - ): Promise => { - const payload: any = { - email, - email_text, - email_verification_code_type, - } - return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload) - }, - loginViaEmailVerificationCode: async (optin: number): Promise => { - return apiGet( - CONFIG.LOGIN_API_URL + 'loginViaEmailVerificationCode?emailVerificationCode=' + optin, - ) - }, - getUserInfos: async (sessionId: number, email: string): Promise => { - const payload: any = { - session_id: sessionId, - email: email, - ask: ['user.first_name', 'user.last_name'], - } - return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload) - }, - updateUserInfos: async (sessionId: number, email: string, data: any): Promise => { - const payload: any = { - session_id: sessionId, - email, - update: { - 'User.first_name': data.firstName, - 'User.last_name': data.lastName, - 'User.description': data.description, - }, - } - return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) - }, - changePassword: async (sessionId: number, email: string, password: string): Promise => { - const payload: any = { - session_id: sessionId, - email, - password, - } - return apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload) - }, - changePasswordProfile: async ( - sessionId: number, - email: string, - password: string, - passwordNew: string, - ): Promise => { - const payload: any = { - session_id: sessionId, - email, - update: { - 'User.password_old': password, - 'User.password': passwordNew, - }, - } - return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) - }, - changeUsernameProfile: async ( - sessionId: number, - email: string, - username: string, - ): Promise => { - const payload: any = { - session_id: sessionId, - email, - update: { - 'User.username': username, - }, - } - return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) - }, - updateLanguage: async (sessionId: number, email: string, language: string): Promise => { - const payload: any = { - session_id: sessionId, - email, - update: { - 'User.language': language, - }, - } - return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) - }, - checkUsername: async (username: string, groupId = 1): Promise => { - return apiGet(CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`) - }, - getNetworkInfos: async (ask: string[]): Promise => { - return (await apiPost(CONFIG.LOGIN_API_URL + `networkInfos`, { ask: ask })).result.data - }, -} - -export { loginAPI, NetworkInfosResult, LoginResult } diff --git a/backend/src/graphql/models/Balance.ts b/backend/src/graphql/models/Balance.ts index 4897f3265..93d497e0c 100644 --- a/backend/src/graphql/models/Balance.ts +++ b/backend/src/graphql/models/Balance.ts @@ -1,27 +1,21 @@ /* 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' -@Entity() @ObjectType() -export class Balance extends BaseEntity { +export class Balance { constructor(json: any) { - super() this.balance = Number(json.balance) this.decay = Number(json.decay) this.decayDate = json.decay_date } @Field(() => Number) - @Column() balance: number @Field(() => Number) - @Column() decay: number @Field(() => String) - @Column() decayDate: string } diff --git a/backend/src/graphql/models/CheckUsernameResponse.ts b/backend/src/graphql/models/CheckUsernameResponse.ts index de5724c8d..b3186ffcf 100644 --- a/backend/src/graphql/models/CheckUsernameResponse.ts +++ b/backend/src/graphql/models/CheckUsernameResponse.ts @@ -1,13 +1,10 @@ /* 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 CheckUsernameResponse extends BaseEntity { +export class CheckUsernameResponse { constructor(json: any) { - super() this.state = json.state this.msg = json.msg this.groupId = json.group_id diff --git a/backend/src/graphql/models/CreateResponse.ts b/backend/src/graphql/models/CreateResponse.ts deleted file mode 100644 index 144d6456c..000000000 --- a/backend/src/graphql/models/CreateResponse.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 CreateResponse extends BaseEntity { - constructor(json: any) { - super() - this.state = json.state - } - - @Field(() => String) - state: string -} diff --git a/backend/src/graphql/models/LoginResponse.ts b/backend/src/graphql/models/LoginResponse.ts index 2abe1ef96..258784b75 100644 --- a/backend/src/graphql/models/LoginResponse.ts +++ b/backend/src/graphql/models/LoginResponse.ts @@ -1,25 +1,20 @@ /* 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' import { User } from './User' // temporaray solution until we have JWT implemented -@Entity() @ObjectType() -export class LoginResponse extends BaseEntity { +export class LoginResponse { constructor(json: any) { - super() this.sessionId = json.session_id this.user = new User(json.user) } @Field(() => Number) - @Column() sessionId: number @Field(() => User) - @Column() user: User } diff --git a/backend/src/graphql/models/LoginViaVerificationCode.ts b/backend/src/graphql/models/LoginViaVerificationCode.ts index bd0d66781..61286ca0e 100644 --- a/backend/src/graphql/models/LoginViaVerificationCode.ts +++ b/backend/src/graphql/models/LoginViaVerificationCode.ts @@ -1,22 +1,17 @@ /* 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' -@Entity() @ObjectType() -export class LoginViaVerificationCode extends BaseEntity { +export class LoginViaVerificationCode { constructor(json: any) { - super() this.sessionId = json.session_id this.email = json.user.email } @Field(() => Number) - @Column() sessionId: number @Field(() => String) - @Column() email: string } diff --git a/backend/src/graphql/models/ResetPasswordResponse.ts b/backend/src/graphql/models/ResetPasswordResponse.ts deleted file mode 100644 index aae209059..000000000 --- a/backend/src/graphql/models/ResetPasswordResponse.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 ResetPasswordResponse extends BaseEntity { - constructor(json: any) { - super() - this.state = json.state - } - - @Field(() => String) - state: string -} diff --git a/backend/src/graphql/models/SendPasswordResetEmailResponse.ts b/backend/src/graphql/models/SendPasswordResetEmailResponse.ts index f426d5245..d387efede 100644 --- a/backend/src/graphql/models/SendPasswordResetEmailResponse.ts +++ b/backend/src/graphql/models/SendPasswordResetEmailResponse.ts @@ -1,13 +1,10 @@ /* 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 SendPasswordResetEmailResponse extends BaseEntity { +export class SendPasswordResetEmailResponse { constructor(json: any) { - super() this.state = json.state this.msg = json.msg } diff --git a/backend/src/graphql/models/UpdateUserInfosResponse.ts b/backend/src/graphql/models/UpdateUserInfosResponse.ts index 765da5208..0e41f21cb 100644 --- a/backend/src/graphql/models/UpdateUserInfosResponse.ts +++ b/backend/src/graphql/models/UpdateUserInfosResponse.ts @@ -1,13 +1,10 @@ /* 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 UpdateUserInfosResponse extends BaseEntity { +export class UpdateUserInfosResponse { constructor(json: any) { - super() this.validValues = json.valid_values } diff --git a/backend/src/graphql/models/User.ts b/backend/src/graphql/models/User.ts index 68543bf09..47037d483 100644 --- a/backend/src/graphql/models/User.ts +++ b/backend/src/graphql/models/User.ts @@ -1,18 +1,15 @@ /* 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' -@Entity() @ObjectType() -export class User extends BaseEntity { +export class User { /* @Field(() => ID) @PrimaryGeneratedColumn() id: number */ constructor(json: any) { - super() this.email = json.email this.firstName = json.first_name this.lastName = json.last_name @@ -22,62 +19,49 @@ export class User extends BaseEntity { } @Field(() => String) - @Column({ length: 191 }) email: string @Field(() => String) - @Column({ length: 150 }) firstName: string @Field(() => String) - @Column() lastName: string @Field(() => String) - @Column() username: string @Field(() => String) - @Column('text') description: string /* @Field(() => String) - @Column({ length: 64 }) pubkey: string // not sure about the type here. Maybe better to have a string @Field(() => number) - @Column({ type: 'datetime' }) created: number @Field(() => Boolean) - @Column({ default: false }) emailChecked: boolean @Field(() => Boolean) - @Column({ default: false }) passphraseShown: boolean */ @Field(() => String) - @Column({ default: 'de' }) language: string /* @Field(() => Boolean) - @Column({ default: false }) disabled: boolean */ /* I suggest to have a group as type here @Field(() => ID) - @Column() groupId: number // what is puvlisherId? @Field(() => ID) - @Column({ default: 0 }) publisherId: number */ } diff --git a/backend/src/graphql/resolvers/UserResolver.ts b/backend/src/graphql/resolvers/UserResolver.ts index 5791ccd15..4361bd0ed 100644 --- a/backend/src/graphql/resolvers/UserResolver.ts +++ b/backend/src/graphql/resolvers/UserResolver.ts @@ -1,9 +1,7 @@ // import jwt from 'jsonwebtoken' import { Resolver, Query, Args, Arg } from 'type-graphql' import CONFIG from '../../config' -import { ResetPasswordResponse } from '../models/ResetPasswordResponse' import { CheckUsernameResponse } from '../models/CheckUsernameResponse' -import { CreateResponse } from '../models/CreateResponse' import { GetUserInfoResponse } from '../models/UserInfoData' import { LoginResponse } from '../models/LoginResponse' import { LoginViaVerificationCode } from '../models/LoginViaVerificationCode' @@ -74,10 +72,8 @@ export class UserResolver { return 'success' } - @Query(() => CreateResponse) - async create( - @Args() { email, firstName, lastName, password }: CreateUserArgs, - ): Promise { + @Query(() => String) + async create(@Args() { email, firstName, lastName, password }: CreateUserArgs): Promise { const payload = { email, first_name: firstName, @@ -90,7 +86,7 @@ export class UserResolver { if (!result.success) { throw new Error(result.data) } - return new CreateResponse(result.data) + return 'success' } // TODO @@ -120,11 +116,11 @@ export class UserResolver { return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload) } - @Query(() => ResetPasswordResponse) + @Query(() => String) async resetPassword( @Args() { sessionId, email, password }: ChangePasswordArgs, - ): Promise { + ): Promise { const payload = { session_id: sessionId, email, @@ -132,7 +128,7 @@ export class UserResolver { } const result = await apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload) if (!result.success) throw new Error(result.data) - return new ResetPasswordResponse(result.data) + return 'sucess' } @Query(() => UpdateUserInfosResponse)