diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index d84056f18..02b8f1ad8 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -236,14 +236,21 @@ export default { variables: { pendingCreations: this.submitObj, }, + fetchPolicy: 'no-cache', }) - .then(() => { - this.$store.commit('openCreationsPlus', this.submitObj.length) + .then((result) => { + console.log('result', result) + this.$store.commit( + 'openCreationsPlus', + result.data.createPendingCreations.successfulCreation.length, + ) + if (result.data.createPendingCreations.failedCreation.length > 0) { + result.data.createPendingCreations.failedCreation.forEach((failed) => { + this.$toasted.error('Could not created PendingCreation for ' + failed) + }) + } this.$emit('remove-all-bookmark') }) - .catch(() => { - console.log('Fehler bei der mehrfach Schöpfung') - }) // $store - offene Schöpfungen hochzählen // this.$store.commit('openCreationsPlus', i) diff --git a/admin/src/graphql/createPendingCreations.js b/admin/src/graphql/createPendingCreations.js index 50a2b049c..95d60bc9a 100644 --- a/admin/src/graphql/createPendingCreations.js +++ b/admin/src/graphql/createPendingCreations.js @@ -2,6 +2,10 @@ import gql from 'graphql-tag' export const createPendingCreations = gql` mutation ($pendingCreations: [CreatePendingCreationArgs!]!) { - createPendingCreations(pendingCreations: $pendingCreations) + createPendingCreations(pendingCreations: $pendingCreations) { + success + successfulCreation + failedCreation + } } ` diff --git a/backend/src/graphql/model/CreatePendingCreations.ts b/backend/src/graphql/model/CreatePendingCreations.ts new file mode 100644 index 000000000..eeb6b13d3 --- /dev/null +++ b/backend/src/graphql/model/CreatePendingCreations.ts @@ -0,0 +1,19 @@ +import { ObjectType, Field, Int } from 'type-graphql' + +@ObjectType() +export class CreatePendingCreations { + constructor() { + this.success = false + this.successfulCreation = [] + this.failedCreation = [] + } + + @Field(() => Boolean) + success: boolean + + @Field(() => [String]) + successfulCreation: string[] + + @Field(() => [String]) + failedCreation: string[] +} diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index bfab633b9..a08552844 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -2,6 +2,7 @@ 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 { CreatePendingCreations } from '../model/CreatePendingCreations' import { UpdatePendingCreation } from '../model/UpdatePendingCreation' import { RIGHTS } from '../../auth/RIGHTS' import { TransactionRepository } from '../../typeorm/repository/Transaction' @@ -63,17 +64,62 @@ export class AdminResolver { } // @Authorized([RIGHTS.SEARCH_USERS]) - @Mutation(() => Boolean) + @Mutation(() => CreatePendingCreations) async createPendingCreations( @Arg('pendingCreations', () => [CreatePendingCreationArgs]) pendingCreations: CreatePendingCreationArgs[], - ): Promise { - pendingCreations.forEach((pendingCreation) => { - this.createPendingCreation(pendingCreation).catch((error) => { - console.log('pendingCreation ' + JSON.stringify(pendingCreation) + ' had an error ' + error) - }) + ): Promise { + let success = false + const successfulCreation: string[] = [] + const failedCreation: string[] = [] + for (const pendingCreation of pendingCreations) { + await this.createPendingCreation(pendingCreation) + .then((result) => { + console.log('Successfuly created ' + JSON.stringify(pendingCreation) + ' ' + result) + successfulCreation.push(pendingCreation.email) + success = true + }) + .catch(() => { + console.log('Failed to creat ' + JSON.stringify(pendingCreation)) + failedCreation.push(pendingCreation.email) + }) + } + // await Promise.all( + // pendingCreations.map(async (pendingCreation) => { + // await this.createPendingCreation(pendingCreation) + // .then((result) => { + // console.log('Successfuly created ' + JSON.stringify(pendingCreation) + ' ' + result) + // successfulCreation.push(pendingCreation.email) + // success = true + // }) + // .catch(() => { + // console.log('Failed to creat ' + JSON.stringify(pendingCreation)) + // failedCreation.push(pendingCreation.email) + // }) + // }), + // ) + // await pendingCreations.forEach(async (pendingCreation) => { + // await this.createPendingCreation(pendingCreation) + // .then((result) => { + // console.log('Successfuly created ' + JSON.stringify(pendingCreation) + ' ' + result) + // successfulCreation.push(pendingCreation.email) + // success = true + // }) + // .catch(() => { + // console.log('Failed to creat ' + JSON.stringify(pendingCreation)) + // failedCreation.push(pendingCreation.email) + // }) + // }) + console.log('createPendingCreations', { + success, + successfulCreation, + failedCreation, }) - return true + return { + success, + successfulCreation, + failedCreation, + } } // @Authorized([RIGHTS.SEARCH_USERS])