From 46af6be07d01cf8a84b95ce38c1913b913e3322d Mon Sep 17 00:00:00 2001 From: Nic Kendall <54819898+NWKendall@users.noreply.github.com> Date: Thu, 9 Apr 2020 16:14:52 -0300 Subject: [PATCH 1/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a39bbcb8..3cd3a7cf 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Check the wiki for a [setup guide](https://github.com/Lambda-School-Labs/story-s - Integration testing ## Endpoints +[Postman Documentation](https://documenter.getpostman.com/view/9969236/SzS1UpP9?version=latest) #### Authorization Routes From 4477e629d4d43f53f747538586f581e22b3a6f5b Mon Sep 17 00:00:00 2001 From: Nic Kendall <54819898+NWKendall@users.noreply.github.com> Date: Fri, 10 Apr 2020 16:36:27 -0300 Subject: [PATCH 2/2] Understanding matchmaking with hui (#105) * picture check essentially working * refined console log for pictureCheck * something not working * final tweaks --- src/routes/battles/battles.routes.ts | 2 +- src/routes/matchmaking/matchmaking.routes.ts | 35 +++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/routes/battles/battles.routes.ts b/src/routes/battles/battles.routes.ts index 5694dcf0..ca12dfef 100644 --- a/src/routes/battles/battles.routes.ts +++ b/src/routes/battles/battles.routes.ts @@ -42,7 +42,7 @@ battlesRoutes.get('/battles', Only(Child), async (req, res) => { match.team1_child2_id === id ? teammate = match.team1_child1_id : match.team2_child1_id === id ? teammate = match.team2_child2_id : teammate = match.team2_child1_id } - console.log(teammate) + console.log(`student: ${thisMatch.team.student.studentId}, teammate: ${teammate}`) const [ story ] = stories.filter(el => el.week === cohort.week) const [ illustration ] = illustrations.filter(el => el.week === cohort.week) diff --git a/src/routes/matchmaking/matchmaking.routes.ts b/src/routes/matchmaking/matchmaking.routes.ts index 596eaa3e..04014b90 100644 --- a/src/routes/matchmaking/matchmaking.routes.ts +++ b/src/routes/matchmaking/matchmaking.routes.ts @@ -4,21 +4,21 @@ import { runScript } from '../../util/scripts/scripting'; import { attemptJSONParse } from '../../util/utils'; import { Only } from '../../middleware'; -import { Admin, Matches, Stories, Child } from '../../database/entity'; +import { Admin, Matches, Stories, Child, Illustrations } from '../../database/entity'; import { Matchmaking, WeekMatches } from '../../models'; import { connection } from '../../util/typeorm-connection'; const matchMakingRoutes = Router(); matchMakingRoutes.get('/:week', Only(Admin), async (req, res) => { + // add delete functionality to this route so deletes matches before repopulating mathes, prevent spamming const thisWeek = req.params.week; const matches = await getRepository(Matches, connection()).find({ - where: { week: req.params.week }, + where: { week: thisWeek }, }); - console.log(matches); + console.log(`GET FIRST MATCHES`, matches); if (matches.length) { - console.log(matches); - res.status(200).json({ message: `fetch matches success`, match: matches }); + return res.status(200).json({ message: `fetch matches success`, match: matches }); } try { @@ -29,18 +29,26 @@ matchMakingRoutes.get('/:week', Only(Admin), async (req, res) => { }); } catch (err) { console.log(err.toString()); - res.status(500).json({ err: err.toString(), message: 'Could not fetch submissions' }); + return res.status(500).json({ err: err.toString(), message: 'Could not fetch submissions' }); } let submissionObject = {}; - + for (const story of stories) { try { const [childusMinimus] = await getRepository(Child, connection()).find({ where: { id: story.childId }, }); + // Checks for presence of picture + const pictureCheck = await getRepository(Illustrations, connection()).find({ + where: { id: childusMinimus.id, week: req.params.week }, + }); + console.log(`PICTURE CHECK - id: ${story.childId}`, `length: ${pictureCheck.length}`); + // if picture is present, perform DS matchmaking + if (pictureCheck.length){ submissionObject = { + ...submissionObject, [story.childId]: { flesch_reading_ease: story.flesch_reading_ease, @@ -57,9 +65,10 @@ matchMakingRoutes.get('/:week', Only(Admin), async (req, res) => { grade: childusMinimus.grade, }, }; + } } catch (err) { console.log(err.toString()); - res.status(500).json({ + return res.status(500).json({ err: err.toString(), message: 'Could not fetch child within matched submissions', }); @@ -72,8 +81,8 @@ matchMakingRoutes.get('/:week', Only(Admin), async (req, res) => { const competitions = await match(submissionObject); competition = JSON.parse(competitions[0].split(`'`).join(`"`)); } else { - res.json({ - message: `not enough submissions to generate matchmaking within week: ${req.params.week}`, + return res.json({ + message: `not enough submissions to generate matchmaking within week: ${thisWeek}`, }); } @@ -89,7 +98,7 @@ matchMakingRoutes.get('/:week', Only(Admin), async (req, res) => { const matches = await getRepository(Matches, connection()).find({ where: { week: thisWeek }, }); - res.status(200).json({ message: `saved success`, match: matches }); + return res.status(200).json({ message: `saved success`, match: matches }); // await match-ups and responds to FE with match-ups 3.12.20 // first call to assign match-ups works, but this next await doesn't fully resolve for some reason and generates an empty array } catch (err) { @@ -102,6 +111,7 @@ matchMakingRoutes.get('/:week', Only(Admin), async (req, res) => { }); matchMakingRoutes.delete('/:week', Only(Admin), async (req, res) => { + // link this functionality to a button in the admin dashboard, rather than including it in the get reqeust above. try { const matchesToDelete = await getRepository(Matches, connection()).find({ select: ['id'], @@ -132,6 +142,7 @@ function match(data: Matchmaking) { export { matchMakingRoutes }; async function checkTeams(value) { + // checking to see individuals aren't being reused across matchups, can/should be refactored let existingMatch = []; try { existingMatch[0] = await getRepository(Matches, connection()).find({ @@ -177,7 +188,7 @@ async function checkTeams(value) { } catch (err) { console.log(err.toString()); } - + console.log(`CHECK TEAMS`, existingMatch) return existingMatch; }