1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-10-01 00:50:10 +02:00

fix: dto returns

This commit is contained in:
Elias Schneider 2022-10-10 17:58:42 +02:00
parent 4bab33ad8a
commit 02beb66910
9 changed files with 20 additions and 17 deletions

View File

@ -6,10 +6,11 @@ import {
Post, Post,
} from "@nestjs/common"; } from "@nestjs/common";
import { ConfigService } from "@nestjs/config"; import { ConfigService } from "@nestjs/config";
import { UserDTO } from "src/user/dto/user.dto";
import { AuthService } from "./auth.service"; import { AuthService } from "./auth.service";
import { AuthDTO } from "./dto/auth.dto";
import { AuthRegisterDTO } from "./dto/authRegister.dto"; import { AuthRegisterDTO } from "./dto/authRegister.dto";
import { AuthSignInDTO } from "./dto/authSignIn.dto";
import { RefreshAccessTokenDTO } from "./dto/refreshAccessToken.dto"; import { RefreshAccessTokenDTO } from "./dto/refreshAccessToken.dto";
@Controller("auth") @Controller("auth")
@ -27,7 +28,7 @@ export class AuthController {
} }
@Post("signIn") @Post("signIn")
signIn(@Body() dto: AuthDTO) { signIn(@Body() dto: AuthSignInDTO) {
return this.authService.signIn(dto); return this.authService.signIn(dto);
} }

View File

@ -10,8 +10,8 @@ import { User } from "@prisma/client";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import * as argon from "argon2"; import * as argon from "argon2";
import { PrismaService } from "src/prisma/prisma.service"; import { PrismaService } from "src/prisma/prisma.service";
import { AuthDTO } from "./dto/auth.dto";
import { AuthRegisterDTO } from "./dto/authRegister.dto"; import { AuthRegisterDTO } from "./dto/authRegister.dto";
import { AuthSignInDTO } from "./dto/authSignIn.dto";
@Injectable() @Injectable()
export class AuthService { export class AuthService {
@ -44,7 +44,7 @@ export class AuthService {
} }
} }
async signIn(dto: AuthDTO) { async signIn(dto: AuthSignInDTO) {
const user = await this.prisma.user.findUnique({ const user = await this.prisma.user.findUnique({
where: { where: {
email: dto.email, email: dto.email,

View File

@ -1,4 +1,4 @@
import { PickType } from "@nestjs/swagger"; import { PickType } from "@nestjs/swagger";
import { AuthDTO } from "./auth.dto"; import { UserDTO } from "src/user/dto/user.dto";
export class AuthRegisterDTO extends AuthDTO {} export class AuthRegisterDTO extends UserDTO {}

View File

@ -1,7 +1,7 @@
import { PickType } from "@nestjs/swagger"; import { PickType } from "@nestjs/swagger";
import { AuthDTO } from "./auth.dto"; import { UserDTO } from "src/user/dto/user.dto";
export class AuthSignInDTO extends PickType(AuthDTO, [ export class AuthSignInDTO extends PickType(UserDTO, [
"email", "email",
"password", "password",
] as const) {} ] as const) {}

View File

@ -16,7 +16,7 @@ export class FileDTO {
share: ShareDTO; share: ShareDTO;
constructor(partial: Partial<FileDTO>) { from(partial: Partial<FileDTO>) {
return plainToClass(FileDTO, partial, { excludeExtraneousValues: true }); return plainToClass(FileDTO, partial, { excludeExtraneousValues: true });
} }
} }

View File

@ -15,6 +15,7 @@ import { FileInterceptor } from "@nestjs/platform-express";
import { Response } from "express"; import { Response } from "express";
import { JwtGuard } from "src/auth/guard/jwt.guard"; import { JwtGuard } from "src/auth/guard/jwt.guard";
import { FileDownloadGuard } from "src/file/guard/fileDownload.guard"; import { FileDownloadGuard } from "src/file/guard/fileDownload.guard";
import { ShareDTO } from "src/share/dto/share.dto";
import { ShareSecurityGuard } from "src/share/guard/shareSecurity.guard"; import { ShareSecurityGuard } from "src/share/guard/shareSecurity.guard";
import { FileService } from "./file.service"; import { FileService } from "./file.service";
@ -42,7 +43,7 @@ export class FileController {
file: Express.Multer.File, file: Express.Multer.File,
@Param("shareId") shareId: string @Param("shareId") shareId: string
) { ) {
return await this.fileService.create(file, shareId); return new ShareDTO().from( await this.fileService.create(file, shareId));
} }
@Get(":fileId/download") @Get(":fileId/download")

View File

@ -1,5 +1,5 @@
import { Expose, plainToClass, Type } from "class-transformer"; import { Expose, plainToClass, Type } from "class-transformer";
import { AuthDTO } from "src/auth/dto/auth.dto"; import { AuthSignInDTO } from "src/auth/dto/authSignIn.dto";
import { FileDTO } from "src/file/dto/file.dto"; import { FileDTO } from "src/file/dto/file.dto";
export class ShareDTO { export class ShareDTO {
@ -14,8 +14,8 @@ export class ShareDTO {
files: FileDTO[]; files: FileDTO[];
@Expose() @Expose()
@Type(() => AuthDTO) @Type(() => AuthSignInDTO)
creator: AuthDTO; creator: AuthSignInDTO;
from(partial: Partial<ShareDTO>) { from(partial: Partial<ShareDTO>) {
return plainToClass(ShareDTO, partial, { excludeExtraneousValues: true }); return plainToClass(ShareDTO, partial, { excludeExtraneousValues: true });

View File

@ -1,7 +1,7 @@
import { Expose, plainToClass } from "class-transformer"; import { Expose, plainToClass } from "class-transformer";
import { IsEmail, IsNotEmpty, IsString } from "class-validator"; import { IsEmail, IsNotEmpty, IsString } from "class-validator";
export class AuthDTO { export class UserDTO {
@Expose() @Expose()
id: string; id: string;
@ -20,7 +20,7 @@ export class AuthDTO {
@IsString() @IsString()
password: string; password: string;
constructor(partial: Partial<AuthDTO>) { from(partial: Partial<UserDTO>) {
return plainToClass(AuthDTO, partial, { excludeExtraneousValues: true }); return plainToClass(UserDTO, partial, { excludeExtraneousValues: true });
} }
} }

View File

@ -2,12 +2,13 @@ import { Controller, Get, UseGuards } from "@nestjs/common";
import { User } from "@prisma/client"; import { User } from "@prisma/client";
import { GetUser } from "src/auth/decorator/getUser.decorator"; import { GetUser } from "src/auth/decorator/getUser.decorator";
import { JwtGuard } from "src/auth/guard/jwt.guard"; import { JwtGuard } from "src/auth/guard/jwt.guard";
import { UserDTO } from "./dto/user.dto";
@Controller("users") @Controller("users")
export class UserController { export class UserController {
@Get("me") @Get("me")
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async getCurrentUser(@GetUser() user: User) { async getCurrentUser(@GetUser() user: User) {
return user; return new UserDTO().from(user);
} }
} }