mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-18 04:29:40 +02:00
- Move finance, mail, moodlit to apps-archived for later development - Rename games/voxel-lava to games/voxelava 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
ParseUUIDPipe,
|
|
} from '@nestjs/common';
|
|
import { JwtAuthGuard, CurrentUser, CurrentUserData } from '@manacore/shared-nestjs-auth';
|
|
import { AttachmentService } from './attachment.service';
|
|
import { AttachmentQueryDto, CreateAttachmentDto, UploadUrlDto } from './dto/attachment.dto';
|
|
|
|
@Controller()
|
|
@UseGuards(JwtAuthGuard)
|
|
export class AttachmentController {
|
|
constructor(private readonly attachmentService: AttachmentService) {}
|
|
|
|
@Get('emails/:emailId/attachments')
|
|
async findByEmail(
|
|
@CurrentUser() user: CurrentUserData,
|
|
@Param('emailId', ParseUUIDPipe) emailId: string
|
|
) {
|
|
const attachments = await this.attachmentService.findByEmailId(emailId, user.userId);
|
|
return { attachments };
|
|
}
|
|
|
|
@Get('attachments/:id')
|
|
async findOne(@CurrentUser() user: CurrentUserData, @Param('id', ParseUUIDPipe) id: string) {
|
|
const attachment = await this.attachmentService.findById(id, user.userId);
|
|
if (!attachment) {
|
|
return { attachment: null };
|
|
}
|
|
return { attachment };
|
|
}
|
|
|
|
@Post('attachments')
|
|
async create(@CurrentUser() user: CurrentUserData, @Body() dto: CreateAttachmentDto) {
|
|
const attachment = await this.attachmentService.create({
|
|
...dto,
|
|
userId: user.userId,
|
|
});
|
|
return { attachment };
|
|
}
|
|
|
|
@Delete('attachments/:id')
|
|
async delete(@CurrentUser() user: CurrentUserData, @Param('id', ParseUUIDPipe) id: string) {
|
|
await this.attachmentService.delete(id, user.userId);
|
|
return { success: true };
|
|
}
|
|
|
|
// Get presigned URL for client-side upload
|
|
@Post('attachments/upload-url')
|
|
async getUploadUrl(@CurrentUser() user: CurrentUserData, @Body() dto: UploadUrlDto) {
|
|
const result = await this.attachmentService.getUploadUrl(user.userId, dto);
|
|
return result;
|
|
}
|
|
|
|
// Get presigned URL for downloading
|
|
@Get('attachments/:id/download')
|
|
async getDownloadUrl(
|
|
@CurrentUser() user: CurrentUserData,
|
|
@Param('id', ParseUUIDPipe) id: string
|
|
) {
|
|
const result = await this.attachmentService.getDownloadUrl(id, user.userId);
|
|
return result;
|
|
}
|
|
|
|
// Mark attachment as uploaded (called after client uploads to presigned URL)
|
|
@Post('attachments/:id/complete')
|
|
async markUploaded(
|
|
@CurrentUser() user: CurrentUserData,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() body: { storageKey: string }
|
|
) {
|
|
const attachment = await this.attachmentService.markUploaded(id, user.userId, body.storageKey);
|
|
return { attachment };
|
|
}
|
|
}
|