diff --git a/.commitlintrc.json b/.commitlintrc.json index c30e5a9..32b50ea 100644 --- a/.commitlintrc.json +++ b/.commitlintrc.json @@ -1,3 +1,3 @@ { - "extends": ["@commitlint/config-conventional"] + "extends": ["@commitlint/config-conventional"] } diff --git a/src/kweeks/dto/update-kweek.dto.ts b/src/kweeks/dto/update-kweek.dto.ts index c752e4c..31c5b25 100644 --- a/src/kweeks/dto/update-kweek.dto.ts +++ b/src/kweeks/dto/update-kweek.dto.ts @@ -1,4 +1 @@ -import { PartialType } from "@nestjs/swagger"; -import { CreateKweekDto } from "./create-kweek.dto"; - -export class UpdateKweekDto extends PartialType(CreateKweekDto) {} +export class UpdateKweekDTO {} diff --git a/src/kweeks/kweeks.controller.ts b/src/kweeks/kweeks.controller.ts index 026e4e0..01ccd22 100644 --- a/src/kweeks/kweeks.controller.ts +++ b/src/kweeks/kweeks.controller.ts @@ -1,93 +1,94 @@ +import { FilesInterceptor } from "@nest-lab/fastify-multer"; import { - Controller, - Get, - Post, - Body, - Patch, - Param, - Delete, - UseInterceptors, - UploadedFiles, - Request, + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + Request, + UploadedFiles, + UseInterceptors, } from "@nestjs/common"; -import { KweeksService } from "./kweeks.service"; -import { CreateKweekDTO } from "./dto/create-kweek.dto"; -import { UpdateKweekDto } from "./dto/update-kweek.dto"; import { - ApiBearerAuth, - ApiConsumes, - ApiOperation, - ApiTags, + ApiBearerAuth, + ApiConsumes, + ApiOperation, + ApiTags, } from "@nestjs/swagger"; import { Public } from "src/public.decorator"; -import { FilesInterceptor } from "@nest-lab/fastify-multer"; +import { CreateKweekDTO } from "./dto/create-kweek.dto"; +import { UpdateKweekDTO } from "./dto/update-kweek.dto"; +import { KweeksService } from "./kweeks.service"; @ApiTags("Kweeks") @Controller("kweeks") export class KweeksController { - constructor(private readonly kweeksService: KweeksService) {} + constructor(private readonly kweeksService: KweeksService) {} - @Post() - @ApiOperation({ summary: "Creates a kweek" }) - @ApiBearerAuth("JWT") - @ApiConsumes("multipart/form-data") - @UseInterceptors(FilesInterceptor("attachments", 4)) - create( - @Body() createKweekDto: CreateKweekDTO, - @UploadedFiles() attachments: File, - @Request() req, - ) { - return this.kweeksService.create(createKweekDto); - } + @Post() + @ApiOperation({ summary: "Creates a kweek" }) + @ApiBearerAuth("JWT") + @ApiConsumes("multipart/form-data") + @UseInterceptors(FilesInterceptor("attachments", 4)) + create( + @Body() createKweekDto: CreateKweekDTO, + @UploadedFiles() attachments: File, + @Request() req, + ) { + // TODO: Find a way to handle multiple files with Swagger + return this.kweeksService.create(createKweekDto); + } - @Public() - @Get(":id") - @ApiOperation({ summary: "Retrieves information about a kweek" }) - findOne(@Param("id") id: string) { - return this.kweeksService.findOne(+id); - } + @Public() + @Get(":id") + @ApiOperation({ summary: "Retrieves information about a kweek" }) + findOne(@Param("id") id: string) { + return this.kweeksService.findOne(+id); + } - @Patch(":id") - @ApiOperation({ summary: "Updates a kweek content" }) - @ApiBearerAuth("JWT") - update(@Param("id") id: string, @Body() updateKweekDto: UpdateKweekDto) { - return this.kweeksService.update(+id, updateKweekDto); - } + @Patch(":id") + @ApiOperation({ summary: "Updates a kweek content" }) + @ApiBearerAuth("JWT") + update(@Param("id") id: string, @Body() updateKweekDto: UpdateKweekDTO ) { + return this.kweeksService.update(+id, updateKweekDto); + } - @Delete(":id") - @ApiOperation({ summary: "Deletes a kweek" }) - @ApiBearerAuth("JWT") - remove(@Param("id") id: string) { - return this.kweeksService.remove(+id); - } + @Delete(":id") + @ApiOperation({ summary: "Deletes a kweek" }) + @ApiBearerAuth("JWT") + remove(@Param("id") id: string) { + return this.kweeksService.remove(+id); + } - @Post(":id/like") - @ApiOperation({ summary: "Likes a kweek" }) - @ApiBearerAuth("JWT") - likeKweek() {} + @Post(":id/like") + @ApiOperation({ summary: "Likes a kweek" }) + @ApiBearerAuth("JWT") + likeKweek() {} - @Public() - @Get(":id/comments") - @ApiOperation({ summary: "Retrieves comments of a kweek" }) - comments() {} + @Public() + @Get(":id/comments") + @ApiOperation({ summary: "Retrieves comments of a kweek" }) + comments() {} - @Public() - @Get(":id/comments/:comment_id") - @ApiOperation({ summary: "Retrieves information about a comment" }) - comment() {} + @Public() + @Get(":id/comments/:comment_id") + @ApiOperation({ summary: "Retrieves information about a comment" }) + comment() {} - @Patch(":id/comments/:comment_id") - @ApiOperation({ summary: "Updates a comment content" }) - @ApiBearerAuth("JWT") - updateComment() {} + @Patch(":id/comments/:comment_id") + @ApiOperation({ summary: "Updates a comment content" }) + @ApiBearerAuth("JWT") + updateComment() {} - @Delete(":id/comments/:comment_id") - @ApiOperation({ summary: "Deletes a comment" }) - @ApiBearerAuth("JWT") - removeComment() {} + @Delete(":id/comments/:comment_id") + @ApiOperation({ summary: "Deletes a comment" }) + @ApiBearerAuth("JWT") + removeComment() {} - @Post(":id/comments/:comment_id/like") - @ApiOperation({ summary: "Likes a comment" }) - @ApiBearerAuth("JWT") - likeComment() {} + @Post(":id/comments/:comment_id/like") + @ApiOperation({ summary: "Likes a comment" }) + @ApiBearerAuth("JWT") + likeComment() {} } diff --git a/src/kweeks/kweeks.service.ts b/src/kweeks/kweeks.service.ts index f7021a0..e4175f1 100644 --- a/src/kweeks/kweeks.service.ts +++ b/src/kweeks/kweeks.service.ts @@ -1,7 +1,7 @@ import { Injectable } from "@nestjs/common"; import { PrismaService } from "src/prisma/prisma.service"; import { CreateKweekDTO } from "./dto/create-kweek.dto"; -import { UpdateKweekDto } from "./dto/update-kweek.dto"; +import { UpdateKweekDTO } from "./dto/update-kweek.dto"; @Injectable() export class KweeksService { @@ -14,7 +14,7 @@ export class KweeksService { return `This action returns a #${id} kweek`; } - update(id: number, updateKweekDto: UpdateKweekDto) { + update(id: number, updateKweekDto: UpdateKweekDTO) { return `This action updates a #${id} kweek`; } diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 97702b8..3e44ff0 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -125,6 +125,6 @@ export class UserController { @ApiOperation({ summary: "Deletes the account of a logged user" }) @ApiBearerAuth("JWT") delete(@Request() req) { - return this.userService.delete(req.user.id) - } + return this.userService.delete(req.user.id); + } } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 8ae90c1..f5e8c00 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -107,11 +107,11 @@ export class UserService { } async updateEmail( - loggedUser: User, + id: string, email: string, ): Promise<{ message: string }> { const user = await this.prisma.user.findFirst({ - where: { id: loggedUser.id }, + where: { id }, }); if (email !== undefined && email.trim() !== user.email) { @@ -124,7 +124,7 @@ export class UserService { await this.prisma.user.update({ where: { - id: loggedUser.id, + id, }, data: { email: email ?? user.email, @@ -136,12 +136,12 @@ export class UserService { } async updateName( - loggedUser: User, + id: string, username: string | undefined, displayName: string, ): Promise> { const user = await this.prisma.user.findFirst({ - where: { id: loggedUser.id }, + where: { id }, }); if (username !== undefined && username.trim() !== user.username) { @@ -155,7 +155,7 @@ export class UserService { return await this.prisma.user.update({ where: { - id: loggedUser.id, + id }, data: { displayName,