diff --git a/node/src/gql/mutation/me/subject-add-or-update-questions.ts b/node/src/gql/mutation/me/subject-add-or-update-questions.ts index e653769..0ff7539 100644 --- a/node/src/gql/mutation/me/subject-add-or-update-questions.ts +++ b/node/src/gql/mutation/me/subject-add-or-update-questions.ts @@ -10,6 +10,7 @@ import { GraphQLID, GraphQLList, GraphQLString, + GraphQLBoolean, } from 'graphql'; import { User } from '../../../models/User'; @@ -23,6 +24,7 @@ interface SubjectAddOrUpdateQuestionGQLType { question: number; category: string; topics: string[]; + useDefaultTopics?: boolean; } export const SubjectAddOrUpdateQuestionGQLType = new GraphQLObjectType({ @@ -31,6 +33,7 @@ export const SubjectAddOrUpdateQuestionGQLType = new GraphQLObjectType({ category: { type: GraphQLString }, topics: { type: GraphQLList(GraphQLID) }, question: { type: GraphQLID }, + useDefaultTopics: { type: GraphQLBoolean }, }, }); diff --git a/node/src/gql/mutation/me/subject-update.ts b/node/src/gql/mutation/me/subject-update.ts index 2add9e0..6d87947 100644 --- a/node/src/gql/mutation/me/subject-update.ts +++ b/node/src/gql/mutation/me/subject-update.ts @@ -67,6 +67,7 @@ export interface SubjectQuestionUpdateInput { question: QuestionUpdateInput; category?: CategoryUpdateInput; topics?: TopicUpdateInput[]; + useDefaultTopics?: boolean; } export const SubjectQuestionInputType = new GraphQLInputObjectType({ @@ -75,6 +76,7 @@ export const SubjectQuestionInputType = new GraphQLInputObjectType({ question: { type: QuestionUpdateInputType }, category: { type: CategoryInputType }, topics: { type: GraphQLList(TopicInputType) }, + useDefaultTopics: { type: GraphQLBoolean }, }), }); @@ -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 diff --git a/node/src/gql/query/mentor-import-preview.ts b/node/src/gql/query/mentor-import-preview.ts index ecbc00e..416a098 100644 --- a/node/src/gql/query/mentor-import-preview.ts +++ b/node/src/gql/query/mentor-import-preview.ts @@ -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({ diff --git a/node/src/gql/types/subject.ts b/node/src/gql/types/subject.ts index 6177944..b96a798 100644 --- a/node/src/gql/types/subject.ts +++ b/node/src/gql/types/subject.ts @@ -41,6 +41,7 @@ export const SubjectQuestionType = new GraphQLObjectType({ fields: { category: { type: CategoryType }, topics: { type: GraphQLList(TopicType) }, + useDefaultTopics: { type: GraphQLBoolean }, question: { type: QuestionType }, }, }); diff --git a/node/src/models/Subject.ts b/node/src/models/Subject.ts index f803c68..25ffa31 100644 --- a/node/src/models/Subject.ts +++ b/node/src/models/Subject.ts @@ -60,6 +60,7 @@ export interface SubjectQuestionProps { question: Question['_id']; category: Category['id']; topics: Topic['id'][]; + useDefaultTopics?: boolean; } export interface SubjectQuestion extends SubjectQuestionProps, Document {} @@ -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 { @@ -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, })); }; diff --git a/node/test/graphql/mutation/me/subject-add-or-update-questions.spec.ts b/node/test/graphql/mutation/me/subject-add-or-update-questions.spec.ts index a1cf3fd..bffce8a 100644 --- a/node/test/graphql/mutation/me/subject-add-or-update-questions.spec.ts +++ b/node/test/graphql/mutation/me/subject-add-or-update-questions.spec.ts @@ -125,6 +125,7 @@ describe('subjectAddOrUpdateQuestions', () => { question category topics + useDefaultTopics } } }`, @@ -143,6 +144,7 @@ describe('subjectAddOrUpdateQuestions', () => { id: '5ffdf41a1ee2c62320b49ec2', }, ], + useDefaultTopics: true, }, { question: { @@ -170,11 +172,13 @@ describe('subjectAddOrUpdateQuestions', () => { question: '511111111111111111111116', category: 'category', topics: ['5ffdf41a1ee2c62320b49ec2'], + useDefaultTopics: true, }, { question: '511111111111111111111110', category: 'invalid', topics: ['5ffdf41a1ee2c62320b49ec2'], + useDefaultTopics: false, }, ]); diff --git a/node/test/graphql/mutation/me/subject-update.spec.ts b/node/test/graphql/mutation/me/subject-update.spec.ts index c6df2cb..e5421f0 100644 --- a/node/test/graphql/mutation/me/subject-update.spec.ts +++ b/node/test/graphql/mutation/me/subject-update.spec.ts @@ -123,6 +123,7 @@ describe('updateSubject', () => { question: 'How old are you?', }, category: { id: 'newcategory' }, + useDefaultTopics: true, topics: [ { id: 'newtopic', @@ -170,6 +171,7 @@ describe('updateSubject', () => { categoryParent } questions { + useDefaultTopics question { question } @@ -221,6 +223,7 @@ describe('updateSubject', () => { question: { question: 'How old are you?', }, + useDefaultTopics: true, category: { id: 'newcategory', name: 'New category', @@ -239,6 +242,7 @@ describe('updateSubject', () => { { question: { question: 'new question' }, category: null, + useDefaultTopics: false, topics: [ { id: '5ffdf41a1ee2c62320b49ec3',