Files
pcpuma_unam_api/src/modulo/modulo.service.ts
T

30 lines
796 B
TypeScript
Raw Normal View History

2022-04-04 20:02:54 -05:00
import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Modulo } from './modulo.entity';
@Injectable()
export class ModuloService {
constructor(
@InjectRepository(Modulo) private repository: Repository<Modulo>,
) {}
2022-04-16 09:52:15 -05:00
findAllByIdInstitucion(id_institucion: number) {
2022-04-06 15:27:23 -05:00
return this.repository.find({
2022-04-16 09:52:15 -05:00
where: { institucion: { id_institucion: 1 } },
2022-04-06 15:27:23 -05:00
});
}
2022-04-04 20:02:54 -05:00
2022-04-06 15:27:23 -05:00
create(attrs: Partial<Modulo>) {
return this.repository
.findOne({
where: { institucion: attrs.institucion, modulo: attrs.modulo },
})
.then((res) => {
console.log(res);
if (res) throw new Error('Ya existe este usuario.');
return this.repository.save(attrs);
});
2022-04-04 20:02:54 -05:00
}
}