fix: rename DTO name

This commit is contained in:
Hackntosh 2024-02-03 17:00:10 +00:00
parent 2f33a05eab
commit ac9026aea6
6 changed files with 86 additions and 88 deletions

View file

@ -1,3 +1,3 @@
{ {
"extends": ["@commitlint/config-conventional"] "extends": ["@commitlint/config-conventional"]
} }

View file

@ -1,4 +1 @@
import { PartialType } from "@nestjs/swagger"; export class UpdateKweekDTO {}
import { CreateKweekDto } from "./create-kweek.dto";
export class UpdateKweekDto extends PartialType(CreateKweekDto) {}

View file

@ -1,93 +1,94 @@
import { FilesInterceptor } from "@nest-lab/fastify-multer";
import { import {
Controller, Body,
Get, Controller,
Post, Delete,
Body, Get,
Patch, Param,
Param, Patch,
Delete, Post,
UseInterceptors, Request,
UploadedFiles, UploadedFiles,
Request, UseInterceptors,
} from "@nestjs/common"; } from "@nestjs/common";
import { KweeksService } from "./kweeks.service";
import { CreateKweekDTO } from "./dto/create-kweek.dto";
import { UpdateKweekDto } from "./dto/update-kweek.dto";
import { import {
ApiBearerAuth, ApiBearerAuth,
ApiConsumes, ApiConsumes,
ApiOperation, ApiOperation,
ApiTags, ApiTags,
} from "@nestjs/swagger"; } from "@nestjs/swagger";
import { Public } from "src/public.decorator"; 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") @ApiTags("Kweeks")
@Controller("kweeks") @Controller("kweeks")
export class KweeksController { export class KweeksController {
constructor(private readonly kweeksService: KweeksService) {} constructor(private readonly kweeksService: KweeksService) {}
@Post() @Post()
@ApiOperation({ summary: "Creates a kweek" }) @ApiOperation({ summary: "Creates a kweek" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
@ApiConsumes("multipart/form-data") @ApiConsumes("multipart/form-data")
@UseInterceptors(FilesInterceptor("attachments", 4)) @UseInterceptors(FilesInterceptor("attachments", 4))
create( create(
@Body() createKweekDto: CreateKweekDTO, @Body() createKweekDto: CreateKweekDTO,
@UploadedFiles() attachments: File, @UploadedFiles() attachments: File,
@Request() req, @Request() req,
) { ) {
return this.kweeksService.create(createKweekDto); // TODO: Find a way to handle multiple files with Swagger
} return this.kweeksService.create(createKweekDto);
}
@Public() @Public()
@Get(":id") @Get(":id")
@ApiOperation({ summary: "Retrieves information about a kweek" }) @ApiOperation({ summary: "Retrieves information about a kweek" })
findOne(@Param("id") id: string) { findOne(@Param("id") id: string) {
return this.kweeksService.findOne(+id); return this.kweeksService.findOne(+id);
} }
@Patch(":id") @Patch(":id")
@ApiOperation({ summary: "Updates a kweek content" }) @ApiOperation({ summary: "Updates a kweek content" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
update(@Param("id") id: string, @Body() updateKweekDto: UpdateKweekDto) { update(@Param("id") id: string, @Body() updateKweekDto: UpdateKweekDTO ) {
return this.kweeksService.update(+id, updateKweekDto); return this.kweeksService.update(+id, updateKweekDto);
} }
@Delete(":id") @Delete(":id")
@ApiOperation({ summary: "Deletes a kweek" }) @ApiOperation({ summary: "Deletes a kweek" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
remove(@Param("id") id: string) { remove(@Param("id") id: string) {
return this.kweeksService.remove(+id); return this.kweeksService.remove(+id);
} }
@Post(":id/like") @Post(":id/like")
@ApiOperation({ summary: "Likes a kweek" }) @ApiOperation({ summary: "Likes a kweek" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
likeKweek() {} likeKweek() {}
@Public() @Public()
@Get(":id/comments") @Get(":id/comments")
@ApiOperation({ summary: "Retrieves comments of a kweek" }) @ApiOperation({ summary: "Retrieves comments of a kweek" })
comments() {} comments() {}
@Public() @Public()
@Get(":id/comments/:comment_id") @Get(":id/comments/:comment_id")
@ApiOperation({ summary: "Retrieves information about a comment" }) @ApiOperation({ summary: "Retrieves information about a comment" })
comment() {} comment() {}
@Patch(":id/comments/:comment_id") @Patch(":id/comments/:comment_id")
@ApiOperation({ summary: "Updates a comment content" }) @ApiOperation({ summary: "Updates a comment content" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
updateComment() {} updateComment() {}
@Delete(":id/comments/:comment_id") @Delete(":id/comments/:comment_id")
@ApiOperation({ summary: "Deletes a comment" }) @ApiOperation({ summary: "Deletes a comment" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
removeComment() {} removeComment() {}
@Post(":id/comments/:comment_id/like") @Post(":id/comments/:comment_id/like")
@ApiOperation({ summary: "Likes a comment" }) @ApiOperation({ summary: "Likes a comment" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
likeComment() {} likeComment() {}
} }

View file

@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common"; import { Injectable } from "@nestjs/common";
import { PrismaService } from "src/prisma/prisma.service"; import { PrismaService } from "src/prisma/prisma.service";
import { CreateKweekDTO } from "./dto/create-kweek.dto"; import { CreateKweekDTO } from "./dto/create-kweek.dto";
import { UpdateKweekDto } from "./dto/update-kweek.dto"; import { UpdateKweekDTO } from "./dto/update-kweek.dto";
@Injectable() @Injectable()
export class KweeksService { export class KweeksService {
@ -14,7 +14,7 @@ export class KweeksService {
return `This action returns a #${id} kweek`; return `This action returns a #${id} kweek`;
} }
update(id: number, updateKweekDto: UpdateKweekDto) { update(id: number, updateKweekDto: UpdateKweekDTO) {
return `This action updates a #${id} kweek`; return `This action updates a #${id} kweek`;
} }

View file

@ -125,6 +125,6 @@ export class UserController {
@ApiOperation({ summary: "Deletes the account of a logged user" }) @ApiOperation({ summary: "Deletes the account of a logged user" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
delete(@Request() req) { delete(@Request() req) {
return this.userService.delete(req.user.id) return this.userService.delete(req.user.id);
} }
} }

View file

@ -107,11 +107,11 @@ export class UserService {
} }
async updateEmail( async updateEmail(
loggedUser: User, id: string,
email: string, email: string,
): Promise<{ message: string }> { ): Promise<{ message: string }> {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { id: loggedUser.id }, where: { id },
}); });
if (email !== undefined && email.trim() !== user.email) { if (email !== undefined && email.trim() !== user.email) {
@ -124,7 +124,7 @@ export class UserService {
await this.prisma.user.update({ await this.prisma.user.update({
where: { where: {
id: loggedUser.id, id,
}, },
data: { data: {
email: email ?? user.email, email: email ?? user.email,
@ -136,12 +136,12 @@ export class UserService {
} }
async updateName( async updateName(
loggedUser: User, id: string,
username: string | undefined, username: string | undefined,
displayName: string, displayName: string,
): Promise<Pick<User, "username" | "displayName">> { ): Promise<Pick<User, "username" | "displayName">> {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { id: loggedUser.id }, where: { id },
}); });
if (username !== undefined && username.trim() !== user.username) { if (username !== undefined && username.trim() !== user.username) {
@ -155,7 +155,7 @@ export class UserService {
return await this.prisma.user.update({ return await this.prisma.user.update({
where: { where: {
id: loggedUser.id, id
}, },
data: { data: {
displayName, displayName,