From 498f85d24ebfe59eb8c30f377e30b135cd395d0a Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Wed, 21 Jan 2026 13:42:56 +0100 Subject: [PATCH] feat(contents): add `update` method with user ownership validation - Introduced `update` method in contents service to allow partial updates. - Implemented user ownership validation to ensure secure modifications. - Added cache clearing logic after successful updates. --- backend/src/contents/contents.service.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/src/contents/contents.service.ts b/backend/src/contents/contents.service.ts index 2c82425..04fe82d 100644 --- a/backend/src/contents/contents.service.ts +++ b/backend/src/contents/contents.service.ts @@ -194,6 +194,25 @@ export class ContentsService { return updated; } + async update(id: string, userId: string, data: any) { + this.logger.log(`Updating content ${id} for user ${userId}`); + + // Vérifier que le contenu appartient à l'utilisateur + const existing = await this.contentsRepository.findOne(id, userId); + if (!existing || existing.userId !== userId) { + throw new BadRequestException( + "Contenu non trouvé ou vous n'avez pas la permission de le modifier.", + ); + } + + const updated = await this.contentsRepository.update(id, data); + + if (updated) { + await this.clearContentsCache(); + } + return updated; + } + async findOne(idOrSlug: string, userId?: string) { const content = await this.contentsRepository.findOne(idOrSlug, userId); if (!content) return null;