Delete button sends call to Adminresolver deletePendingCreation.

This commit is contained in:
elweyn 2021-12-06 13:45:50 +01:00
parent b47bf3d41d
commit 48b7c9a0af
3 changed files with 27 additions and 8 deletions

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const deletePendingCreation = gql`
mutation ($id: Float!) {
deletePendingCreation(id: $id)
}
`

View File

@ -12,6 +12,7 @@
<script>
import UserTable from '../components/UserTable.vue'
import { getPendingCreations } from '../graphql/getPendingCreations'
import { deletePendingCreation } from '../graphql/deletePendingCreation'
export default {
name: 'CreationConfirm',
@ -57,11 +58,23 @@ export default {
findArr = this.confirmResult.find((arr) => arr.id === e.id)
index = this.confirmResult.indexOf(findArr)
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
// console.log('findArr', findArr)
this.$apollo
.mutate({
mutation: deletePendingCreation,
variables: {
id: findArr.id,
},
})
.then((result) => {
index = this.confirmResult.indexOf(findArr)
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
})
.catch((error) => {
this.$toasted.error(error.message)
})
}
},
getPendingCreations() {

View File

@ -130,9 +130,8 @@ export class AdminResolver {
@Mutation(() => Boolean)
async deletePendingCreation(@Arg('id') id: number): Promise<boolean> {
const pendingCreationRepository = getCustomRepository(PendingCreationRepository)
const entity = await pendingCreationRepository.findOne(id)
if (!entity) throw new Error('Not pending creation with this id.')
const res = await pendingCreationRepository.manager.remove(entity)
const entity = await pendingCreationRepository.findOneOrFail(id)
const res = await pendingCreationRepository.delete(entity)
return !!res
}
}