feat: cho phép người dùng chỉnh sửa thông tin ảnh đã upload

This commit is contained in:
2026-06-20 07:37:01 +07:00
parent 4373ed684a
commit 9da8a9494d
18 changed files with 987 additions and 298 deletions
+50 -2
View File
@@ -484,7 +484,13 @@ class PublicTourController {
}
}
},
photos: true,
photos: {
include: {
uploader: {
select: { id: true, name: true }
}
}
},
legs: {
orderBy: { sequence: 'asc' },
include: {
@@ -913,7 +919,13 @@ class TourController {
}
}
},
photos: true,
photos: {
include: {
uploader: {
select: { id: true, name: true }
}
}
},
legs: {
orderBy: { sequence: 'asc' },
include: {
@@ -1675,6 +1687,42 @@ class PhotoController {
await this.prisma.photo.delete({ where: { id } });
return { message: 'Ảnh đã được xóa thành công.' };
}
@Patch(':id')
async updatePhoto(
@Param('id', ParseUUIDPipe) id: string,
@Body() body: { title?: string; description?: string; latitude?: number; longitude?: number },
@Req() req: any
) {
const photo = await this.prisma.photo.findUnique({
where: { id }
});
if (!photo) {
throw new NotFoundException('Không tìm thấy ảnh.');
}
// Chỉ người tải lên hoặc Admin mới có quyền sửa thông tin ảnh
if (photo.uploaderId !== req.user.id && !req.user.isAdmin) {
throw new ForbiddenException('Bạn không có quyền chỉnh sửa thông tin của bức ảnh này.');
}
const currentMetadata = (photo.metadata as any) || {};
const updatedMetadata = {
...currentMetadata,
lat: body.latitude !== undefined ? body.latitude : currentMetadata.lat,
lng: body.longitude !== undefined ? body.longitude : currentMetadata.lng,
title: body.title !== undefined ? body.title : currentMetadata.title,
description: body.description !== undefined ? body.description : currentMetadata.description,
};
return this.prisma.photo.update({
where: { id },
data: {
metadata: updatedMetadata
}
});
}
}
@UseGuards(JwtAuthGuard)