Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Griffinn committed Apr 10, 2020
2 parents 1f660ef + 4477e62 commit bc4e570
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/routes/battles/battles.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
35 changes: 23 additions & 12 deletions src/routes/matchmaking/matchmaking.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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',
});
Expand All @@ -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}`,
});
}

Expand All @@ -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) {
Expand All @@ -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'],
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -177,7 +188,7 @@ async function checkTeams(value) {
} catch (err) {
console.log(err.toString());
}

console.log(`CHECK TEAMS`, existingMatch)
return existingMatch;
}

Expand Down

0 comments on commit bc4e570

Please sign in to comment.