import { Injectable, NotFoundException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Kontonummer } from '../database/entities'; @Injectable() export class KontonummernService { constructor( @InjectRepository(Kontonummer) private readonly kontonummerRepo: Repository, ) {} async findByCorrespondent(correspondentId: number): Promise { return this.kontonummerRepo.find({ where: { CorrespondentId: correspondentId }, }); } async create(correspondentId: number, nummer: string): Promise { const existing = await this.kontonummerRepo.findOne({ where: { CorrespondentId: correspondentId, Nummer: nummer }, }); if (existing) { return existing; } const kontonummer = this.kontonummerRepo.create({ CorrespondentId: correspondentId, Nummer: nummer, }); return this.kontonummerRepo.save(kontonummer); } }