Skip to content
Snippets Groups Projects
Commit 94674204 authored by FionaDmello's avatar FionaDmello
Browse files

refactored code to handle snake case codes by transforming them for further...

refactored code to handle snake case codes by transforming them for further calculation into camelCase, removed eslint exceptions
parent df75a7c5
No related branches found
No related tags found
1 merge request!68Details API for details page
Pipeline #510418 passed
...@@ -25,20 +25,5 @@ ...@@ -25,20 +25,5 @@
"default-case-last": "error", "default-case-last": "error",
"max-lines-per-function": ["error", 500], "max-lines-per-function": ["error", 500],
"react/no-is-mounted": "off" //debug the linting issue when this is on "react/no-is-mounted": "off" //debug the linting issue when this is on
}, }
"overrides": [
{
"files": ["src/app/api/**/*.{js,ts}"],
"rules": {
"camelcase": "off"
}
}
// {
// "files": ["src/app/**/*.{js,ts,jsx,tsx}"],
// "excludedFiles": ["src/app/api/**/*.{js,ts}"],
// "rules": {
// "no-console": "error"
// }
// }
]
} }
...@@ -184,27 +184,29 @@ export const handleDetailsParamErrors = (errors: ZodIssue[]) => { ...@@ -184,27 +184,29 @@ export const handleDetailsParamErrors = (errors: ZodIssue[]) => {
const errorMessages = { const errorMessages = {
custom: message === "ID cannot be an empty string" && message, custom: message === "ID cannot be an empty string" && message,
invalid_union: message === "Invalid input" && "Document type submitted is invalid", invalidUnion: message === "Invalid input" && "Document type submitted is invalid",
invalid_type: message === "Required" && "Request missing id parameter", invalidType: message === "Required" && "Request missing id parameter",
}; };
const errorMessage = errorMessages[code as keyof typeof errorMessages]; const camelCaseCode = getCamelCaseCode(code);
if (errorMessage) return errorResponse(errorMessage); const errorMessage = errorMessages[camelCaseCode as keyof typeof errorMessages];
if (errorMessage) {
return errorResponse(errorMessage);
}
} }
// TODO: Is the following check even required? const missingParams = errors.map((e) => e.path[0]).join(" and ");
const isMultiParamError = return errorResponse(`Request missing ${missingParams} parameters`);
errors.length > 1 && };
errors.every(
(error) => const getCamelCaseCode = (code: string) => {
(error.code === "invalid_type" && error.message === "Required") || const codeArray = code.split("_");
(error.code === "invalid_union" && error.message === "Invalid input") if (codeArray.length === 2) {
); const codeKey = codeArray[1]?.charAt(0)?.toUpperCase() + codeArray[1].slice(1);
codeArray.pop();
if (isMultiParamError) { return codeArray.join() + codeKey;
const missingParams = errors.map((e) => e.path[0]).join(" and ");
return errorResponse(`Request missing ${missingParams} parameters`);
} }
return "custom";
}; };
export const getEnrichedRecords = async (rorRecords: ResultItem[]): Promise<ResultItem[]> => { export const getEnrichedRecords = async (rorRecords: ResultItem[]): Promise<ResultItem[]> => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment