implement file module and add files relation to booking entity and populate on fetch

This commit is contained in:
marshal
2026-05-25 10:19:08 +03:00
parent ae317540c1
commit 9432814e3b
12 changed files with 245 additions and 44 deletions

View File

@@ -0,0 +1,28 @@
import { Controller, Get, Param, ParseUUIDPipe, Res } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { Response } from "express";
import { FilesService } from "./files.service";
@ApiTags("files")
@Controller("files")
export class FilesController {
constructor(private readonly filesService: FilesService) {}
@Get(":fileId")
@ApiOperation({
summary: "Download a file by ID",
description:
"Global endpoint — streams any uploaded file directly from MinIO by its UUID. " +
"No resource context (e.g. booking ID) required.",
})
async download(
@Param("fileId", ParseUUIDPipe) fileId: string,
@Res() res: Response,
) {
const { stream, record } = await this.filesService.streamById(fileId);
res.setHeader("Content-Type", record.mimeType);
res.setHeader("Content-Disposition", `attachment; filename="${record.name}"`);
stream.pipe(res);
}
}