Subir carpetas con las nuevas tablas
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from '@nestjs/common';
|
||||
import { AsistenciaService } from './asistencia.service';
|
||||
import { Asistencia } from './asistencia.entity';
|
||||
import { CreateAsistenciaDto } from './dto/create-asistencia.dto';
|
||||
import { UpdateAsistenciaDto } from './dto/update.asistencia.dto';
|
||||
|
||||
@Controller('asistencia')
|
||||
export class AsistenciaController {
|
||||
|
||||
constructor(private asistenciaService: AsistenciaService) {}
|
||||
|
||||
@Get()
|
||||
getAsistencias(): Promise<Asistencia[]> {
|
||||
return this.asistenciaService.getAsistencias()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
getAsistencia(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.asistenciaService.getAsistencia(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
createAsistencia(@Body() newAsistencia: CreateAsistenciaDto) {
|
||||
return this.asistenciaService.createAsistencia(newAsistencia)
|
||||
}
|
||||
|
||||
@Delete()
|
||||
deleteAsistencia(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.asistenciaService.deleteAsistencia(id)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
updateAsistencia(@Param('id', ParseIntPipe) id: number, @Body() asistencia: UpdateAsistenciaDto) {
|
||||
return this.asistenciaService.updateAsistencia(id, asistencia)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class Asistencia {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_asistecia: number
|
||||
|
||||
//({type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }
|
||||
@Column({type: 'datetime', default: () => 'CURRENT_TIMESTAMP'})
|
||||
fecha_asistencia: Date
|
||||
|
||||
@Column()
|
||||
metodo: boolean
|
||||
|
||||
@Column()
|
||||
estado: boolean
|
||||
|
||||
//relaciones con las otras tablas
|
||||
@Column()
|
||||
id_participante: number
|
||||
|
||||
@Column()
|
||||
id_evento: number
|
||||
|
||||
@Column()
|
||||
id_administrador: number
|
||||
|
||||
/*
|
||||
@ManyToOne(() => Administrador, (admin) => admin.asistencias)
|
||||
@JoinColumn({ name: "id_administrador" })
|
||||
administrador: Administrador;
|
||||
|
||||
@ManyToOne(() => Evento, (evento) => evento.asistencias)
|
||||
@JoinColumn({ name: "id_evento" })
|
||||
evento: Evento;
|
||||
|
||||
@ManyToOne(() => Participante, (participante) => participante.asistencias)
|
||||
@JoinColumn({ name: "id_participante" })
|
||||
participante: Participante;
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AsistenciaService } from './asistencia.service';
|
||||
import { AsistenciaController } from './asistencia.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Asistencia } from './asistencia.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Asistencia])],
|
||||
controllers: [AsistenciaController],
|
||||
providers: [AsistenciaService]
|
||||
})
|
||||
export class AsistenciaModule {}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Asistencia } from './asistencia.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateAsistenciaDto } from './dto/create-asistencia.dto';
|
||||
import { UpdateAsistenciaDto } from './dto/update.asistencia.dto';
|
||||
|
||||
@Injectable()
|
||||
export class AsistenciaService {
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Asistencia) private asistenciaRepository: Repository<Asistencia>
|
||||
) {}
|
||||
|
||||
async createAsistencia(asistencia: CreateAsistenciaDto) {
|
||||
|
||||
const asistenciaFound = await this.asistenciaRepository.findOne({
|
||||
where: {
|
||||
fecha_asistencia: asistencia.fecha_asistencia,
|
||||
metodo: asistencia.metodo,
|
||||
estado: asistencia.estdao
|
||||
}
|
||||
})
|
||||
|
||||
if (asistenciaFound) {
|
||||
return new HttpException('User already exists', HttpStatus.CONFLICT)
|
||||
}
|
||||
|
||||
return this.asistenciaRepository.save(asistencia)
|
||||
}
|
||||
|
||||
getAsistencias() {
|
||||
return this.asistenciaRepository.find({})
|
||||
}
|
||||
|
||||
async getAsistencia(id_asistecia: number) {
|
||||
const asistenciaFound = await this.asistenciaRepository.findOne({
|
||||
where: {
|
||||
id_asistecia
|
||||
}
|
||||
})
|
||||
|
||||
if (!asistenciaFound) {
|
||||
return new HttpException('User not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
return asistenciaFound
|
||||
}
|
||||
|
||||
async deleteAsistencia(id_asistecia: number) {
|
||||
const result = await this.asistenciaRepository.delete({ id_asistecia })
|
||||
|
||||
if (result.affected === 0) {
|
||||
return new HttpException('User not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
async updateAsistencia(id_asistecia: number, asistencia: UpdateAsistenciaDto) {
|
||||
const asistenciaFound = await this.asistenciaRepository.findOne({
|
||||
where: {
|
||||
id_asistecia
|
||||
}
|
||||
})
|
||||
|
||||
if (!asistenciaFound) {
|
||||
return new HttpException('User not found', HttpStatus.NOT_FOUND)
|
||||
}
|
||||
|
||||
const updateAsistencia = Object.assign(asistenciaFound, asistencia)
|
||||
return this.asistenciaRepository.save(updateAsistencia)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export class CreateAsistenciaDto {
|
||||
fecha_asistencia: Date
|
||||
metodo: boolean
|
||||
estdao: boolean
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export class UpdateAsistenciaDto {
|
||||
fecha_asistencia?: Date
|
||||
metodo?: boolean
|
||||
estado?: boolean
|
||||
}
|
||||
Reference in New Issue
Block a user