Skip to content

Commit

Permalink
mentor id fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Shiel committed Nov 11, 2024
1 parent 9c60ac1 commit 5904bc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions node/src/gql/mutation/me/subject-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import {
QuestionUpdateInput,
QuestionUpdateInputType,
} from './question-update';
import { UseDefaultTopics, idOrNew, toUpdateProps } from './helpers';
import {
UseDefaultTopics,
idOrNew,
toUpdateProps,
validateAndConvertToObjectId,
} from './helpers';
import { canEditContent } from '../../../utils/check-permissions';

export interface CategoryUpdateInput {
Expand Down Expand Up @@ -115,7 +120,9 @@ export async function questionInputToUpdate(
): Promise<SubjectQuestionProps> {
const { _id, props } = toUpdateProps<Question>({
...input.question,
mentor: idOrNew(input.question.mentor),
mentor: input.question.mentor
? validateAndConvertToObjectId(input.question.mentor)
: undefined,
_id: idOrNew(input.question._id),
});
const q = await QuestionModel.findOneAndUpdate(
Expand Down
10 changes: 8 additions & 2 deletions node/src/models/Question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Permission to use, copy, modify, and distribute this software and its documentat
The full terms of this copyright and license should always be found in the root directory of this software deliverable as "license.txt" and if these terms are not found with this software, please contact the USC Stevens Center for the full license.
*/
import { idOrNew, toUpdateProps } from '../gql/mutation/me/helpers';
import {
idOrNew,
toUpdateProps,
validateAndConvertToObjectId,
} from '../gql/mutation/me/helpers';
import { QuestionUpdateInput } from '../gql/mutation/me/question-update';
import mongoose, { Document, Model, Schema, Types } from 'mongoose';
import { Mentor, MentorType } from './Mentor';
Expand Down Expand Up @@ -72,7 +76,9 @@ QuestionSchema.statics.updateOrCreate = async function (
) {
const { _id, props } = toUpdateProps<Question>({
...question,
mentor: idOrNew(question.mentor),
mentor: question.mentor
? validateAndConvertToObjectId(question.mentor)
: undefined,
_id: idOrNew(question._id),
});
return await this.findOneAndUpdate(
Expand Down

0 comments on commit 5904bc7

Please sign in to comment.