Skip to content

Wrote method checkTieredBadge in badgeHelpers.ts#44

Open
sinharia wants to merge 3 commits intomasterfrom
ria6/tiered-badge-helper
Open

Wrote method checkTieredBadge in badgeHelpers.ts#44
sinharia wants to merge 3 commits intomasterfrom
ria6/tiered-badge-helper

Conversation

@sinharia
Copy link
Copy Markdown

No description provided.

@helenailic helenailic changed the base branch from badges to master April 15, 2026 20:30
@helenailic helenailic self-requested a review April 15, 2026 20:30
Comment thread src/utils/badgeHelpers.ts Outdated
//getting badges from the /badges endpoint
let badges = null;
try {
const response = await fetch('/badges');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this in the backend, shouldn't be fetching an endpoint but rather querying the database yourself (mongo db syntax)

Comment thread src/utils/badgeHelpers.ts Outdated
return null;
}
const tierList = [tier3, tier2, tier1];
for (const tier in tierList) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this "for ... in" syntax is correct IF you're coding in python -- look into the javascript/typescript docs to see what unintended behavior this for loop actually does.. and what syntax you should be using instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to for-of syntax

Comment thread src/utils/badgeHelpers.ts Outdated
export async function checkTieredBadge( //what will method signature be? what's it returning
user: User, counterField: string, tier1: number, tier2: number, tier3: number
) {
//operating on the assumption that the badges database has not been created yet.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up comments that aren't relevant to explaining the code!

Comment thread src/utils/badgeHelpers.ts Outdated
if (!badge) {
continue;
}
const userCounterField = user[counterField]; //no counterField yet?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here on the comment point!

Comment thread src/utils/badgeHelpers.ts Outdated
}
const tierList = [tier3, tier2, tier1];
for (const tier in tierList) {
const badge = badges.find(b => b.category === counterField && b.tier === tier);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to find the specific badge name you need, you can't actually do b.tier == tier, as the tier1, tier2, tier3 (i concede, misleading names, are the count thresholds: so like ok you need to attend 3 events, 5 events, 8 events, while the badge tier field is the tier number (1st, 2nd, or 3rd). as such, you may need to do a if sequence to address each tier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants