Skip to content

Commit 3412d87

Browse files
committed
Use legacy scorecard ID as a fallback for legacy data
1 parent 570451d commit 3412d87

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/api/scorecard/scorecard.service.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,45 @@ export class ScoreCardService {
307307
*/
308308
async viewScorecard(id: string): Promise<ScorecardWithGroupResponseDto> {
309309
try {
310-
const data = await this.prisma.scorecard.findUniqueOrThrow({
311-
where: { id },
312-
include: {
313-
scorecardGroups: {
314-
include: {
315-
sections: {
316-
include: {
317-
questions: true,
318-
},
310+
const include = {
311+
scorecardGroups: {
312+
include: {
313+
sections: {
314+
include: {
315+
questions: true,
319316
},
320317
},
321318
},
322319
},
320+
};
321+
322+
const scorecardById = await this.prisma.scorecard.findUnique({
323+
where: { id },
324+
include,
325+
});
326+
327+
if (scorecardById) {
328+
return scorecardById as ScorecardWithGroupResponseDto;
329+
}
330+
331+
const scorecardByLegacyId = await this.prisma.scorecard.findFirst({
332+
where: { legacyId: id },
333+
include,
323334
});
324-
return data as ScorecardWithGroupResponseDto;
335+
336+
if (!scorecardByLegacyId) {
337+
throw new NotFoundException({
338+
message: `Scorecard with ID ${id} not found. Please check the ID and try again.`,
339+
details: { scorecardId: id },
340+
});
341+
}
342+
343+
return scorecardByLegacyId as ScorecardWithGroupResponseDto;
325344
} catch (error) {
345+
if (error instanceof NotFoundException) {
346+
throw error;
347+
}
348+
326349
const errorResponse = this.prismaErrorService.handleError(
327350
error,
328351
`viewing scorecard with ID: ${id}`,

0 commit comments

Comments
 (0)