programa listo

This commit is contained in:
xXpuma99Xx
2022-04-20 09:48:21 -05:00
parent cd0674817f
commit 2845660f05
3 changed files with 32 additions and 3 deletions
+16 -1
View File
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { ConflictException, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Programa } from './entity/programa.entity';
@@ -8,4 +8,19 @@ export class ProgramaService {
constructor(
@InjectRepository(Programa) private repository: Repository<Programa>,
) {}
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();
}
}