Finalizing the mass creation.

This commit is contained in:
ogerly 2021-12-09 14:14:49 +01:00 committed by elweyn
parent 5ca221a0c0
commit 79fb25d51e
4 changed files with 89 additions and 13 deletions

View File

@ -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)

View File

@ -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
}
}
`

View File

@ -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[]
}

View File

@ -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<boolean> {
pendingCreations.forEach((pendingCreation) => {
this.createPendingCreation(pendingCreation).catch((error) => {
console.log('pendingCreation ' + JSON.stringify(pendingCreation) + ' had an error ' + error)
})
): Promise<CreatePendingCreations> {
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])