Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable member types #50

Merged
merged 17 commits into from
Aug 31, 2018
Merged

Configurable member types #50

merged 17 commits into from
Aug 31, 2018

Conversation

eemeli
Copy link
Member

@eemeli eemeli commented Aug 6, 2018

Replaces the MembershipStatus enum with a table membership_types in Postgres, and uses its data rather than hard-coded values for related processing.

TODO: Improve documentation, adding database update instructions

Copy link

@heymatthew heymatthew left a comment

Choose a reason for hiding this comment

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

Looks like a great change, I think this is going to make things far more configurable.

Just a few suggestions...

  • There's a stray FIXME without context. Could we fix it or leave a hint about what needs fixing?
  • A few of these functions are getting large. I'd love to see them broken up into named bits to make it clearer what they're doing.
  • There's complex logic generating SQL that is an excellent candidate for it's own function.
  • Spotted a few places with magic numbers. Comments or named constants would make it easier to follow.
  • Some small tests would be wonderful :)

Hope this helps, push back if any of it doesn't sit the style of the project.

.map(({ id, name }) => ({ id, name }))
return {
attending,
email: res[0].email,
hugo_members,
key: res[0].key,
membership: mt[mi],
membership: res[0].membership, // FIXME

Choose a reason for hiding this comment

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

What needs fixing here? Could you describe it in this comment, or just fix it ;-).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, sorry, this is #49.

Choose a reason for hiding this comment

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

Fair enough. How about just putting that in the comment?

// FIXME will come back to this for issue #49

data.email ? tx.oneOrNone(`SELECT key FROM Keys WHERE email=$(email)`, data) : {},
tx.none(`INSERT INTO Log ${log.sqlValues}`, log)
]))
.then(([{ hugo_nominator, hugo_voter, next_email, prev_email, name }, key]) => {
.then(([{ hugo_nominator, wsfs_member, next_email, prev_email, name }, key]) => {

Choose a reason for hiding this comment

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

This method is getting really large. Would you consider extracting some of this into callable functions?

FROM people p
LEFT JOIN membership_types m USING (membership)
WHERE ${queryParts.join(' AND ')} AND
m.allow_lookup = true`, queryValues

Choose a reason for hiding this comment

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

The queryParts construction logic is looking quite complex. Could we extract this to a function?

This would make it easy to write a little test ;-).

const mp = prices[p.data.membership]
if (typeof mp !== 'number' || mp < 0) {
throw new InputError(`Membership type not available for purchase: ${JSON.stringify(p.data.membership)}`)
}

Choose a reason for hiding this comment

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

This method is getting really large. Would you consider breaking up into more functions?

FROM people p
LEFT JOIN siteselection_votes s ON (p.id = s.person_id)
LEFT JOIN membership_types m USING (membership)
WHERE p.id = $1 AND m.wsfs_member = true`, id)

Choose a reason for hiding this comment

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

Magic numbers in switch case. Is there any way we could name these numbers?
Either that or a nice little comment about what they represent?

Vote seems like an important function. Could we get a little test going for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tbh I can't remember why I ended up doing transactions this way; probably misunderstood that a construction like db.tx(t => t.one(...).then(res => t.one(...))) wouldn't work for some reason. Should refactor all of these.

email = prev.email;
member_number = prev.member_number;
const log = new LogEntry(req, `Upgrade to ${data.membership}`);
if (data.paper_pubs) log.description += ' and add paper pubs';
log.subject = data.id;
return tx.none(`INSERT INTO Log ${log.sqlValues}`, log);

case 3:
case 4:

Choose a reason for hiding this comment

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

More magic numbers, could we name these or leave a comment about them?
What happens when i doensn't fit between 0 and 4?

@heymatthew
Copy link

Do we need to make changes to the importer too?

@eemeli
Copy link
Member Author

eemeli commented Aug 8, 2018

Yeah, the importer will need to be updated as well. Should also add tests for member data updates, voting, and a bunch of other things.

Copy link

@heymatthew heymatthew left a comment

Choose a reason for hiding this comment

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

Looks better man 👍 :shipit:

I'll raise an issue about updating the importer separately.

@eemeli eemeli merged commit f25e487 into master Aug 31, 2018
@eemeli eemeli deleted the member-types branch August 31, 2018 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants