Files
api-AT/src/programa/programa.service.ts
T

42 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@nestjs/common';
import { CreateProgramaDto } from './dto/create-programa.dto';
import { UpdateProgramaDto } from './dto/update-programa.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Programa } from './entities/programa.entity';
import { Repository } from 'typeorm';
@Injectable()
export class ProgramaService {
constructor(
@InjectRepository(Programa)
2026-02-10 13:23:44 -06:00
private readonly programaRepository: Repository<Programa>
) { }
findAll() {
2026-02-10 13:23:44 -06:00
return this.programaRepository.find({ order: { programa: 'ASC' } });
}
2026-02-10 13:23:44 -06:00
findOne(id_programa: number) {
2026-02-10 13:23:44 -06:00
const programa = this.programaRepository.findOne({ where: { id_programa } })
2026-02-10 13:23:44 -06:00
if (!programa) {
return "this program dosnt exist"
}
return programa;
}
2026-02-03 12:47:07 -05:00
async create(createProgramaDto: CreateProgramaDto) {
const nuevo = this.programaRepository.create(createProgramaDto);
return await this.programaRepository.save(nuevo);
}
2026-02-03 12:47:07 -05:00
async update(id: number, updateProgramaDto: UpdateProgramaDto) {
await this.programaRepository.update(id, updateProgramaDto);
return await this.findOne(id);
}
}
2026-02-03 12:47:07 -05:00
2026-02-10 13:23:44 -06:00
2026-02-03 12:47:07 -05:00