generated from freeCodeCamp/template
-
-
Notifications
You must be signed in to change notification settings - Fork 133
[WIP] feat(api): Integration of FCC Proper endpoints and Dynamic Student Data #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NewtonLC
wants to merge
2
commits into
freeCodeCamp:main
Choose a base branch
from
NewtonLC:feat/fcc-proper-apis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| export default async function handler(req, res) { | ||
| if (req.method !== 'POST') { | ||
| return res.status(405).json({ error: 'Method not allowed' }); | ||
| } | ||
|
|
||
| try { | ||
| // Parse cookies from request header | ||
| const cookies = {}; | ||
| if (req.headers.cookie) { | ||
| req.headers.cookie.split(';').forEach(cookie => { | ||
| const [name, value] = cookie.trim().split('='); | ||
| cookies[name] = decodeURIComponent(value); | ||
| }); | ||
| } | ||
|
|
||
| // Get token from cookie if it exists | ||
| const cookieToken = cookies.jwt_access_token; | ||
| const { targetUrl, ...bodyData } = req.body; | ||
|
|
||
| if (!cookieToken) { | ||
| console.log('Unauthorized!'); | ||
| return res.status(401).json({ error: 'Unauthorized' }); | ||
| } | ||
|
|
||
| if (!targetUrl) { | ||
| console.log('Missing targetUrl'); | ||
| return res.status(400).json({ error: 'Missing targetUrl' }); | ||
| } | ||
|
|
||
| console.log('proxy hit', { | ||
| targetUrl, | ||
| bodyDataKeys: Object.keys(bodyData) | ||
| }); | ||
|
|
||
| // Build the full FCC URL | ||
| const fccUrl = `http://localhost:3000${targetUrl}`; | ||
|
|
||
| const headers = { | ||
| 'Content-Type': 'application/json', | ||
| Cookie: `jwt_access_token=${cookieToken}` | ||
| }; | ||
|
|
||
| // Make POST request with body data | ||
| const fccResponse = await fetch(fccUrl, { | ||
| method: 'POST', | ||
| headers, | ||
| body: JSON.stringify(bodyData), | ||
| credentials: 'include' | ||
| }); | ||
|
|
||
| // Get the response data | ||
| const data = await fccResponse.json(); | ||
|
|
||
| // Return the data to the client | ||
| return res.status(fccResponse.status).json(data); | ||
| } catch (error) { | ||
| console.error('Error proxying request to FCC:', error); | ||
| return res.status(500).json({ error: 'Failed to fetch from FCC' }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import challengeMap from '../data/challengeMap.json'; | ||
|
|
||
| /** | ||
| * Resolves a full FCC Proper student data object (from the proxy) to the dashboard format. | ||
| * @param {Object} studentDataFromFCC - { email1: [completedChallenges], email2: [completedChallenges], ... } | ||
| * @returns {Array} - Array of student objects: { email, certifications: [...] } | ||
| */ | ||
| export function resolveAllStudentsToDashboardFormat(studentDataFromFCC) { | ||
| if (!studentDataFromFCC || typeof studentDataFromFCC !== 'object') return []; | ||
| return Object.entries(studentDataFromFCC).map( | ||
| ([email, completedChallenges]) => ({ | ||
| email, | ||
| ...buildStudentDashboardData(completedChallenges, challengeMap) | ||
| }) | ||
| ); | ||
| } | ||
| /** | ||
| * Transforms a student's flat completed challenge array into the nested dashboard format. | ||
| * @param {Array} completedChallenges - Array of completed challenge objects (with id, completedDate, etc.) | ||
| * @param {Object} challengeMap - The challenge map object from /api/build-challenge-map | ||
| * @returns {Object} - Nested structure: { certifications: [ { [certName]: { blocks: [ { [blockName]: { completedChallenges: [...] } } ] } } ] } | ||
| */ | ||
| export function buildStudentDashboardData(completedChallenges, challengeMap) { | ||
| const result = { certifications: [] }; | ||
| const certMap = {}; | ||
|
|
||
| completedChallenges.forEach(challenge => { | ||
| const mapEntry = challengeMap[challenge.id]; | ||
| if (!mapEntry) { | ||
| // DEBUG: Print missing challenge IDs, confirm with curriculum team if these challenge IDs are no longer valid. | ||
| // console.warn('Challenge ID not found in challengeMap:', challenge.id); | ||
| return; // skip unknown ids | ||
| } | ||
| const { certification, block, name } = mapEntry; | ||
| if (!certMap[certification]) { | ||
| certMap[certification] = { blocks: {} }; | ||
| } | ||
| if (!certMap[certification].blocks[block]) { | ||
| certMap[certification].blocks[block] = { completedChallenges: [] }; | ||
| } | ||
| certMap[certification].blocks[block].completedChallenges.push({ | ||
| ...challenge, | ||
| challengeName: name | ||
| }); | ||
| }); | ||
|
|
||
| // Convert to the expected nested array format | ||
| for (const cert in certMap) { | ||
| const certObj = {}; | ||
| certObj[cert] = { | ||
| blocks: Object.entries(certMap[cert].blocks).map( | ||
| ([blockName, blockObj]) => ({ | ||
| [blockName]: blockObj | ||
| }) | ||
| ) | ||
| }; | ||
| result.certifications.push(certObj); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have confirmed that we are to ignore missing challenge map IDs as they are in reference to old steps that are no longer included or tracked (therefore legacy) and we do not list legacy data. The only reason for keeping the notation is in case they might wanted the debug option here. Otherwise this notation can be removed.