feat(contents): enhance user-specific data handling and admin content management

Integrate user-specific fields (`isLiked`, `favoritesCount`) in content APIs and improve `ContentCard` through reactive updates. Add admin-only content deletion support. Refactor services and repository to enrich responses with additional data (author details, tags).
This commit is contained in:
Mathis HERRIOT
2026-01-14 21:43:44 +01:00
parent fb7ddde42e
commit d7c2a965a0
6 changed files with 152 additions and 14 deletions

View File

@@ -126,7 +126,18 @@ export class ContentsService {
this.contentsRepository.count(options),
]);
return { data, totalCount };
const processedData = data.map((content) => ({
...content,
url: this.getFileUrl(content.storageKey),
author: {
...content.author,
avatarUrl: content.author?.avatarUrl
? this.getFileUrl(content.author.avatarUrl)
: null,
},
}));
return { data: processedData, totalCount };
}
async create(userId: string, data: CreateContentDto) {
@@ -162,8 +173,30 @@ export class ContentsService {
return deleted;
}
async findOne(idOrSlug: string) {
return this.contentsRepository.findOne(idOrSlug);
async removeAdmin(id: string) {
this.logger.log(`Removing content ${id} by admin`);
const deleted = await this.contentsRepository.softDeleteAdmin(id);
if (deleted) {
await this.clearContentsCache();
}
return deleted;
}
async findOne(idOrSlug: string, userId?: string) {
const content = await this.contentsRepository.findOne(idOrSlug, userId);
if (!content) return null;
return {
...content,
url: this.getFileUrl(content.storageKey),
author: {
...content.author,
avatarUrl: content.author?.avatarUrl
? this.getFileUrl(content.author.avatarUrl)
: null,
},
};
}
generateBotHtml(content: { title: string; storageKey: string }): string {