2022-04-20 09:48:21 -05:00
|
|
|
import { ConflictException, Injectable } from '@nestjs/common';
|
2022-04-04 20:53:32 -05:00
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
2022-04-17 23:05:18 -05:00
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
import { Programa } from './entity/programa.entity';
|
2022-04-04 20:02:54 -05:00
|
|
|
|
|
|
|
|
@Injectable()
|
2022-04-04 20:53:32 -05:00
|
|
|
export class ProgramaService {
|
|
|
|
|
constructor(
|
|
|
|
|
@InjectRepository(Programa) private repository: Repository<Programa>,
|
|
|
|
|
) {}
|
2022-04-20 09:48:21 -05:00
|
|
|
|
|
|
|
|
create(programa: string) {
|
|
|
|
|
return this.repository
|
|
|
|
|
.findOne({ programa })
|
|
|
|
|
.then((existePrograma) => {
|
|
|
|
|
if (existePrograma)
|
|
|
|
|
throw new ConflictException('Ya existe este programa.');
|
|
|
|
|
return this.repository.save(this.repository.create({ programa }));
|
|
|
|
|
})
|
|
|
|
|
.then((_) => ({ message: 'Se creo correctamente el programa.' }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findAll() {
|
|
|
|
|
return this.repository.find();
|
|
|
|
|
}
|
2022-04-04 20:53:32 -05:00
|
|
|
}
|