fix: bố cục lại cách hiển thị thông tin ảnh
This commit is contained in:
@@ -1723,6 +1723,52 @@ class PhotoController {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Post(':id/toggle-like')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
async toggleLikePhoto(@Param('id', ParseUUIDPipe) id: string, @Req() req: any) {
|
||||
const userId = req.user.id;
|
||||
const photo = await this.prisma.photo.findUnique({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
if (!photo) {
|
||||
throw new NotFoundException('Không tìm thấy ảnh.');
|
||||
}
|
||||
|
||||
const currentMetadata = (photo.metadata as any) || {};
|
||||
const likedUserIds = Array.isArray(currentMetadata.likedUserIds)
|
||||
? currentMetadata.likedUserIds
|
||||
: [];
|
||||
|
||||
const index = likedUserIds.indexOf(userId);
|
||||
let updatedLikedUserIds = [...likedUserIds];
|
||||
|
||||
if (index > -1) {
|
||||
// Unlike
|
||||
updatedLikedUserIds.splice(index, 1);
|
||||
} else {
|
||||
// Like
|
||||
updatedLikedUserIds.push(userId);
|
||||
}
|
||||
|
||||
const updatedMetadata = {
|
||||
...currentMetadata,
|
||||
likedUserIds: updatedLikedUserIds
|
||||
};
|
||||
|
||||
return this.prisma.photo.update({
|
||||
where: { id },
|
||||
data: {
|
||||
metadata: updatedMetadata
|
||||
},
|
||||
include: {
|
||||
uploader: {
|
||||
select: { id: true, name: true }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
|
||||
Reference in New Issue
Block a user