mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { Resolver, Query, Mutation, Arg } from 'type-graphql'
|
|
import { User } from '../models/User'
|
|
// import { CreateBookInput } from '../inputs/CreateBookInput'
|
|
// import { UpdateBookInput } from '../inputs/UpdateBookInput'
|
|
|
|
@Resolver()
|
|
export class UserResolver {
|
|
@Query(() => [User])
|
|
users(): Promise<User[]> {
|
|
return User.find()
|
|
}
|
|
|
|
@Query(() => User)
|
|
user(@Arg('id') id: string): Promise<User | undefined> {
|
|
return User.findOne({ where: { id } })
|
|
}
|
|
|
|
/*
|
|
@Mutation(() => User)
|
|
async createBook(@Arg('data') data: CreateBookInput) {
|
|
const book = User.create(data)
|
|
await book.save()
|
|
return book
|
|
}
|
|
|
|
@Mutation(() => Book)
|
|
async updateBook(@Arg('id') id: string, @Arg('data') data: UpdateBookInput) {
|
|
const book = await Book.findOne({ where: { id } })
|
|
if (!book) throw new Error('Book not found!')
|
|
Object.assign(book, data)
|
|
await book.save()
|
|
return book
|
|
}
|
|
*/
|
|
@Mutation(() => Boolean)
|
|
async deleteUser(@Arg('id') id: string): Promise<boolean> {
|
|
const user = await User.findOne({ where: { id } })
|
|
if (!user) throw new Error('User not found!')
|
|
await user.remove()
|
|
return true
|
|
}
|
|
}
|