feat(api): get certslug route (#50515)

Co-authored-by: Sboonny <muhammed@freecodecamp.org>
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Muhammed Mustafa
2024-04-11 08:57:46 +02:00
committed by GitHub
parent 208fdbd735
commit 086ff36333
7 changed files with 626 additions and 5 deletions

View File

@@ -59,6 +59,7 @@ type CompletedChallengeFile = {
path?: string | null;
};
// TODO: Should probably prefer `import{CompletedChallenge}from'@prisma/client'` instead of defining it here
export type CompletedChallenge = {
id: string;
solution?: string | null;

View File

@@ -1,4 +1,7 @@
import { ErrorObject } from 'ajv';
import { certTypes } from '../../../shared/config/certification-settings';
type CertLogs = (typeof certTypes)[keyof typeof certTypes];
type FormattedError = {
type: 'error';
@@ -47,6 +50,30 @@ export const formatProjectCompletedValidation = (
};
};
/**
* Format validation errors for /project-completed.
*
* @param errors An array of validation errors.
* @returns Formatted errors that can be used in the response.
*/
export const formatCertificationValidation = (
errors: ErrorObject[]
): FormattedError => {
const error = getError(errors);
return error.instancePath === '' &&
Object.values(certTypes).includes(error.params.missingProperty as CertLogs)
? ({
type: 'error',
message:
'You have not provided the valid param for us to display the certification.'
} as const)
: ({
type: 'error',
message: 'That does not appear to be a valid certification request.'
} as const);
};
/**
* Format validation errors for /coderoad-challenge-completed.
*