ajout de la fenêtre de logs pour le mode développeur + quelques routes sans bdd pour l'instant

This commit is contained in:
batche
2022-10-21 15:38:15 +02:00
parent f162ea2d11
commit a175ef7162
168 changed files with 7444 additions and 5 deletions

View File

@@ -1,9 +1,11 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
@Module({
imports: [],
imports: [AuthModule, UsersModule],
controllers: [AppController],
providers: [AppService],
})

View File

@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
return 'Hello Toto!';
}
}

View File

@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { UsersModule } from 'src/users/users.module';
@Module({
imports: [UsersModule],
providers: [AuthService],
})
export class AuthModule {}

View File

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

View File

@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { UsersService } from '../users/users.service';
@Injectable()
export class AuthService {
constructor (private usersService: UsersService) {}
async validateUser(username: string, pass: string): Promise<any> {
return null;
}
}

View File

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

View File

@@ -0,0 +1,5 @@
export class User {
userId: number;
username: string;
password: string;
}

View File

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

View File

@@ -0,0 +1,38 @@
import {
Body, Controller, Delete, Get, HttpCode,
HttpStatus, Param, Patch, Post, Query
} from '@nestjs/common';
import { UsersService } from './users.service';
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}
// par exemple dans postamn ou insomnia http://localhost:3000/users?limit=10&offset=20
@Get()
findAll(@Query() query) {
const { limit, offset } = query;
return `This action returns all users. The limits is ${limit} and the offset is ${offset}`;
}
@Get(':id')
findOne(@Param('id') id: string) {
return 'This action returns a single user whose id is ' + id;
}
@Post()
@HttpCode(HttpStatus.GONE)
create(@Body() body) {
return body;
}
@Patch(':id')
update(@Param('id') id: string, @Body() body) {
return 'The user whose id is ' + id + ' has been updated';
}
@Delete(':id')
remove(@Param('id') id: string) {
return 'The user whose id is ' + id + ' has been deleted';
}
}

View File

@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
@Module({
providers: [UsersService],
exports: [UsersService],
controllers: [UsersController],
})
export class UsersModule {}

View File

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

View File

@@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common';
import { User } from './entities/user.entity';
@Injectable()
export class UsersService {
private users:User[] = [
{
userId: 1,
username: 'john',
password: 'changeme',
},
{
userId: 2,
username: 'maria',
password: 'guess',
},
];
findOne(id: number) {
return this.users.find(user => user.userId === id);
}
findAll() {
return this.users;
}
create(createUserDto: any) {
this.users.push(createUserDto);
}
update(id: number, updateUserDto: any) {
const index = this.users.findIndex(user => user.userId === id);
this.users[index] = updateUserDto;
}
}