feat: cho phép người dùng chỉnh sửa thông tin ảnh đã upload
This commit is contained in:
Vendored
+48
-2
@@ -501,7 +501,13 @@ let PublicTourController = class PublicTourController {
|
||||
}
|
||||
}
|
||||
},
|
||||
photos: true,
|
||||
photos: {
|
||||
include: {
|
||||
uploader: {
|
||||
select: { id: true, name: true }
|
||||
}
|
||||
}
|
||||
},
|
||||
legs: {
|
||||
orderBy: { sequence: 'asc' },
|
||||
include: {
|
||||
@@ -850,7 +856,13 @@ let TourController = class TourController {
|
||||
}
|
||||
}
|
||||
},
|
||||
photos: true,
|
||||
photos: {
|
||||
include: {
|
||||
uploader: {
|
||||
select: { id: true, name: true }
|
||||
}
|
||||
}
|
||||
},
|
||||
legs: {
|
||||
orderBy: { sequence: 'asc' },
|
||||
include: {
|
||||
@@ -1695,6 +1707,31 @@ let PhotoController = class PhotoController {
|
||||
await this.prisma.photo.delete({ where: { id } });
|
||||
return { message: 'Ảnh đã được xóa thành công.' };
|
||||
}
|
||||
async updatePhoto(id, body, req) {
|
||||
const photo = await this.prisma.photo.findUnique({
|
||||
where: { id }
|
||||
});
|
||||
if (!photo) {
|
||||
throw new common_1.NotFoundException('Không tìm thấy ảnh.');
|
||||
}
|
||||
if (photo.uploaderId !== req.user.id && !req.user.isAdmin) {
|
||||
throw new common_1.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 || {};
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('upload-anonymous'),
|
||||
@@ -1714,6 +1751,15 @@ __decorate([
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], PhotoController.prototype, "deletePhoto", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)(':id'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__param(2, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], PhotoController.prototype, "updatePhoto", null);
|
||||
PhotoController = __decorate([
|
||||
(0, common_1.Controller)('photos'),
|
||||
(0, exports.Roles)(client_1.ParticipantRole.OWNER, client_1.ParticipantRole.MANAGER, client_1.ParticipantRole.MEMBER, client_1.ParticipantRole.MEMBER_NO_FINANCE),
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+50
-2
@@ -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)
|
||||
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 MiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 790 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 459 KiB |
Reference in New Issue
Block a user