Skip to content
Snippets Groups Projects
items.controller.ts 1.12 KiB
Newer Older
Homar Franquesa Agil's avatar
Homar Franquesa Agil committed
import { 
    Body,
    Controller,
    Delete,
    Get,
    Param,
    Post,
    Put,
    UseGuards,
} from '@nestjs/common';
import { ItemsService } from './items.service';
import { Items } from '../items';
import { Item } from '../item';
//import { LocalAuthGuard } from '../auth/local-auth.guard';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('items')
export class ItemsController {
    constructor(private readonly itemsService: ItemsService) {}


    @Get()
    async findAll(): Promise<Items> {
        return this.itemsService.findAll();
    }
    @Get(':id')
    async find(@Param('id') id: number): Promise<Item> {
        return this.itemsService.find(id);
    }

    @UseGuards(JwtAuthGuard)
    @Post()
    async create(@Body('item') item: Item): Promise<void> {
        this.itemsService.create(item);
    }

    @UseGuards(JwtAuthGuard)
    @Put()
    async update(@Body('item') item: Item): Promise<void> {
        this.itemsService.update(item);
    }

    @UseGuards(JwtAuthGuard)
    @Delete(':id')
    async delete(@Param('id') id: number): Promise<void> {
        this.itemsService.delete(id);
    }
}