Wrote method checkTieredBadge in badgeHelpers.ts#44
Conversation
| //getting badges from the /badges endpoint | ||
| let badges = null; | ||
| try { | ||
| const response = await fetch('/badges'); |
There was a problem hiding this comment.
since this in the backend, shouldn't be fetching an endpoint but rather querying the database yourself (mongo db syntax)
| return null; | ||
| } | ||
| const tierList = [tier3, tier2, tier1]; | ||
| for (const tier in tierList) { |
There was a problem hiding this comment.
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
| 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. |
There was a problem hiding this comment.
clean up comments that aren't relevant to explaining the code!
| if (!badge) { | ||
| continue; | ||
| } | ||
| const userCounterField = user[counterField]; //no counterField yet? |
There was a problem hiding this comment.
same here on the comment point!
| } | ||
| const tierList = [tier3, tier2, tier1]; | ||
| for (const tier in tierList) { | ||
| const badge = badges.find(b => b.category === counterField && b.tier === tier); |
There was a problem hiding this comment.
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
No description provided.