Skip to content

Commit

Permalink
Providers_Module_test
Browse files Browse the repository at this point in the history
  • Loading branch information
bodyduardU committed Mar 8, 2023
1 parent 394123d commit 9cd3431
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 28 deletions.
6 changes: 4 additions & 2 deletions nestjs/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CatsController } from './cats/cats.controller';
import { CatsService } from './cats/cats.service';
import { CatsModule } from './cats/cats.module';

@Module({
imports: [],
controllers: [AppController, CatsController],
imports: [CatsModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
45 changes: 19 additions & 26 deletions nestjs/src/cats/cats.controller.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
import { Controller, Get, Req, Res, Post, HttpStatus } from '@nestjs/common';
import { HttpCode, Param } from '@nestjs/common/decorators';
// import { Request } from '@nestjs/common/decorators';
import {
Controller,
Get,
Req,
Res,
Post,
Body,
HttpStatus,
} from '@nestjs/common';

import { Request } from 'express';
import { CatsService } from './cats.service';
import { CreateCatDto } from './create-cat.dto';
import { Cat } from 'src/interfaces/cat.interface';

@Controller('cats')
export class CatsController {
constructor(private catsService: CatsService) {}
@Post()
create(): string {
return 'This action asd';
async create(@Body() createCatDto: CreateCatDto) {
this.catsService.create(createCatDto);
}

@Get()
findAll(@Res({ passthrough: true }) res: Response) {
// res.status(HttpStatus.OK);
return ['123'];
}

@Get(':id')
findOne(@Param('id') id: string): string {
return `this is ${id}`;
async findAll(): Promise<Cat[]> {
return this.catsService.findAll();
}
// @Get(':id')
// findOne(@Param() params): string {
// console.log(params.id);
// return `123 ${params.id}`;
// }
// @Get('')
// findAll(@Req() request: Request): string {
// return 'asdasd';
// }
// @Get()
// find(): string {
// return 'ok';
// }
}
11 changes: 11 additions & 0 deletions nestjs/src/cats/cats.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';

@Module({
controllers: [CatsController],
providers: [CatsService],
})
export class CatsModule {
constructor(private catsService: CatsService) {}
}
18 changes: 18 additions & 0 deletions nestjs/src/cats/cats.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CatsService } from './cats.service';

describe('CatsService', () => {
let service: CatsService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CatsService],
}).compile();

service = module.get<CatsService>(CatsService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
15 changes: 15 additions & 0 deletions nestjs/src/cats/cats.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@nestjs/common';
import { Cat } from 'src/interfaces/cat.interface';

@Injectable()
export class CatsService {
private readonly cats: Cat[] = [];

create(cat: Cat) {
this.cats.push(cat);
}

findAll(): Cat[] {
return this.cats;
}
}
5 changes: 5 additions & 0 deletions nestjs/src/cats/create-cat.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class CreateCatDto {
name: string;
age: number;
breed: string;
}
5 changes: 5 additions & 0 deletions nestjs/src/interfaces/cat.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Cat {
name: string;
age: number;
breed: string;
}

0 comments on commit 9cd3431

Please sign in to comment.