diff --git a/admin/src/components/EditCreationFormular.vue b/admin/src/components/EditCreationFormular.vue index aa60cced7..896101e41 100644 --- a/admin/src/components/EditCreationFormular.vue +++ b/admin/src/components/EditCreationFormular.vue @@ -232,6 +232,7 @@ export default { } if (this.type === 'singleCreation') { this.submitObj = { + id: this.item.id, email: this.item.email, creationDate: this.radioSelected.long, amount: Number(this.value), @@ -247,14 +248,20 @@ export default { variables: this.submitObj, }) .then((result) => { - this.$emit('update-user-data', this.item, result.data.createPendingCreation) + this.$emit('update-user-data', this.item, result.data.updatePendingCreation.creation) + this.$emit('update-creation-data', { + amount: Number(result.data.updatePendingCreation.amount), + date: result.data.updatePendingCreation.date, + memo: result.data.updatePendingCreation.memo, + moderator: Number(result.data.updatePendingCreation.moderator), + }) this.$toasted.success( `Offene schöpfung (${this.value} GDD) für ${this.item.email} wurde geändert, liegt zur Bestätigung bereit`, ) this.submitObj = null this.createdIndex = null // das creation Formular reseten - this.$refs.creationForm.reset() + this.$refs.updateCreationForm.reset() // Den geschöpften Wert auf o setzen this.value = 0 }) @@ -262,7 +269,7 @@ export default { this.$toasted.error(error.message) this.submitObj = null // das creation Formular reseten - this.$refs.creationForm.reset() + this.$refs.updateCreationForm.reset() // Den geschöpften Wert auf o setzen this.value = 0 }) diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index f2bc2e43b..2c5c1c508 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -240,9 +240,18 @@ export default { row.toggleDetails() }, updateCreationData(data) { - this.creationUserData = { - ...data, - } + // console.log('updateCreationData this.creationUserData11=> ', this.creationUserData) + // console.log('updateCreationData data=> ', data) + // this.creationUserData = { + // ...this.creationUserData, + // ...data, + // } + // console.log('updateCreationData this.creationUserData22=> ', this.creationUserData) + + this.creationUserData.amount = data.amount + this.creationUserData.date = data.date + this.creationUserData.memo = data.memo + this.creationUserData.moderator = data.moderator }, updateUserData(rowItem, newCreation) { rowItem.creation = newCreation diff --git a/admin/src/graphql/updatePendingCreation.js b/admin/src/graphql/updatePendingCreation.js index 5c63b4674..b137d961c 100644 --- a/admin/src/graphql/updatePendingCreation.js +++ b/admin/src/graphql/updatePendingCreation.js @@ -1,13 +1,27 @@ import gql from 'graphql-tag' export const updatePendingCreation = gql` - query ($email: String!, $amount: Int!, $memo: String!, $creationDate: String!, $moderator: Int!) { + mutation ( + $id: Int! + $email: String! + $amount: Int! + $memo: String! + $creationDate: String! + $moderator: Int! + ) { updatePendingCreation( + id: $id email: $email amount: $amount memo: $memo creationDate: $creationDate moderator: $moderator - ) + ) { + amount + date + memo + creation + moderator + } } ` diff --git a/backend/src/graphql/arg/UpdatePendingCreationArgs.ts b/backend/src/graphql/arg/UpdatePendingCreationArgs.ts new file mode 100644 index 000000000..bde7133aa --- /dev/null +++ b/backend/src/graphql/arg/UpdatePendingCreationArgs.ts @@ -0,0 +1,22 @@ +import { ArgsType, Field, Int } from 'type-graphql' + +@ArgsType() +export default class CreatePendingCreationArgs { + @Field(() => Int) + id: number + + @Field(() => String) + email: string + + @Field(() => Int) + amount: number + + @Field(() => String) + memo: string + + @Field(() => String) + creationDate: string + + @Field(() => Int) + moderator: number +} diff --git a/backend/src/graphql/model/UpdatePendingCreation.ts b/backend/src/graphql/model/UpdatePendingCreation.ts new file mode 100644 index 000000000..c8033f86e --- /dev/null +++ b/backend/src/graphql/model/UpdatePendingCreation.ts @@ -0,0 +1,19 @@ +import { ObjectType, Field } from 'type-graphql' + +@ObjectType() +export class UpdatePendingCreation { + @Field(() => Date) + date: Date + + @Field(() => String) + memo: string + + @Field(() => Number) + amount: number + + @Field(() => Number) + moderator: number + + @Field(() => [Number]) + creation: number[] +} diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 51b018897..245809ffc 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -2,11 +2,13 @@ import { Resolver, Query, Arg, Args, Authorized, Mutation } from 'type-graphql' import { getCustomRepository, Raw } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { PendingCreation } from '../model/PendingCreation' +import { UpdatePendingCreation } from '../model/UpdatePendingCreation' import { RIGHTS } from '../../auth/RIGHTS' import { TransactionCreationRepository } from '../../typeorm/repository/TransactionCreation' import { PendingCreationRepository } from '../../typeorm/repository/PendingCreation' import { UserRepository } from '../../typeorm/repository/User' import CreatePendingCreationArgs from '../arg/CreatePendingCreationArgs' +import UpdatePendingCreationArgs from '../arg/UpdatePendingCreationArgs' import moment from 'moment' import { LoginPendingTasksAdmin } from '@entity/LoginPendingTasksAdmin' @@ -30,6 +32,7 @@ export class AdminResolver { return adminUsers } + @Authorized([RIGHTS.SEARCH_USERS]) @Mutation(() => [Number]) async createPendingCreation( @Args() { email, amount, memo, creationDate, moderator }: CreatePendingCreationArgs, @@ -54,6 +57,55 @@ export class AdminResolver { return await getUserCreations(user.id) } + // @Authorized([RIGHTS.SEARCH_USERS]) + @Mutation(() => UpdatePendingCreation) + async updatePendingCreation( + @Args() { id, email, amount, memo, creationDate, moderator }: UpdatePendingCreationArgs, + ): Promise { + console.log('UpdatePendingCreationArgs', { id, email, amount, memo, creationDate, moderator }) + const userRepository = getCustomRepository(UserRepository) + const user = await userRepository.findByEmail(email) + + const pendingCreationRepository = getCustomRepository(PendingCreationRepository) + const updatedCreation = await pendingCreationRepository.findOneOrFail({ id }) + console.log('updatedCreation', updatedCreation) + + if (updatedCreation.userId !== user.id) + throw new Error('user of the pending creation and send user does not correspond') + + updatedCreation.amount = BigInt(amount * 10000) + updatedCreation.memo = memo + updatedCreation.date = new Date(creationDate) + updatedCreation.moderator = moderator + + await pendingCreationRepository.save(updatedCreation) + const result = new UpdatePendingCreation() + result.amount = parseInt(updatedCreation.amount.toString()) + result.memo = updatedCreation.memo + result.date = updatedCreation.date + result.moderator = updatedCreation.moderator + result.creation = await getUserCreations(user.id) + + console.log('result', result) + return result + + // const creations = await getUserCreations(user.id) + // const creationDateObj = new Date(creationDate) + // if (isCreationValid(creations, amount, creationDateObj)) { + // const pendingCreationRepository = getCustomRepository(PendingCreationRepository) + // const loginPendingTaskAdmin = pendingCreationRepository.create() + // loginPendingTaskAdmin.userId = user.id + // loginPendingTaskAdmin.amount = BigInt(amount * 10000) + // loginPendingTaskAdmin.created = new Date() + // loginPendingTaskAdmin.date = creationDateObj + // loginPendingTaskAdmin.memo = memo + // loginPendingTaskAdmin.moderator = moderator + // + // pendingCreationRepository.save(loginPendingTaskAdmin) + // } + // return await getUserCreations(user.id) + } + @Query(() => [PendingCreation]) async getPendingCreations(): Promise { const pendingCreationRepository = getCustomRepository(PendingCreationRepository)