Initial commit: NestJS NextJS pnpm monorepo
This commit is contained in:
commit
610dcf202b
175 files changed
+25172
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ManufacturerService } from './manufacturer.service';
|
||||
import { ManufacturerCreateDto, ManufacturerUpdateDto } from '../_dto/manufacturer.dto';
|
||||
|
||||
|
||||
@Controller('manufacturer')
|
||||
export class ManufacturerController {
|
||||
constructor(private readonly manufacturerService: ManufacturerService) {}
|
||||
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.manufacturerService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.manufacturerService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() createManufacturerDto: ManufacturerCreateDto) {
|
||||
return this.manufacturerService.create(createManufacturerDto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateManufacturerDto: ManufacturerUpdateDto) {
|
||||
console.log(updateManufacturerDto)
|
||||
return this.manufacturerService.update(id, updateManufacturerDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.manufacturerService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ManufacturerService } from './manufacturer.service';
|
||||
import { ManufacturerController } from './manufacturer.controller';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { Manufacturer, ManufacturerSchema } from '../_entities/manufacturer.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([
|
||||
{ name: Manufacturer.name, schema: ManufacturerSchema },
|
||||
])
|
||||
],
|
||||
controllers: [ManufacturerController],
|
||||
providers: [ManufacturerService],
|
||||
})
|
||||
export class ManufacturerModule {}
|
||||
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user