Skip to content

Commit

Permalink
feat: allow list of required talks for prize submission
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavilien committed Feb 8, 2025
1 parent 74d697a commit 1b5ddc5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/_types/Prize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IPrize extends Document {
name: string;
description: string;
eligibility?: string;
requiredTalk?: ObjectId;
requiredTalk?: ObjectId[];
provider: ObjectId;
winner?: ObjectId;
createdAt: Date;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/PrizeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const createNewPrize = async (

const talk = await CheckinItem.findOne({ name: requiredTalk });
if (talk != null) {
prize.requiredTalk = talk._id;
prize.requiredTalk = [talk._id];
}

await prize.save();
Expand Down
11 changes: 8 additions & 3 deletions src/controllers/ProjectsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,11 @@ export const enterProject = async (
const members = team.members;
let eligible = false;

const requiredTalk = await CheckinItem.findById(prize.requiredTalk);
const requiredTalks = await CheckinItem.find({
_id: { $in: prize.requiredTalk },
});

if (!requiredTalk) {
if (requiredTalks.length === 0) {
eligible = true;
} else {
await Promise.all(
Expand All @@ -343,9 +345,12 @@ export const enterProject = async (
item: checkInItems[i]._id,
});
const hasCheckedIn = histories.length !== 0;
const requiredTalksString = prize.requiredTalk?.map((t) =>
t.toString()
);
if (
hasCheckedIn &&
checkInItems[i]._id.toString() === prize.requiredTalk.toString()
requiredTalksString?.includes(checkInItems[i]._id.toString())
) {
eligible = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Prize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Prize: Schema<IPrize> = new Schema(
required: false,
},
requiredTalk: {
type: Schema.Types.ObjectId,
type: [Schema.Types.ObjectId],
ref: "CheckinItem",
required: false,
},
Expand Down

0 comments on commit 1b5ddc5

Please sign in to comment.