Skip to content

Commit

Permalink
fix: duplicate team submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ddenizakpinar committed Jun 29, 2023
1 parent 128fe40 commit 9d08bca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 70 deletions.
13 changes: 4 additions & 9 deletions client/src/modules/Lobby/components/Confetti/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import { CONFETTI_PARTICLE_COUNT } from 'src/constants';
type ConfettiProps = {};

const Confetti: FC<ConfettiProps> = () => {
const refAnimationInstance: any = useRef(null);

const getInstance = useCallback((instance: any) => {
refAnimationInstance.current = instance;
}, []);
const refAnimationInstance = useRef<confetti.CreateTypes | null>(null);

const makeShot = useCallback((position: number, particleRatio: number, opts: any) => {
if (!refAnimationInstance.current) return;

setTimeout(() => {
if (!refAnimationInstance.current) return;
refAnimationInstance.current({
...opts,
origin: { y: position },
Expand Down Expand Up @@ -118,8 +113,8 @@ const Confetti: FC<ConfettiProps> = () => {

return (
<ReactCanvasConfetti
refConfetti={getInstance}
className="z-50 pointer-events-none fixed left-0 top-0 h-full w-full"
refConfetti={(ref) => (refAnimationInstance.current = ref)}
className="pointer-events-none fixed left-0 top-0 z-50 h-full w-full"
/>
);
};
Expand Down
3 changes: 1 addition & 2 deletions client/src/modules/Lobby/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { disconnectSocket, joinLobby, sendMessage } from '@services/lobby';
import { useRouter } from 'next/router';
import { FC, useEffect, useMemo, useState } from 'react';
import Chat from '../../components/shared/Chat';
import Dino from './components/Dino';
import Participants from './components/Participants';
import { Status } from '@models/enums';
import { DateTime } from 'luxon';
Expand Down Expand Up @@ -84,7 +83,7 @@ const Lobby: FC<LobbyProps> = ({ discussion }) => {
{!discussion && (
<>
<Connection />
{mounted() && <Dino />}
{/* {mounted() && <Dino />} */}
</>
)}
{discussion && (
Expand Down
26 changes: 25 additions & 1 deletion server/src/modules/challenge/challenge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,31 @@ export class ChallengeService {
}

async getPlacements(challengeId: string) {
return await this.dataService.queries.findChallengePlacements(challengeId);
const teamFinishRankings = await this.dataService.queries.findChallengeTeamFinishRankings(
challengeId,
);
const placements = [];
for (const teamFinishRanking of teamFinishRankings) {
const placement = {
participants: [],
submission: null,
...teamFinishRanking,
};
const team = await this.dataService.teams.findById(teamFinishRanking.teamId, {
populate: '*',
});
const submission = await this.dataService.submissions.findOne(
{ challengeId, teamId: teamFinishRanking.teamId },
{ sort: { date: 'asc' } },
);

placement.participants = team.participants;
placement.submission = submission;

placements.push(placement);
}

return placements;
}

async participate(userId: string, challengeId: string) {
Expand Down
28 changes: 0 additions & 28 deletions server/src/modules/providers/ottoman/ottoman.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ export class OttomanQueries {
return result.rows[0];
}

async findWinners(challengeId: string) {
const result = await this._query(queries.findWinners, {
parameters: { CHALLENGE_ID: challengeId },
});

return result.rows;
}

async findChallengeTeamFinishRankings(challengeId: string) {
const result = await this._query(queries.findChallengeTeamFinishRankings, {
parameters: { CHALLENGE_ID: challengeId },
Expand All @@ -58,26 +50,6 @@ export class OttomanQueries {
});
}

async findChallengePlacements(challengeId: string) {
const result = await this._query(queries.findChallengePlacements, {
parameters: { CHALLENGE_ID: challengeId },
});

const placements = [];

result.rows.forEach(({ date, teamId, submission, participants }) => {
const mappedParticipants = participants.map((participant) => participant[bucketName]);
placements.push({
date,
teamId,
submission,
participants: mappedParticipants,
});
});

return placements;
}

async appendChallengeToUser(userId: string, challenge: UserChallenge) {
await this._query(queries.appendChallengeToUser, {
parameters: { USER_ID: userId, CHALLENGE: challenge },
Expand Down
30 changes: 0 additions & 30 deletions server/src/modules/providers/ottoman/schemas/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ GROUP BY q1.id,
difficulty,
problem`;

const findWinners = `
SELECT MAX([runtime, teamId])[0] as runtime, MAX([runtime, teamId])[1] as teamId FROM ${bucketName}
where type = 'submission' and challengeId = $CHALLENGE_ID
group by teamId order by runtime desc limit 3`;

const findChallengeTeamFinishRankings = `
SELECT MIN([date, teamId])[0] as date, MIN([date, teamId])[1] as teamId FROM ${bucketName}
where type = 'submission' and status = 3 and challengeId = $CHALLENGE_ID
Expand All @@ -107,29 +102,6 @@ SET points = points + $POINTS
WHERE type = 'user' and id = $USER_ID
`;

const findChallengePlacements = `
SELECT MIN([date, teamId])[0] AS date,
MIN([date, teamId])[1] AS teamId,
participants,
submission
FROM ${bucketName} submission
LET team = (
SELECT participants
FROM ${bucketName} q2
WHERE type = 'team'
AND id = submission.teamId),
participants = (
SELECT *
FROM ${bucketName} where type = 'user' and id in team[0].participants)
WHERE type = 'submission'
AND status = 3
AND challengeId = $CHALLENGE_ID
GROUP BY teamId,
participants,
submission
ORDER BY date ASC
`;

const appendChallengeToUser = `
Update ${bucketName} set challenges = ARRAY_APPEND(challenges, $CHALLENGE)
where type = 'user' and id = $USER_ID
Expand Down Expand Up @@ -257,10 +229,8 @@ const findDraftArticles = `
export const queries = {
findChallenges,
findChallenge,
findWinners,
findChallengeTeamFinishRankings,
addPointsToUser,
findChallengePlacements,
appendChallengeToUser,
appendProblemToUser,
findProblems,
Expand Down

0 comments on commit 9d08bca

Please sign in to comment.