feat(canina): implement multi-select bulk media delete, fix logo clipping, fix blog API URLs, and improve dosage labels
This commit is contained in:
1 parent
7e403bd53e
commit
b161ecf815
8 files changed
+203
-46
No files matched your search
@@ -39,6 +39,17 @@ export class MediaController {
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('bulk')
|
||||
@ApiOperation({ summary: 'حذف دستهجمعی فایلها' })
|
||||
async deleteManyMedia(@Body('ids') ids: string[]) {
|
||||
if (!ids || !Array.isArray(ids) || ids.length === 0) {
|
||||
throw new BadRequestException('لیست شناسههای رسانه الزامی است');
|
||||
}
|
||||
const data = await this.mediaService.deleteManyMedia(ids);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف فایل' })
|
||||
|
||||
@@ -62,6 +62,33 @@ export class MediaService {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
async deleteManyMedia(ids: string[]) {
|
||||
const mediaItems = await this.prisma.media.findMany({
|
||||
where: { id: { in: ids } },
|
||||
});
|
||||
|
||||
for (const media of mediaItems) {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
'uploads',
|
||||
path.basename(media.url),
|
||||
);
|
||||
if (fs.existsSync(filePath)) {
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch {
|
||||
// Ignore individual unlink errors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.prisma.media.deleteMany({
|
||||
where: { id: { in: ids } },
|
||||
});
|
||||
|
||||
return { success: true, count: mediaItems.length };
|
||||
}
|
||||
|
||||
async updateMedia(
|
||||
id: string,
|
||||
data: {
|
||||
|
||||
Reference in new issue
Block a user