wip first chat

This commit is contained in:
lenovo
2022-11-20 20:18:59 +01:00
parent 8fc383c8fc
commit ada109416a
81 changed files with 16167 additions and 48 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,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 {}

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,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);
}
}

View 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();
});
});

View 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);
}
}
}

View File

@@ -0,0 +1,6 @@
export class Coffee {
id: number;
name: string;
brand: string;
flavors: string[];
}

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();