refactor: use cert as key (#64293)

This commit is contained in:
Oliver Eyton-Williams
2025-12-04 10:21:03 +01:00
committed by GitHub
parent 73ad631dfd
commit 9d8cbcff5a
6 changed files with 64 additions and 45 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ import { getChallenges } from '../../utils/get-challenges.js';
import {
certIds,
certSlugTypeMap,
certTypeTitleMap,
certToTitleMap,
certTypes,
currentCertifications,
legacyCertifications,
@@ -298,7 +298,7 @@ export const protectedCertificateRoutes: FastifyPluginCallbackTypebox = (
}
const certType = certSlugTypeMap[certSlug];
const certName = certTypeTitleMap[certType];
const certName = certToTitleMap[certSlug];
const user = await fastify.prisma.user.findUnique({
where: { id: req.user?.id }
+4 -5
View File
@@ -4,7 +4,7 @@ import { find } from 'lodash-es';
import * as schemas from '../../schemas.js';
import {
certSlugTypeMap,
certTypeTitleMap,
certToTitleMap,
certTypeIdMap,
completionHours,
oldDataVizId
@@ -53,7 +53,7 @@ export const unprotectedCertificateRoutes: FastifyPluginCallbackTypebox = (
const certType = certSlugTypeMap[certSlug];
const certId = certTypeIdMap[certType];
const certTitle = certTypeTitleMap[certType];
const certTitle = certToTitleMap[certSlug];
const completionTime = completionHours[certType] || 300;
const user = await fastify.prisma.user.findFirst({
where: { username },
@@ -180,16 +180,15 @@ export const unprotectedCertificateRoutes: FastifyPluginCallbackTypebox = (
}
if (!user[certType]) {
const cert = certTypeTitleMap[certType];
logger.info(
`User ${username} has not completed the ${cert} certification.`
`User ${username} has not completed the ${certTitle} certification.`
);
return reply.send({
messages: [
{
type: 'info',
message: 'flash.user-not-certified',
variables: { username, cert }
variables: { username, cert: certTitle }
}
]
});