Skip to content

Commit

Permalink
useDefaultTopics
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Feb 6, 2024
1 parent b87d6f3 commit 9bf060d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions node/src/gql/mutation/me/subject-add-or-update-questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
GraphQLID,
GraphQLList,
GraphQLString,
GraphQLBoolean,
} from 'graphql';
import { User } from '../../../models/User';

Expand All @@ -23,6 +24,7 @@ interface SubjectAddOrUpdateQuestionGQLType {
question: number;
category: string;
topics: string[];
useDefaultTopics?: boolean;
}

export const SubjectAddOrUpdateQuestionGQLType = new GraphQLObjectType({
Expand All @@ -31,6 +33,7 @@ export const SubjectAddOrUpdateQuestionGQLType = new GraphQLObjectType({
category: { type: GraphQLString },
topics: { type: GraphQLList(GraphQLID) },
question: { type: GraphQLID },
useDefaultTopics: { type: GraphQLBoolean },
},
});

Expand Down
3 changes: 3 additions & 0 deletions node/src/gql/mutation/me/subject-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface SubjectQuestionUpdateInput {
question: QuestionUpdateInput;
category?: CategoryUpdateInput;
topics?: TopicUpdateInput[];
useDefaultTopics?: boolean;
}

export const SubjectQuestionInputType = new GraphQLInputObjectType({
Expand All @@ -75,6 +76,7 @@ export const SubjectQuestionInputType = new GraphQLInputObjectType({
question: { type: QuestionUpdateInputType },
category: { type: CategoryInputType },
topics: { type: GraphQLList(TopicInputType) },
useDefaultTopics: { type: GraphQLBoolean },
}),
});

Expand Down Expand Up @@ -123,6 +125,7 @@ export async function questionInputToUpdate(
return {
question: q._id,
category: input.category?.id,
useDefaultTopics: input.useDefaultTopics || false,
// don't include topics that are not in the subject
topics:
input.topics
Expand Down
1 change: 1 addition & 0 deletions node/src/gql/query/mentor-import-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const SubjectQuestionPreviewType = new GraphQLObjectType({
category: { type: CategoryType },
topics: { type: GraphQLList(TopicType) },
question: { type: QuestionType },
useDefaultTopics: { type: GraphQLBoolean },
},
});
export const AnswerPreviewType = new GraphQLObjectType({
Expand Down
1 change: 1 addition & 0 deletions node/src/gql/types/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const SubjectQuestionType = new GraphQLObjectType({
fields: {
category: { type: CategoryType },
topics: { type: GraphQLList(TopicType) },
useDefaultTopics: { type: GraphQLBoolean },
question: { type: QuestionType },
},
});
Expand Down
3 changes: 3 additions & 0 deletions node/src/models/Subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface SubjectQuestionProps {
question: Question['_id'];
category: Category['id'];
topics: Topic['id'][];
useDefaultTopics?: boolean;
}

export interface SubjectQuestion extends SubjectQuestionProps, Document {}
Expand All @@ -68,6 +69,7 @@ export const SubjectQuestionSchema = new Schema({
question: { type: mongoose.Types.ObjectId, ref: 'Question' },
category: { type: String },
topics: { type: [String] },
useDefaultTopics: { type: Boolean, default: false },
});

export interface Subject extends Document {
Expand Down Expand Up @@ -167,6 +169,7 @@ SubjectSchema.statics.getQuestions = async function (
question: questions.find((q) => `${q._id}` === `${sq.question}`),
category: subject.categories.find((c) => c.id === sq.category),
topics: subject.topics.filter((t) => sq.topics.includes(t.id)),
useDefaultTopics: sq.useDefaultTopics,
}));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('subjectAddOrUpdateQuestions', () => {
question
category
topics
useDefaultTopics
}
}
}`,
Expand All @@ -143,6 +144,7 @@ describe('subjectAddOrUpdateQuestions', () => {
id: '5ffdf41a1ee2c62320b49ec2',
},
],
useDefaultTopics: true,
},
{
question: {
Expand Down Expand Up @@ -170,11 +172,13 @@ describe('subjectAddOrUpdateQuestions', () => {
question: '511111111111111111111116',
category: 'category',
topics: ['5ffdf41a1ee2c62320b49ec2'],
useDefaultTopics: true,
},
{
question: '511111111111111111111110',
category: 'invalid',
topics: ['5ffdf41a1ee2c62320b49ec2'],
useDefaultTopics: false,
},
]);

Expand Down
4 changes: 4 additions & 0 deletions node/test/graphql/mutation/me/subject-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('updateSubject', () => {
question: 'How old are you?',
},
category: { id: 'newcategory' },
useDefaultTopics: true,
topics: [
{
id: 'newtopic',
Expand Down Expand Up @@ -170,6 +171,7 @@ describe('updateSubject', () => {
categoryParent
}
questions {
useDefaultTopics
question {
question
}
Expand Down Expand Up @@ -221,6 +223,7 @@ describe('updateSubject', () => {
question: {
question: 'How old are you?',
},
useDefaultTopics: true,
category: {
id: 'newcategory',
name: 'New category',
Expand All @@ -239,6 +242,7 @@ describe('updateSubject', () => {
{
question: { question: 'new question' },
category: null,
useDefaultTopics: false,
topics: [
{
id: '5ffdf41a1ee2c62320b49ec3',
Expand Down

0 comments on commit 9bf060d

Please sign in to comment.