29 lines
912 B
TypeScript
29 lines
912 B
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { Drink } from './entities/drink.entity';
|
|
import { CreateDrinkDto } from './dto/create-drink.dto';
|
|
|
|
@Injectable()
|
|
export class DrinksService {
|
|
constructor(
|
|
@InjectRepository(Drink)
|
|
private readonly drinkRepository: Repository<Drink>,
|
|
) {}
|
|
|
|
async create(dto: CreateDrinkDto): Promise<Drink> {
|
|
const drink = this.drinkRepository.create(dto);
|
|
return this.drinkRepository.save(drink);
|
|
}
|
|
|
|
async findByClub(clubId: string): Promise<Drink[]> {
|
|
return this.drinkRepository.find({ where: { clubId } });
|
|
}
|
|
|
|
async findById(id: string): Promise<Drink> {
|
|
const drink = await this.drinkRepository.findOne({ where: { id } });
|
|
if (!drink) throw new NotFoundException(`Getränk ${id} nicht gefunden`);
|
|
return drink;
|
|
}
|
|
}
|