From 4c7ed8ea0d5c58493f5c9c93fe2483e7c09bed38 Mon Sep 17 00:00:00 2001 From: y8a5y Date: Sun, 21 Dec 2025 14:30:02 +0100 Subject: [PATCH] refacto(Resume Service): move view count increment outside of findOne --- apps/server/src/resume/resume.service.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/server/src/resume/resume.service.ts b/apps/server/src/resume/resume.service.ts index 53d4ab243..3a4669a7d 100644 --- a/apps/server/src/resume/resume.service.ts +++ b/apps/server/src/resume/resume.service.ts @@ -84,21 +84,19 @@ export class ResumeService { }; } - async findOneByUsernameSlug(username: string, slug: string, userId?: string) { - const resume = await this.prisma.resume.findFirstOrThrow({ + async findOneByUsernameSlug(username: string, slug: string) { + return await this.prisma.resume.findFirstOrThrow({ where: { user: { username }, slug, visibility: "public" }, }); + } + async incrementViewCountForOne(resumeId: string) { // Update statistics: increment the number of views by 1 - if (!userId) { - await this.prisma.statistics.upsert({ - where: { resumeId: resume.id }, - create: { views: 1, downloads: 0, resumeId: resume.id }, - update: { views: { increment: 1 } }, - }); - } - - return resume; + await this.prisma.statistics.upsert({ + where: { resumeId }, + create: { views: 1, downloads: 0, resumeId }, + update: { views: { increment: 1 } }, + }); } async update(userId: string, id: string, updateResumeDto: UpdateResumeDto) {