38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { Injectable,NotFoundException } from '@nestjs/common';
|
|
import { ManufacturerCreateDto, ManufacturerUpdateDto } from '../_dto/manufacturer.dto';
|
|
import { InjectModel } from '@nestjs/mongoose';
|
|
import { Model } from 'mongoose';
|
|
import { Manufacturer } from '../_entities/manufacturer.entity';
|
|
|
|
|
|
@Injectable()
|
|
export class ManufacturerService {
|
|
constructor(
|
|
@InjectModel(Manufacturer.name)
|
|
private manufacturerModel: Model<Manufacturer>,
|
|
) { }
|
|
|
|
create(dto: ManufacturerCreateDto) {
|
|
return this.manufacturerModel.create(dto);
|
|
}
|
|
|
|
findAll() {
|
|
return this.manufacturerModel
|
|
.find();
|
|
}
|
|
|
|
async findOne(id: string) {
|
|
const article = await this.manufacturerModel.findById(id);
|
|
if (!article) throw new NotFoundException('Artikel nicht gefunden');
|
|
return article;
|
|
}
|
|
|
|
update(id: string, dto: ManufacturerUpdateDto) {
|
|
return this.manufacturerModel.findByIdAndUpdate(id, dto, { new: true });
|
|
}
|
|
|
|
remove(id: string) {
|
|
return this.manufacturerModel.findByIdAndDelete(id);
|
|
}
|
|
}
|