1
0
Files
aaaa/src/auth/auth.controller.ts
2025-11-13 11:09:27 +04:00

56 lines
1.4 KiB
TypeScript

import {
Controller,
Post,
Body,
UseInterceptors,
UploadedFile,
} from "@nestjs/common";
import {AuthService} from "./auth.service";
import {ApiBody, ApiConsumes, ApiTags} from "@nestjs/swagger";
import {FileInterceptor} from "@nestjs/platform-express";
import {RegisterDto} from "./dto/register.dto";
import {LoginDto} from "./dto/login.dto";
import {ImageValidationInterceptor} from "../common/interceptors/image-validation.interceptor";
@ApiTags("auth")
@Controller("auth")
export class AuthController {
constructor(private readonly auth: AuthService) {
}
@Post("register")
@ApiConsumes("multipart/form-data")
@ApiBody({
schema: {
type: "object",
properties: {
username: {type: "string"},
email: {type: "string"},
password: {type: "string"},
name: {type: "string"},
file: {
type: "string",
format: "binary",
description: "avatar WEBP <= 10MB, <= 1920px",
},
},
required: ["username", "email", "password"],
},
})
@UseInterceptors(
FileInterceptor("file", {limits: {fileSize: 10 * 1024 * 1024}}),
new ImageValidationInterceptor({required: false, fieldName: "file"}),
)
async register(
@Body() dto: RegisterDto,
@UploadedFile() file?: Express.Multer.File,
) {
return this.auth.register(dto, file);
}
@Post("login")
async login(@Body() dto: LoginDto) {
return this.auth.login(dto);
}
}