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

added a reaction selector for comments #1340

Merged
merged 21 commits into from
Jul 23, 2024
Merged

added a reaction selector for comments #1340

merged 21 commits into from
Jul 23, 2024

Conversation

ARADDCC002
Copy link
Member

@ARADDCC002 ARADDCC002 commented Jun 20, 2024

image

image

image

@ARADDCC012
Copy link
Member

Updated look:
image

Copy link
Member

Choose a reason for hiding this comment

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

Could we get some quick unit tests for these.

backend/src/models/Response.ts Show resolved Hide resolved

const response = await updateResponseReaction(req.user, responseId, kind as ReactionKindKeys)

await audit.onUpdateResponse(req, responseId)
Copy link
Member

Choose a reason for hiding this comment

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

Could we add the kind to the audit?

Copy link
Member

Choose a reason for hiding this comment

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

We don't actually need to audit reactions at all, so I'm going to remove

Comment on lines 82 to 84
if (response.reactions === undefined) {
response.reactions = []
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it better to update it like this or define a migration?

Copy link
Member

Choose a reason for hiding this comment

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

We should do a migration for sure

response.reactions.push(newReaction)
} else {
updatedReaction.users.includes(user.dn)
? (updatedReaction.users = updatedReaction.users.filter((reactionUser) => reactionUser !== user.dn))
Copy link
Member

Choose a reason for hiding this comment

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

Could these brackets be removed?

Copy link
Member

Choose a reason for hiding this comment

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

They are needed in this case, however I'm not a fan of using a ternary like this. Imo they should only be used when conditionally returning a value. I've updated to:

  if (!updatedReaction) {
    const newReaction: ResponseReaction = {
      kind,
      users: [user.dn],
    }
    response.reactions.push(newReaction)
  } else if (updatedReaction.users.includes(user.dn)) {
    updatedReaction.users = updatedReaction.users.filter((reactionUser) => reactionUser !== user.dn)
  } else {
    updatedReaction.users.push(user.dn)
  }

Comment on lines 24 to 27
if (res.ok) {
mutateResponses()
setAnchorEl(null)
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you need a if (!res.ok) condition to catch errors with this backend call? It appears to just not update giving no feadback if it errors.

Comment on lines 35 to 40
if (response.entity !== toEntity('user', user.dn)) {
throw Forbidden('Only the original author can update a comment or review response.', {
userDn: user.dn,
responseId,
})
}
Copy link
Member

Choose a reason for hiding this comment

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

This suggests that you can only get individual responses on responses that you've written. Is this expected?

Copy link
Member

@ARADDCC012 ARADDCC012 Jul 8, 2024

Choose a reason for hiding this comment

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

Yeah it doesn't really make any sense, this function has been removed

Comment on lines 28 to 43
export async function getResponseById(user: UserInterface, responseId: string) {
const response = await ResponseModel.findOne({ _id: responseId })

if (!response) {
throw NotFound(`The requested response was not found.`, { responseId })
}

if (response.entity !== toEntity('user', user.dn)) {
throw Forbidden('Only the original author can update a comment or review response.', {
userDn: user.dn,
responseId,
})
}

return response
}
Copy link
Member

Choose a reason for hiding this comment

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

I can't see anywhere this function is called. Is it necessary?


registerPath({
method: 'patch',
path: '/api/v2/response/{responseId}',
Copy link
Member

Choose a reason for hiding this comment

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

Update

export const patchResponseReactionSchema = z.object({
params: z.object({
responseId: z.string(),
kind: z.string(z.nativeEnum(ResponseKind)),
Copy link
Member

Choose a reason for hiding this comment

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

This should be kind: z.nativeEnum(ReactionKind)

method: 'patch',
path: '/api/v2/response/{responseId}',
tags: ['response'],
description: `Update either a comment or a review response's reactions`,
Copy link
Member

Choose a reason for hiding this comment

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

Update

params: { responseId, kind },
} = parse(req, patchResponseReactionSchema)

const response = await updateResponseReaction(req.user, responseId, kind as ReactionKindKeys)
Copy link
Member

Choose a reason for hiding this comment

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

If the zod schema is corrected, this type assertion won't be needed

updatedReaction.users.push(user.dn)
}

response.save()
Copy link
Member

Choose a reason for hiding this comment

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

await?

@ARADDCC012 ARADDCC012 merged commit fc012d1 into main Jul 23, 2024
14 checks passed
@ARADDCC012 ARADDCC012 deleted the dev/comment-reactions branch July 23, 2024 10:20
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.

4 participants