2025-04-02 13:54:50 -06:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
Param,
|
|
|
|
|
ParseIntPipe,
|
|
|
|
|
Patch,
|
|
|
|
|
Post,
|
|
|
|
|
Query,
|
|
|
|
|
} from '@nestjs/common';
|
2025-04-01 15:07:11 -06:00
|
|
|
import { QrService } from './qr.service';
|
|
|
|
|
import { Qr } from './qr.entity';
|
|
|
|
|
import { CreateQrDto } from './dto/create-qr.dto';
|
|
|
|
|
import { UpdateQrDto } from './dto/update.qr.dto';
|
2025-04-02 13:54:50 -06:00
|
|
|
import { ApiOperation, ApiQuery } from '@nestjs/swagger';
|
2025-04-01 15:07:11 -06:00
|
|
|
|
|
|
|
|
@Controller('qr')
|
|
|
|
|
export class QrController {
|
2025-04-02 13:54:50 -06:00
|
|
|
constructor(private qrService: QrService) {}
|
2025-04-01 15:07:11 -06:00
|
|
|
|
2025-04-02 13:54:50 -06:00
|
|
|
@Get('generate')
|
|
|
|
|
@ApiOperation({ summary: 'Genera un código QR a partir de un texto' })
|
|
|
|
|
@ApiQuery({
|
|
|
|
|
name: 'text',
|
|
|
|
|
required: true,
|
|
|
|
|
description: 'Texto a codificar en el QR',
|
|
|
|
|
})
|
|
|
|
|
async generateQRCode(@Query('text') text: string): Promise<string> {
|
|
|
|
|
return this.qrService.generateQRCode(text);
|
|
|
|
|
}
|
2025-04-01 15:07:11 -06:00
|
|
|
|
2025-04-02 13:54:50 -06:00
|
|
|
@Get()
|
|
|
|
|
getQrs(): Promise<Qr[]> {
|
|
|
|
|
return this.qrService.getQrs();
|
|
|
|
|
}
|
2025-04-01 15:07:11 -06:00
|
|
|
|
2025-04-02 13:54:50 -06:00
|
|
|
@Get(':id')
|
|
|
|
|
getQr(@Param('id', ParseIntPipe) id: number) {
|
|
|
|
|
return this.qrService.getQr(id);
|
|
|
|
|
}
|
2025-04-01 15:07:11 -06:00
|
|
|
|
2025-04-02 13:54:50 -06:00
|
|
|
@Post() //en el body ValidationPipe
|
|
|
|
|
createQr(@Body() newQr: CreateQrDto) {
|
|
|
|
|
return this.qrService.createQr(newQr);
|
|
|
|
|
}
|
2025-04-01 15:07:11 -06:00
|
|
|
|
2025-04-02 13:54:50 -06:00
|
|
|
@Delete(':id')
|
|
|
|
|
deleteQr(@Param('id', ParseIntPipe) id: number) {
|
|
|
|
|
return this.qrService.deleteQr(id);
|
|
|
|
|
}
|
2025-04-01 15:07:11 -06:00
|
|
|
|
2025-04-02 13:54:50 -06:00
|
|
|
@Patch(':id')
|
|
|
|
|
updateQr(@Param('id', ParseIntPipe) id: number, @Body() qr: UpdateQrDto) {
|
|
|
|
|
return this.qrService.updateQr(id, qr);
|
|
|
|
|
}
|
2025-04-01 15:07:11 -06:00
|
|
|
}
|