From 3412d878713423ffe53a9b8d9ac1af5678bba554 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Sat, 1 Nov 2025 17:04:10 +1100 Subject: [PATCH] Use legacy scorecard ID as a fallback for legacy data --- src/api/scorecard/scorecard.service.ts | 43 ++++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/api/scorecard/scorecard.service.ts b/src/api/scorecard/scorecard.service.ts index fee2e4b..ee56280 100644 --- a/src/api/scorecard/scorecard.service.ts +++ b/src/api/scorecard/scorecard.service.ts @@ -307,22 +307,45 @@ export class ScoreCardService { */ async viewScorecard(id: string): Promise { try { - const data = await this.prisma.scorecard.findUniqueOrThrow({ - where: { id }, - include: { - scorecardGroups: { - include: { - sections: { - include: { - questions: true, - }, + const include = { + scorecardGroups: { + include: { + sections: { + include: { + questions: true, }, }, }, }, + }; + + const scorecardById = await this.prisma.scorecard.findUnique({ + where: { id }, + include, + }); + + if (scorecardById) { + return scorecardById as ScorecardWithGroupResponseDto; + } + + const scorecardByLegacyId = await this.prisma.scorecard.findFirst({ + where: { legacyId: id }, + include, }); - return data as ScorecardWithGroupResponseDto; + + if (!scorecardByLegacyId) { + throw new NotFoundException({ + message: `Scorecard with ID ${id} not found. Please check the ID and try again.`, + details: { scorecardId: id }, + }); + } + + return scorecardByLegacyId as ScorecardWithGroupResponseDto; } catch (error) { + if (error instanceof NotFoundException) { + throw error; + } + const errorResponse = this.prismaErrorService.handleError( error, `viewing scorecard with ID: ${id}`,