Skip to content

Commit 6b60511

Browse files
authored
Merge pull request #75 from Emmanuel-Ugochukwu1/feat/audit-detail-page
feat: implement audit detail page with findings view (#32)
2 parents 00a8449 + 35f3f1e commit 6b60511

8 files changed

Lines changed: 942 additions & 303 deletions

File tree

apps/api/src/modules/audits/audits.controller.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
1+
import { Body, Controller, Get, Param, Patch, Post, Query, UseGuards } from '@nestjs/common';
22
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
33

44
import { CurrentUser } from '../../common/decorators/current-user.decorator';
@@ -30,4 +30,14 @@ export class AuditsController {
3030
findOne(@Param('id') id: string, @CurrentUser('id') userId: string) {
3131
return this.auditsService.findOne(id, userId);
3232
}
33+
34+
@Patch('findings/:id')
35+
@ApiOperation({ summary: 'Update finding status' })
36+
updateFindingStatus(
37+
@Param('id') id: string,
38+
@Body() body: { status: string },
39+
@CurrentUser('id') userId: string,
40+
) {
41+
return this.auditsService.updateFindingStatus(id, body.status, userId);
42+
}
3343
}

apps/api/src/modules/audits/audits.service.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { ForbiddenException, Injectable, NotFoundException } from '@nestjs/common';
1+
import {
2+
BadRequestException,
3+
ForbiddenException,
4+
Injectable,
5+
NotFoundException,
6+
} from '@nestjs/common';
27
import { logger } from '@veridion/logger';
38

49
import { CacheService } from '../../common/cache/cache.service';
@@ -106,4 +111,30 @@ export class AuditsService {
106111
private auditCachePrefix(userId: string): string {
107112
return `audits:${userId}:`;
108113
}
114+
115+
async updateFindingStatus(findingId: string, status: string, userId: string) {
116+
const validStatuses = ['OPEN', 'ACKNOWLEDGED', 'FALSE_POSITIVE', 'RESOLVED'];
117+
if (!validStatuses.includes(status)) {
118+
throw new BadRequestException(`Invalid status. Must be one of: ${validStatuses.join(', ')}`);
119+
}
120+
121+
const finding = await this.prisma.db.auditFinding.findUnique({
122+
where: { id: findingId },
123+
include: { audit: { include: { project: { select: { userId: true } } } } },
124+
});
125+
126+
if (!finding) throw new NotFoundException('Finding not found');
127+
if (finding.audit.project.userId !== userId) {
128+
throw new ForbiddenException('Access denied');
129+
}
130+
131+
const updated = await this.prisma.db.auditFinding.update({
132+
where: { id: findingId },
133+
data: { status },
134+
});
135+
136+
logger.info({ findingId, status, userId }, 'Finding status updated');
137+
138+
return updated;
139+
}
109140
}

0 commit comments

Comments
 (0)