Skip to content

Conversation

@cindyhjli
Copy link

Notion ticket link

Interactions Middleware Ticket

Implementation description

  • added logInteraction function to handle request data and create log message
  • added interactions table and interaction types
  • implemented/updated routes for logging
  • added interactionService for logging interactions

Steps to test

  1. Run migration to get the new interactions tables
  2. Test the routes:
  • Required fields for all routes are 'interactionType', 'actorId', and 'targetId'
  • Other fields specific to the route are required for the log message to display properly, otherwise it will fail or fill in the log message with "undefined" (the log message fields can be found in logInteraction.ts)
  • Check the interactions table for the new logs

What should reviewers focus on?

  • Log messages are correctly inserted into the interactions table

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • I have run the appropriate linter(s)
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

Copy link
Collaborator

@sthuray sthuray left a comment

Choose a reason for hiding this comment

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

Great job with this! A few requests:

  1. Update the table schemas to match the ones in this ticket (this one is more consistent with our other tables, and more thorough in the type declaration): https://github.com/uwblueprint/humane-society/pull/107/files#diff-415d2f577bee729ff37cde4ecd68acc5177abd43148e5f79823839ee741ecdd7

  2. the logInteraction file could use some error handling if it doesn't receive all expected values. Example: if "TASK_ASSIGNEE_CHANGED" is the interaction type, you expect to receive both "oldUserName" and "newUserName", but "newUserName" is null, then throw an error. (instead of using defaults with ?? in some places)

@@ -1,5 +1,3 @@
version: "3.7"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason for this?

break;

case InteractionTypeEnum.CHANGED_PET_NAME:
short_description = `Changed ${oldUserName}'s name to ${newUserName}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be a good idea to add some verification here just so if newUserName is undefined, we won't get
Changed ${oldUserName}'s name to undefined

const targetUserId =
interactionType.includes("USER") && !interactionType.includes("TASK") ? targetId : null;
const targetPetId = interactionType.includes("PET") ? targetId : null;
const targetTaskId = interactionType.includes("TASK_") ? targetId : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't there cases where this give targetTaskId the petId?

@sthuray sthuray marked this pull request as draft December 18, 2025 02:18
Copy link
Contributor

@he-is-harry he-is-harry left a comment

Choose a reason for hiding this comment

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

Leaving some comments from my pass of this PR, looks good overall, just some suggestions to make.

As a more general note, when I was testing the change I noticed that the interaction_types table requires these InteractionTypeEnum values to be inserted before the logging will work. I think it might be beneficial to create a migration that inputs the values in, especially since these enum values are from our development side.


// defineRelationships();

const InteractionType = InteractionTypeModel(sequelize, DataTypes);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can define these interaction and interaction type models in a more similar way to what is done for the other types, it might remove the need for these lines here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe these files here were just added by mistake, I think they can be removed as there are no dependencies on them.

};
};

export enum InteractionTypeEnum {
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a bit of duplication between the different enum types. For example, ASSIGNED_TASK is not used and TASK_ASSIGNED is used instead, but then STARTED_TASK is used below while TASK_STARTED is not used. We should probably remove the duplicates here that are not used and consolidate the logic, I would probably remove the ones above in all caps since they don't match the pattern

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as this the package.json comment above, I believe this one can be removed

@Akishai18
Copy link
Collaborator

@he-is-harry Thanks for your review. Just fix merge conflicts when you get the chance.

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.

6 participants