mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(api): return default values for user fields (#51843)
This commit is contained in:
committed by
GitHub
parent
70741db619
commit
45bc74acce
@@ -109,11 +109,8 @@ const minimalUserData: Prisma.userCreateInput = {
|
||||
const computedProperties = {
|
||||
calendar: {},
|
||||
completedChallengeCount: 0,
|
||||
completedChallenges: [], // we don't need to provide an empty array, prisma will create it
|
||||
isEmailVerified: minimalUserData.emailVerified,
|
||||
points: 1,
|
||||
portfolio: [],
|
||||
yearsTopContributor: [],
|
||||
// This is the default value if profileUI is missing. If individual properties
|
||||
// are missing from the db, they will be omitted from the response.
|
||||
profileUI: {
|
||||
@@ -541,8 +538,17 @@ describe('userRoutes', () => {
|
||||
const publicUser = {
|
||||
..._.omit(minimalUserData, ['externalId', 'unsubscribeId']),
|
||||
...computedProperties,
|
||||
id: testUser?.id,
|
||||
joinDate: new ObjectId(testUser?.id).getTimestamp().toISOString()
|
||||
id: testUser.id,
|
||||
joinDate: new ObjectId(testUser.id).getTimestamp().toISOString(),
|
||||
// the following properties are defaults provided if the field is
|
||||
// missing in the user document.
|
||||
completedChallenges: [],
|
||||
// TODO: add completedExams when /generate-exam is implemented
|
||||
// completedExams: [],
|
||||
partiallyCompletedChallenges: [],
|
||||
portfolio: [],
|
||||
savedChallenges: [],
|
||||
yearsTopContributor: []
|
||||
};
|
||||
|
||||
const response = await superRequest('/user/get-session-user', {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
|
||||
@@ -325,8 +324,6 @@ export const userGetRoutes: FastifyPluginCallbackTypebox = (
|
||||
progressTimestamps,
|
||||
twitter,
|
||||
profileUI,
|
||||
savedChallenges,
|
||||
partiallyCompletedChallenges,
|
||||
...publicUser
|
||||
} = user;
|
||||
|
||||
@@ -340,19 +337,11 @@ export const userGetRoutes: FastifyPluginCallbackTypebox = (
|
||||
calendar: getCalendar(
|
||||
progressTimestamps as ProgressTimestamp[] | null
|
||||
),
|
||||
partiallyCompletedChallenges: isEmpty(
|
||||
partiallyCompletedChallenges
|
||||
)
|
||||
? undefined
|
||||
: partiallyCompletedChallenges,
|
||||
// This assertion is necessary until the database is normalized.
|
||||
points: getPoints(
|
||||
progressTimestamps as ProgressTimestamp[] | null
|
||||
),
|
||||
profileUI: normalizeProfileUI(profileUI),
|
||||
savedChallenges: isEmpty(savedChallenges)
|
||||
? undefined
|
||||
: savedChallenges,
|
||||
// TODO(Post-MVP) remove this and just use emailVerified
|
||||
isEmailVerified: user.emailVerified,
|
||||
joinDate: new ObjectId(user.id).getTimestamp().toISOString(),
|
||||
|
||||
Reference in New Issue
Block a user