1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-09-30 16:40:11 +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,
} from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { UserDTO } from "src/user/dto/user.dto";
import { AuthService } from "./auth.service";
import { AuthDTO } from "./dto/auth.dto";
import { AuthRegisterDTO } from "./dto/authRegister.dto";
import { AuthSignInDTO } from "./dto/authSignIn.dto";
import { RefreshAccessTokenDTO } from "./dto/refreshAccessToken.dto";
@Controller("auth")
@ -27,7 +28,7 @@ export class AuthController {
}
@Post("signIn")
signIn(@Body() dto: AuthDTO) {
signIn(@Body() dto: AuthSignInDTO) {
return this.authService.signIn(dto);
}

View File

@ -10,8 +10,8 @@ import { User } from "@prisma/client";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import * as argon from "argon2";
import { PrismaService } from "src/prisma/prisma.service";
import { AuthDTO } from "./dto/auth.dto";
import { AuthRegisterDTO } from "./dto/authRegister.dto";
import { AuthSignInDTO } from "./dto/authSignIn.dto";
@Injectable()
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({
where: {
email: dto.email,

View File

@ -1,4 +1,4 @@
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 { 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",
"password",
] as const) {}

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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";
export class ShareDTO {
@ -14,8 +14,8 @@ export class ShareDTO {
files: FileDTO[];
@Expose()
@Type(() => AuthDTO)
creator: AuthDTO;
@Type(() => AuthSignInDTO)
creator: AuthSignInDTO;
from(partial: Partial<ShareDTO>) {
return plainToClass(ShareDTO, partial, { excludeExtraneousValues: true });

View File

@ -1,7 +1,7 @@
import { Expose, plainToClass } from "class-transformer";
import { IsEmail, IsNotEmpty, IsString } from "class-validator";
export class AuthDTO {
export class UserDTO {
@Expose()
id: string;
@ -20,7 +20,7 @@ export class AuthDTO {
@IsString()
password: string;
constructor(partial: Partial<AuthDTO>) {
return plainToClass(AuthDTO, partial, { excludeExtraneousValues: true });
from(partial: Partial<UserDTO>) {
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 { GetUser } from "src/auth/decorator/getUser.decorator";
import { JwtGuard } from "src/auth/guard/jwt.guard";
import { UserDTO } from "./dto/user.dto";
@Controller("users")
export class UserController {
@Get("me")
@UseGuards(JwtGuard)
async getCurrentUser(@GetUser() user: User) {
return user;
return new UserDTO().from(user);
}
}