Skip to content

Commit

Permalink
fix: add get season question endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BoonHianLim committed Feb 24, 2024
1 parent c74203b commit a426e95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/challenges/src/controllers/season.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const getSeasons = asyncHandler(async (req: Request, res: Response) => {

try {
const seasons = await SeasonService.getSeasonsByDate(_startDate, _endDate);

res.status(200).json({
seasons: seasons,
});
Expand Down Expand Up @@ -165,9 +166,15 @@ const getSeasonRankings = asyncHandler(async (req: Request, res: Response) => {
const getSeasonQuestions = asyncHandler(async (req: Request, res: Response) => {
try {
const seasonID = zodIsValidObjectId.parse(req.params.seasonID);

const season = await SeasonService.getSeasonByID(seasonID);
if (!season) {
res.status(404).json({ message: 'Season not found' });
return;
}

const questions = await SeasonService.getSeasonQuestions(seasonID);

res.status(200).json(questions);
} catch (err) {
if (err instanceof z.ZodError) {
Expand Down
9 changes: 9 additions & 0 deletions apps/challenges/src/model/season.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import mongoose, { Schema } from 'mongoose';
import { QuestionModel } from './question';

export interface GetSeasonResp {
id: mongoose.Types.ObjectId;
title: string;
startDate: Date;
endDate: Date;
questions: QuestionModel[];
}

export interface SeasonModel {
_id: mongoose.Types.ObjectId;
Expand Down

0 comments on commit a426e95

Please sign in to comment.