changed docker file nest to avoid rebuild everything each time, and small changes in chat gateway
This commit is contained in:
22
tests_hugo/nest_course/src/app.controller.spec.ts
Normal file
22
tests_hugo/nest_course/src/app.controller.spec.ts
Normal 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!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
tests_hugo/nest_course/src/app.controller.ts
Normal file
12
tests_hugo/nest_course/src/app.controller.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
12
tests_hugo/nest_course/src/app.module.ts
Normal file
12
tests_hugo/nest_course/src/app.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { CoffeesController } from './coffees/coffees.controller';
|
||||
import { CoffeesService } from './coffees/coffees.service';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController, CoffeesController],
|
||||
providers: [AppService, CoffeesService],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
tests_hugo/nest_course/src/app.service.ts
Normal file
8
tests_hugo/nest_course/src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello nest!';
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
45
tests_hugo/nest_course/src/coffees/coffees.controller.ts
Normal file
45
tests_hugo/nest_course/src/coffees/coffees.controller.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Body,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Patch,
|
||||
Delete,
|
||||
Query
|
||||
} from '@nestjs/common';
|
||||
import { CoffeesService } from './coffees.service';
|
||||
|
||||
@Controller('coffees')
|
||||
export class CoffeesController {
|
||||
constructor(private readonly coffeesService: CoffeesService) {}
|
||||
|
||||
@Get()
|
||||
findAll(@Query() paginationQuery) {
|
||||
// const { limit, offset } = paginationQuery;
|
||||
return this.coffeesService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.coffeesService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
//@HttpCode(HttpStatus.GONE)
|
||||
create(@Body() body) {
|
||||
return this.coffeesService.create(body);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() body) {
|
||||
return this.coffeesService.update(id, body);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.coffeesService.remove(id);
|
||||
}
|
||||
}
|
||||
18
tests_hugo/nest_course/src/coffees/coffees.service.spec.ts
Normal file
18
tests_hugo/nest_course/src/coffees/coffees.service.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CoffeesService } from './coffees.service';
|
||||
|
||||
describe('CoffeesService', () => {
|
||||
let service: CoffeesService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CoffeesService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CoffeesService>(CoffeesService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
42
tests_hugo/nest_course/src/coffees/coffees.service.ts
Normal file
42
tests_hugo/nest_course/src/coffees/coffees.service.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Coffee } from './entities/coffee.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CoffeesService {
|
||||
|
||||
private coffees: Coffee[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'arabica',
|
||||
brand: 'illy',
|
||||
flavors: ['chocolate', 'vanilla'],
|
||||
}
|
||||
];
|
||||
|
||||
findAll() {
|
||||
return this.coffees;
|
||||
}
|
||||
|
||||
findOne(id: string) {
|
||||
return this.coffees.find(item => item.id === +id);
|
||||
}
|
||||
|
||||
create(createCoffeeDto: any) {
|
||||
this.coffees.push(createCoffeeDto);
|
||||
}
|
||||
|
||||
update(id: string, updateCoffeeDto: any) {
|
||||
const existingCoffee = this.findOne(id);
|
||||
if (existingCoffee) {
|
||||
// update the existing entity
|
||||
}
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
const coffeeIndex = this.coffees.findIndex(item => item.id === +id);
|
||||
if (coffeeIndex >= 0) {
|
||||
this.coffees.splice(coffeeIndex, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export class Coffee {
|
||||
id: number;
|
||||
name: string;
|
||||
brand: string;
|
||||
flavors: string[];
|
||||
}
|
||||
8
tests_hugo/nest_course/src/main.ts
Normal file
8
tests_hugo/nest_course/src/main.ts
Normal 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();
|
||||
Reference in New Issue
Block a user