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

Implement Coffee Chat Dao #598

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

alyssayzhang
Copy link
Contributor

@alyssayzhang alyssayzhang commented Mar 25, 2024

Summary

This PR implements the creates the functions that are used to set up coffee chat DAO.

  • [ X ] get all coffee chat instances
  • [ X ] get coffee chat instances for user
  • [ X ] create new coffee chat instance (1 submission)
  • [ X ] update coffee chat instance
  • [ X ] delete coffee chat instance
  • [ X ] delete all coffee chats

Some things to keep in mind:

  • users cannot coffee chat members from previous semesters (prevent users from creating new instances in this case)

Notion/Figma Link

https://www.notion.so/Dev-Roadmap-741d645c627a466da392fc8038ef0143?p=9719280ab9634834bba9d51a94ddeab8&pm=s

@dti-github-bot
Copy link
Member

dti-github-bot commented Mar 25, 2024

[diff-counting] Significant lines: 115.

@alyssayzhang alyssayzhang changed the title Implement Coffee Chat Dao WIP Implement Coffee Chat Dao Mar 25, 2024
@alyssayzhang alyssayzhang changed the title WIP Implement Coffee Chat Dao Implement Coffee Chat Dao Apr 15, 2024
@alyssayzhang alyssayzhang marked this pull request as ready for review May 1, 2024 19:42
@alyssayzhang alyssayzhang requested a review from a team as a code owner May 1, 2024 19:42
Copy link
Contributor

@patriciaahuang patriciaahuang left a comment

Choose a reason for hiding this comment

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

Good job! The design aligns with the other DAO classes. I left a comment on creating a new coffee chat instance, but otherwise this looks good.


if (prevChats.some((c) => c.members.includes(member1) && c.members.includes(member2))) {
throw new Error(
`Cannot create coffee chat with member. Previous coffee chats from previous semesters exist.`
Copy link
Contributor

Choose a reason for hiding this comment

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

There should probably also be a check to make sure a member cannot coffee chat themselves. There doesn't seem to be anything preventing this right now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch, let's put this and the other validation logic in the API layer, not Dao.

Copy link
Collaborator

@andrew032011 andrew032011 left a comment

Choose a reason for hiding this comment

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

Generally, business logic such as rejecting duplicate chats should be done on the API layer, not Dao. Can you remove this here?

Feel free to read the git history/copy paste somewhere to use for the API implementation.

}

/**
* Deletes all coffee chat for all users
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: *coffee chats

const [member1, member2] = coffeeChat.members;

if (member1.netid === member2.netid) {
throw new Error(`Cannot create coffee chat with yourself.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no need for backticks if the string is not a template string

Copy link
Collaborator

Choose a reason for hiding this comment

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

interesting that eslint doesn't complain about this... 🤔

const prevChats2 = await this.getCoffeeChatsByUser(member2);
const prevChats = [...prevChats1, ...prevChats2];

if (prevChats.some((c) => c.members.includes(member1) && c.members.includes(member2))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be very careful about this check. includes(...) uses object equality and we've had a bug introduced in candidate decider in the past from this. Consider instead checking against netIDs or emails.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, we use lodash's isequal which checks for deep equality for the profile update notification job. That can be used here.

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.

None yet

5 participants