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

Updates required for the https://github.com/CDLUC3/dmsp_frontend_prototype/issues/188 frontend Edit Question ticket #194

Merged
merged 5 commits into from
Feb 7, 2025

Conversation

jupiter007
Copy link
Collaborator

Description

  • Removed uniq constraints on text and orderNumber for questionOptions table, because it was restricting the ability to update any text on an existing record.
  • Added getQuestionOptionsToRemove to remove questionOptions that are no longer in the updated set
  • Updated questionOptions resolver to use id instead of questionOptionId because otherwise I had to extend existing class

Fixes # (193)

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Manual testing and also checked that it didn't break any existing unit tests

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I updated the CHANGELOG.md and added documentation if necessary
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@@ -8,7 +8,5 @@ CREATE TABLE `questionOptions` (
`createdById` int,
`modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modifiedById` int,
CONSTRAINT unique_question_option_text UNIQUE (`questionId`, `text`),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to remove these constraints because they were preventing me from updating existing question options on the Edit Question page

@@ -3,7 +3,7 @@ import { MyContext } from "../context";
import { QuestionOption } from "../models/QuestionOption";
import { Question } from "../models/Question";
import { Section } from "../models/Section";
import { hasPermissionOnQuestion } from "../services/questionService";
import { getQuestionOptionsToRemove, hasPermissionOnQuestion } from "../services/questionService";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needed to add getQuestionOptionsToRemove function for when a user removes options from an existing questions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a list of new tickets I am going to create and consolidating how associations like this are handled is one of them.

Let's merge this fix for now and we can come back afterward to make sure we're handling them all in the same way.

// Separate incoming options into "to update" and "to create"
const optionsToUpdate = [];
const optionsToCreate = [];

questionOptions.forEach(option => {
if (existingOptionsMap.has(option.questionOptionId)) {
if (existingOptionsMap.has(option.id)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to using id instead of questionOptionId so that I didn't need to extend the existing QuestionOption class

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah that makes sense. You're working within the context of the QuestionOption itself here.

Copy link
Collaborator

@briri briri left a comment

Choose a reason for hiding this comment

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

LGTM. I was to do some consolidation of how we handle these association relationships but we can do that in a separate ticket

@@ -3,7 +3,7 @@ import { MyContext } from "../context";
import { QuestionOption } from "../models/QuestionOption";
import { Question } from "../models/Question";
import { Section } from "../models/Section";
import { hasPermissionOnQuestion } from "../services/questionService";
import { getQuestionOptionsToRemove, hasPermissionOnQuestion } from "../services/questionService";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a list of new tickets I am going to create and consolidating how associations like this are handled is one of them.

Let's merge this fix for now and we can come back afterward to make sure we're handling them all in the same way.

// Separate incoming options into "to update" and "to create"
const optionsToUpdate = [];
const optionsToCreate = [];

questionOptions.forEach(option => {
if (existingOptionsMap.has(option.questionOptionId)) {
if (existingOptionsMap.has(option.id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah that makes sense. You're working within the context of the QuestionOption itself here.

@@ -74,22 +74,5 @@ export const resolvers: Resolvers = {
return await QuestionOption.findByQuestionOptionId('updateQuestion resolver', context, updatedQuestionOption.id);
}
},
removeQuestionOption: async (_, { questionOptionId }, context: MyContext): Promise<QuestionOption> => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was also thinking about situations like this. There are a few cases where we exposed individual removeThing resolvers, but the front end sends the list of its associations when the parent object gets created/updated.

As part of the ticket I mentioned above, we should probably figure out which approaches we are using for each scenario and delete any unused ones

@jupiter007 jupiter007 merged commit 424b4d8 into development Feb 7, 2025
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.

2 participants