From d8cbf10b30a107d513282a261fd271abe8a961cd Mon Sep 17 00:00:00 2001 From: YanceyOfficial Date: Fri, 27 Dec 2019 14:42:35 +0800 Subject: [PATCH] feat: define PlayerResolver --- src/player/player.resolver.ts | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/player/player.resolver.ts b/src/player/player.resolver.ts index 38a07ea9..79b55b31 100644 --- a/src/player/player.resolver.ts +++ b/src/player/player.resolver.ts @@ -1,4 +1,44 @@ -import { Controller } from '@nestjs/common' +import { Args, Query, Resolver, Mutation } from '@nestjs/graphql' +import { ID } from 'type-graphql' +import { PlayerService } from './player.service' +import { PlayerModel } from './models/player.model' +import { BatchDeleteModel } from '../database/models/database.model' +import { CreatePlayerInput } from './dtos/create-player.input' +import { UpdatePlayerInput } from './dtos/update-player.input' -@Controller('player') -export class PlayerResolver {} +@Resolver(() => PlayerModel) +export class PlayerResolver { + constructor(private readonly playerService: PlayerService) { + this.playerService = playerService + } + + @Query(() => [PlayerModel]) + public async getPlayer() { + return this.playerService.findAll() + } + + @Query(() => PlayerModel) + public async getPlayerById(@Args({ name: 'id', type: () => ID }) id: string) { + return this.playerService.findOneById(id) + } + + @Mutation(() => PlayerModel) + public async createPlayer(@Args('input') input: CreatePlayerInput) { + return this.playerService.create(input) + } + + @Mutation(() => PlayerModel) + public async updatePlayerById(@Args('input') input: UpdatePlayerInput) { + return this.playerService.update(input) + } + + @Mutation(() => PlayerModel) + public async deletePlayerById(@Args({ name: 'id', type: () => ID }) id: string) { + return this.playerService.deleteOneById(id) + } + + @Mutation(() => BatchDeleteModel) + public async deletePlayer(@Args({ name: 'ids', type: () => [ID] }) ids: string[]) { + return this.playerService.batchDelete(ids) + } +}