diff --git a/apps/backend/src/app/app.controller.ts b/apps/backend/src/app/app.controller.ts index 3e7d130..34d0d97 100644 --- a/apps/backend/src/app/app.controller.ts +++ b/apps/backend/src/app/app.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get } from "@nestjs/common"; +import { ApiTags } from "@nestjs/swagger"; import { AppService } from "./app.service"; -import { ApiTags } from '@nestjs/swagger'; @Controller() @ApiTags("useless") diff --git a/apps/backend/src/app/auth/auth.controller.ts b/apps/backend/src/app/auth/auth.controller.ts index 471def4..4778dbd 100644 --- a/apps/backend/src/app/auth/auth.controller.ts +++ b/apps/backend/src/app/auth/auth.controller.ts @@ -10,12 +10,12 @@ import { UnauthorizedException, UseGuards, } from "@nestjs/common"; +import { ApiBearerAuth, ApiTags } from "@nestjs/swagger"; import { SignInDto, SignUpDto } from "apps/backend/src/app/auth/auth.dto"; import { AuthService } from "apps/backend/src/app/auth/auth.service"; import { UserGuard } from "./auth.guard"; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; -@ApiTags('User authentification') +@ApiTags("User authentification") @Controller("auth") export class AuthController { constructor(private readonly authService: AuthService) {} diff --git a/apps/backend/src/app/auth/auth.dto.ts b/apps/backend/src/app/auth/auth.dto.ts index bc6c708..ca1b742 100644 --- a/apps/backend/src/app/auth/auth.dto.ts +++ b/apps/backend/src/app/auth/auth.dto.ts @@ -1,3 +1,4 @@ +import { ApiProperty } from "@nestjs/swagger"; import { IsEmail, IsNotEmpty, @@ -6,7 +7,6 @@ import { MaxLength, MinLength, } from "class-validator"; -import { ApiProperty } from '@nestjs/swagger'; export class SignUpDto { /* @@ -24,7 +24,7 @@ export class SignUpDto { **/ @ApiProperty({ - example: 'jean@paul.fr', + example: "jean@paul.fr", }) @MaxLength(32) @IsEmail() @@ -32,7 +32,7 @@ export class SignUpDto { email: string; @ApiProperty({ - example: 'zSEs-6ze$', + example: "zSEs-6ze$", }) @IsString() @IsNotEmpty() @@ -43,15 +43,17 @@ export class SignUpDto { } export class SignInDto { - @MaxLength(32)@ApiProperty({ - example: 'jean@paul.fr', + @MaxLength(32) + @ApiProperty({ + example: "jean@paul.fr", }) @IsEmail() @IsNotEmpty() email: string; - @IsString()@ApiProperty({ - example: 'zSEs-6ze$', + @IsString() + @ApiProperty({ + example: "zSEs-6ze$", }) @IsNotEmpty() @IsStrongPassword({ diff --git a/apps/backend/src/app/authors/authors.controller.ts b/apps/backend/src/app/authors/authors.controller.ts index f5c477f..a7656d8 100644 --- a/apps/backend/src/app/authors/authors.controller.ts +++ b/apps/backend/src/app/authors/authors.controller.ts @@ -9,11 +9,11 @@ import { Query, UseGuards, } from "@nestjs/common"; +import { ApiBearerAuth, ApiTags } from "@nestjs/swagger"; import { AdminGuard } from "apps/backend/src/app/auth/auth.guard"; import { AuthorsService } from "apps/backend/src/app/authors/authors.service"; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; -@ApiTags('File authors') +@ApiTags("File authors") @Controller("authors") export class AuthorsController { constructor(private readonly authorService: AuthorsService) {} diff --git a/apps/backend/src/app/files/files.controller.ts b/apps/backend/src/app/files/files.controller.ts index 777af7c..58326d9 100644 --- a/apps/backend/src/app/files/files.controller.ts +++ b/apps/backend/src/app/files/files.controller.ts @@ -20,28 +20,31 @@ import { StreamableFile, UseGuards, } from "@nestjs/common"; +import { + ApiBearerAuth, + ApiBody, + ApiConsumes, + ApiHeaders, + ApiOperation, + ApiSecurity, + ApiTags, +} from "@nestjs/swagger"; import { CreateFileTypeDto } from "apps/backend/src/app/files/files.dto"; import { AdminGuard, InsertAdminState } from "../auth/auth.guard"; import { FilesService } from "./files.service"; -import { - ApiBearerAuth, ApiBody, ApiConsumes, - ApiHeaders, ApiOperation, - ApiSecurity, - ApiTags -} from '@nestjs/swagger'; -@ApiTags('Files') +@ApiTags("Files") @Controller("files") export class FilesController { constructor(private readonly filesService: FilesService) {} - @ApiOperation({ summary: "Uploader un fichier"}) + @ApiOperation({ summary: "Uploader un fichier" }) @ApiConsumes("application/octet-stream") @ApiBody({ schema: { - type: 'string', - format: 'binary' - } + type: "string", + format: "binary", + }, }) @ApiHeaders([ { @@ -49,18 +52,21 @@ export class FilesController { description: "Nom du fichier", example: "Logo marianne", allowEmptyValue: false, - required: true + required: true, }, { name: "group_id", description: "Groupe de fichier optionnel", example: "dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c", - allowEmptyValue: true + allowEmptyValue: true, }, { name: "machine_id", description: "Identifiant(s) de machine(s)", - example: ["dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c", "dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c"], + example: [ + "dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c", + "dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c", + ], allowEmptyValue: false, required: true, }, @@ -73,13 +79,15 @@ export class FilesController { }, { name: "is_documentation", - description: "Admin uniquement, défini le fichier comme étant une documentation", + description: + "Admin uniquement, défini le fichier comme étant une documentation", enum: ["true", "false"], allowEmptyValue: false, }, { name: "is_restricted", - description: "Admin uniquement, rend impossible l'écrasement d'un fichier (non implémenté pour l'instant)", + description: + "Admin uniquement, rend impossible l'écrasement d'un fichier (non implémenté pour l'instant)", enum: ["true", "false"], allowEmptyValue: false, }, @@ -170,7 +178,7 @@ export class FilesController { return; } - @HttpCode(HttpStatus.FOUND) + @HttpCode(HttpStatus.OK) @Get("find") async findMany( @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, @@ -180,7 +188,7 @@ export class FilesController { return this.filesService.search(limit, offset, search); } - @HttpCode(HttpStatus.FOUND) + @HttpCode(HttpStatus.OK) @Get("types") async getTypes() { console.log("Performing request"); diff --git a/apps/backend/src/app/files/files.dto.ts b/apps/backend/src/app/files/files.dto.ts index 08e9408..2830c14 100644 --- a/apps/backend/src/app/files/files.dto.ts +++ b/apps/backend/src/app/files/files.dto.ts @@ -1,25 +1,20 @@ import { DefaultValuePipe } from "@nestjs/common"; +import { ApiBearerAuth, ApiProperty } from "@nestjs/swagger"; import { IsUUID, MaxLength, MinLength } from "class-validator"; -import { ApiBearerAuth, ApiProperty } from '@nestjs/swagger'; export class CreateFileTypeDto { @ApiProperty({ description: "Admin uniquement, nom d'affichage.", - examples: [ - ".scad", - "jpg" - ] + examples: [".scad", "jpg"], }) @MaxLength(128) @MinLength(3) name: string; @ApiProperty({ - description: "Admin uniquement, Multipurpose Internet Mail Extensions (MIME)", - examples: [ - "application/x-openscad", - "image/jpeg" - ] + description: + "Admin uniquement, Multipurpose Internet Mail Extensions (MIME)", + examples: ["application/x-openscad", "image/jpeg"], }) @MaxLength(64) @MinLength(4) diff --git a/apps/backend/src/app/groups/groups.controller.ts b/apps/backend/src/app/groups/groups.controller.ts index e403958..763c4a7 100644 --- a/apps/backend/src/app/groups/groups.controller.ts +++ b/apps/backend/src/app/groups/groups.controller.ts @@ -10,13 +10,13 @@ import { Query, UseGuards, } from "@nestjs/common"; +import { ApiBearerAuth, ApiTags } from "@nestjs/swagger"; import { AdminGuard } from "apps/backend/src/app/auth/auth.guard"; import { CreateGroupDto } from "apps/backend/src/app/groups/groups.dto"; import { ISearchQuery } from "apps/backend/src/app/groups/groups.types"; import { GroupsService } from "./groups.service"; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; -@ApiTags('File groups') +@ApiTags("File groups") @Controller("groups") export class GroupsController { constructor(private readonly groupsService: GroupsService) {} diff --git a/apps/backend/src/app/groups/groups.dto.ts b/apps/backend/src/app/groups/groups.dto.ts index 822521f..e1801a9 100644 --- a/apps/backend/src/app/groups/groups.dto.ts +++ b/apps/backend/src/app/groups/groups.dto.ts @@ -1,10 +1,10 @@ +import { ApiProperty } from "@nestjs/swagger"; import { IsString, MaxLength, MinLength } from "class-validator"; -import { ApiProperty } from '@nestjs/swagger'; export class CreateGroupDto { @ApiProperty({ description: "Nom unique.", - example: "Numérique en communs" + example: "Numérique en communs", }) @IsString() @MinLength(4) diff --git a/apps/backend/src/app/machines/machines.controller.ts b/apps/backend/src/app/machines/machines.controller.ts index 8d72d7b..7a743ae 100644 --- a/apps/backend/src/app/machines/machines.controller.ts +++ b/apps/backend/src/app/machines/machines.controller.ts @@ -13,16 +13,16 @@ import { Query, UseGuards, } from "@nestjs/common"; +import { ApiResponse, ApiTags } from "@nestjs/swagger"; import { AdminGuard } from "apps/backend/src/app/auth/auth.guard"; +import { IMachinesTable } from "apps/backend/src/app/db/schema"; import { CreateMachineDto, TypeDto, } from "apps/backend/src/app/machines/machines.dto"; import { MachinesService } from "apps/backend/src/app/machines/machines.service"; -import { ApiResponse, ApiTags } from '@nestjs/swagger'; -import { IMachinesTable } from 'apps/backend/src/app/db/schema'; -@ApiTags('Machines') +@ApiTags("Machines") @Controller("machines") export class MachinesController { constructor(private readonly machineService: MachinesService) {} @@ -68,13 +68,13 @@ export class MachinesController { return await this.machineService.removeFileType(machineId, body.fileTypeId); } - @HttpCode(HttpStatus.FOUND) + @HttpCode(HttpStatus.OK) @Get("types/:machineId") async getTypesOfMachine(@Param("machineId") machineId: string) { return await this.machineService.getFilesTypes(machineId); } - @HttpCode(HttpStatus.FOUND) + @HttpCode(HttpStatus.OK) @Get("files/:machineId") async getFilesForMachine( @Query("limit", new DefaultValuePipe(20), ParseIntPipe) limit: number, diff --git a/apps/backend/src/app/machines/machines.dto.ts b/apps/backend/src/app/machines/machines.dto.ts index 0d1bda8..bf9945b 100644 --- a/apps/backend/src/app/machines/machines.dto.ts +++ b/apps/backend/src/app/machines/machines.dto.ts @@ -1,16 +1,16 @@ +import { ApiProperty } from "@nestjs/swagger"; import { IsUUID, MaxLength, MinLength } from "class-validator"; -import { ApiProperty } from '@nestjs/swagger'; export class CreateMachineDto { @ApiProperty({ - example: "Découpeuse laser portable" + example: "Découpeuse laser portable", }) @MaxLength(128) @MinLength(4) machineName: string; @ApiProperty({ - example: "Découpe au laser" + example: "Découpe au laser", }) @MaxLength(64) @MinLength(2) @@ -19,8 +19,9 @@ export class CreateMachineDto { export class TypeDto { @ApiProperty({ - description: "Un identifiant unique présent en base de donnée qui représente un MIME", - example: "dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c" + description: + "Un identifiant unique présent en base de donnée qui représente un MIME", + example: "dfd0fbb1-2bf3-4dbe-b86d-89b1bff5106c", }) @IsUUID() fileTypeId: string; diff --git a/apps/backend/src/main.ts b/apps/backend/src/main.ts index fcd4ae6..2c58031 100644 --- a/apps/backend/src/main.ts +++ b/apps/backend/src/main.ts @@ -2,7 +2,9 @@ import { Logger } from "@nestjs/common"; import { NestFactory } from "@nestjs/core"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; +import cors from "cors"; import helmet from "helmet"; + import { AppModule } from "./app/app.module"; async function bootstrap() { @@ -11,9 +13,9 @@ async function bootstrap() { .setDescription("Définition de l'api du FabLab Explorer") .setVersion("1.0") .addBearerAuth({ - type: 'http', - scheme: 'bearer', - in: 'header', + type: "http", + scheme: "bearer", + in: "header", }) .build(); @@ -23,6 +25,13 @@ async function bootstrap() { app.use(helmet()); const port = process.env.PORT || 3333; + const corsOptions = { + origin: "http://localhost:3000", + methods: ["GET", "POST", "PUT", "DELETE"], + }; + + app.use(cors(corsOptions)); + const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup("api", app, document);