wip nest course

This commit is contained in:
lenovo
2022-11-19 19:31:44 +01:00
parent ffbb3bf442
commit f0af98eb02
33 changed files with 15169 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

View File

@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}

View File

@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CoffeesController } from './coffees/coffees.controller';
@Module({
imports: [],
controllers: [AppController, CoffeesController],
providers: [AppService],
})
export class AppModule {}

View File

@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello nest!';
}
}

View File

@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CoffeesController } from './coffees.controller';
describe('CoffeesController', () => {
let controller: CoffeesController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CoffeesController],
}).compile();
controller = module.get<CoffeesController>(CoffeesController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@@ -0,0 +1,51 @@
import {
Controller,
Get,
Param,
Post,
Body,
HttpCode,
HttpStatus,
Patch,
Delete,
Query
} from '@nestjs/common';
@Controller('coffees')
export class CoffeesController {
@Get()
findAll(@Query() paginationQuery) {
const { limit, offset } = paginationQuery;
return `this action returns all the coffees.
limit: ${limit},
offset: ${offset}
`;
}
@Get('flavors')
findFlavors() {
return 'this action returns the coffees flavors';
}
@Get(':id')
findOne(@Param('id') id: string) {
return `this action returns #${id} coffees`;
}
@Post()
@HttpCode(HttpStatus.GONE)
create(@Body() body) {
return body;
}
@Patch(':id')
update(@Param('id') id: string, @Body() body) {
return `this action updates #${id} coffee`;
}
@Delete(':id')
remove(@Param('id') id: string) {
return `this action removes #${id} coffee`;
}
}

View File

@@ -0,0 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();