Files
freecodecamp--freecodecamp/api/src/routes/helpers/certificate-utils.ts
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

49 lines
1.6 KiB
TypeScript

import { Prisma } from '@prisma/client';
import {
certSlugTypeMap,
certToIdMap,
Certification
} from '@freecodecamp/shared/config/certification-settings';
import { normalizeDate } from '../../utils/normalize.js';
const fullStackCertificateIds = [
certToIdMap[Certification.RespWebDesign],
certToIdMap[Certification.JsAlgoDataStruct],
certToIdMap[Certification.FrontEndDevLibs],
certToIdMap[Certification.DataVis],
certToIdMap[Certification.BackEndDevApis],
certToIdMap[Certification.LegacyInfoSecQa]
];
/**
* Checks if the given certification slug is known.
*
* @param certSlug - The certification slug to check.
* @returns True if the certification slug is known, otherwise false.
*/
export function isKnownCertSlug(certSlug: string): certSlug is Certification {
return certSlug in certSlugTypeMap;
}
/**
* Retrieves the completion date for the full stack certification, if it exists.
*
* @param completedChallenges - The array of completed challenges.
* @param completedDate - The fallback completed date.
* @returns The latest certification date or the completed date if no certification is found.
*/
export function getFallbackFullStackDate(
completedChallenges: { id: string; completedDate: Prisma.JsonValue }[],
completedDate: Prisma.JsonValue
): number {
const latestCertDate = completedChallenges
.filter(chal => fullStackCertificateIds.includes(chal.id))
.map(chal => ({
...chal,
completedDate: normalizeDate(chal.completedDate)
}))
.sort((a, b) => b.completedDate - a.completedDate)[0]?.completedDate;
return latestCertDate ?? normalizeDate(completedDate);
}