Subir carpetas con las nuevas tablas

This commit is contained in:
santiago
2025-04-01 15:07:11 -06:00
parent 1520825ad3
commit fbd753d27e
45 changed files with 1452 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
export class CreateQrDto {
id_participante_evento: number
fecha_creacion: Date
decha_vencimiento: Date
activo: boolean
}
+5
View File
@@ -0,0 +1,5 @@
export class UpdateQrDto {
fecha_creacion?: Date
fecha_vencimiento: Date
activo?: boolean
}
+36
View File
@@ -0,0 +1,36 @@
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from '@nestjs/common';
import { QrService } from './qr.service';
import { Qr } from './qr.entity';
import { CreateQrDto } from './dto/create-qr.dto';
import { UpdateQrDto } from './dto/update.qr.dto';
@Controller('qr')
export class QrController {
constructor(private qrService: QrService) {}
@Get()
getQrs(): Promise<Qr[]> {
return this.qrService.getQrs();
}
@Get(':id')
getQr(@Param('id', ParseIntPipe) id: number) {
return this.qrService.getQr(id);
}
@Post() //en el body ValidationPipe
createQr(@Body() newQr: CreateQrDto) {
return this.qrService.createQr(newQr)
}
@Delete(':id')
deleteQr(@Param('id', ParseIntPipe) id:number) {
return this.qrService.deleteQr(id);
}
@Patch(':id')
updateQr(@Param('id', ParseIntPipe) id: number, @Body() qr: UpdateQrDto) {
return this.qrService.updateQr(id, qr)
}
}
+25
View File
@@ -0,0 +1,25 @@
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Qr {
@PrimaryGeneratedColumn()
id_qr: number
/*
@OneToOne(() => ParticipanteEvento, (pe) => pe.qr)
@JoinColumn({ name: "id_participante_evento" })
participanteEvento: ParticipanteEvento;
*/
@Column({type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
fecha_creacion: Date
@Column({type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
fecha_vencimiento: Date
@Column()
activo: boolean
//Relacion con id_participante_evento
}
+12
View File
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { QrService } from './qr.service';
import { QrController } from './qr.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Qr } from './qr.entity';
@Module({
imports: [TypeOrmModule.forFeature([Qr])],
controllers: [QrController],
providers: [QrService]
})
export class QrModule {}
+73
View File
@@ -0,0 +1,73 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { Qr } from './qr.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateQrDto } from './dto/create-qr.dto';
import { UpdateQrDto } from './dto/update.qr.dto';
@Injectable()
export class QrService {
constructor(
@InjectRepository(Qr) private qrRepository: Repository<Qr>
) {}
async createQr(qr: CreateQrDto) {
const qrFound = await this.qrRepository.findOne({
where: {
id_qr: qr.id_participante_evento
}
})
if (qrFound) {
return new HttpException('Qr already exists', HttpStatus.CONFLICT)
}
return this.qrRepository.save(qr)
}
getQrs() {
return this.qrRepository.find({})
}
async getQr(id_qr) {
const qrFound = await this.qrRepository.findOne({
where: {
id_qr
}
})
if (!qrFound) {
return new HttpException('User not found', HttpStatus.NOT_FOUND);
}
return qrFound
}
async deleteQr(id_qr: number) {
const result = await this.qrRepository.delete({ id_qr })
if (result.affected === 0) {
return new HttpException('User not found', HttpStatus.NOT_FOUND);
}
return result
}
async updateQr(id_qr: number, qr: UpdateQrDto) {
const qrFound = await this.qrRepository.findOne({
where: {
id_qr
}
})
if (!qrFound) {
return new HttpException('User not found', HttpStatus.NOT_FOUND)
}
const updateQr = Object.assign(qrFound, qr)
return this.qrRepository.save(updateQr)
}
}