feat(api): submit survey endpoint (#53934)

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Niraj Nandish
2024-03-11 10:56:34 +01:00
committed by GitHub
co-authored by Tom
parent 0225713b2a
commit 0577deb64f
5 changed files with 251 additions and 16 deletions
+29 -1
View File
@@ -1,6 +1,11 @@
/* This module's job is to parse the database output and prepare it for
serialization */
import { ProfileUI, CompletedChallenge, ExamResults } from '@prisma/client';
import {
ProfileUI,
CompletedChallenge,
ExamResults,
type Survey
} from '@prisma/client';
import _ from 'lodash';
type NullToUndefined<T> = T extends null ? undefined : T;
@@ -106,3 +111,26 @@ export const normalizeChallenges = (
return noNullPath;
};
type NormalizedSurvey = {
title: string;
responses: {
question: string;
response: string;
}[];
};
/**
* Remove the extra properties from the SurveyResults array.
*
* @param surveyResults The SurveyResults array.
* @returns The input without the id and userid.
*/
export const normalizeSurveys = (
surveyResults: Survey[]
): NormalizedSurvey[] => {
return surveyResults.map(survey => {
const { title, responses } = survey;
return { title, responses };
});
};