From 334d5f22166ac6381a5ef27aff96238c5ab08003 Mon Sep 17 00:00:00 2001 From: Yoganandan Date: Fri, 2 Jun 2023 11:57:04 +0200 Subject: [PATCH] feat: Created new Graphql Query for fetching blank questionary steps with Call Id in Backend. --- .../src/datasources/QuestionaryDataSource.ts | 1 + .../postgres/QuestionaryDataSource.ts | 18 ++++++++++++++++++ .../src/queries/QuestionaryQueries.ts | 7 +++++++ .../BlankQuestionaryStepsByCallIdQuery.ts | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 apps/user-office-backend/src/resolvers/queries/BlankQuestionaryStepsByCallIdQuery.ts diff --git a/apps/user-office-backend/src/datasources/QuestionaryDataSource.ts b/apps/user-office-backend/src/datasources/QuestionaryDataSource.ts index 8b52e06cd8..5e5bf3aafd 100644 --- a/apps/user-office-backend/src/datasources/QuestionaryDataSource.ts +++ b/apps/user-office-backend/src/datasources/QuestionaryDataSource.ts @@ -16,6 +16,7 @@ export interface QuestionaryDataSource { getQuestionary(questionary_id: number): Promise; getQuestionarySteps(questionaryId: number): Promise; getBlankQuestionarySteps(templateId: number): Promise; + getBlankQuestionaryStepsByCallId(callId: number): Promise; getAnswers(questionId: string): Promise; getTemplates(questionId: string): Promise; getIsCompleted(questionaryId: number): Promise; diff --git a/apps/user-office-backend/src/datasources/postgres/QuestionaryDataSource.ts b/apps/user-office-backend/src/datasources/postgres/QuestionaryDataSource.ts index 2b7cc83782..c21279e42f 100644 --- a/apps/user-office-backend/src/datasources/postgres/QuestionaryDataSource.ts +++ b/apps/user-office-backend/src/datasources/postgres/QuestionaryDataSource.ts @@ -13,7 +13,9 @@ import { ConfigBase } from '../../resolvers/types/FieldConfig'; import { QuestionaryDataSource } from '../QuestionaryDataSource'; import database from './database'; import { + CallRecord, createAnswerBasic, + createCallObject, createProposalTemplateObject, createQuestionaryObject, createQuestionTemplateRelationObject, @@ -262,6 +264,22 @@ export default class PostgresQuestionaryDataSource return this.getQuestionaryStepsWithTemplateId(0, templateId); } + async getBlankQuestionaryStepsByCallId( + callId: number + ): Promise { + const call = await database + .select() + .from('call') + .where('call_id', callId) + .first() + .then((call: CallRecord | null) => + call ? createCallObject(call) : null + ); + if (!call) return []; + + return this.getQuestionaryStepsWithTemplateId(0, call.templateId); + } + async updateTopicCompleteness( questionary_id: number, topic_id: number, diff --git a/apps/user-office-backend/src/queries/QuestionaryQueries.ts b/apps/user-office-backend/src/queries/QuestionaryQueries.ts index 3db3c86be9..6f3f49e70d 100644 --- a/apps/user-office-backend/src/queries/QuestionaryQueries.ts +++ b/apps/user-office-backend/src/queries/QuestionaryQueries.ts @@ -127,6 +127,13 @@ export default class QuestionaryQueries { return this.dataSource.getBlankQuestionarySteps(templateId); } + async getBlankQuestionaryStepsByCallId( + agent: UserWithRole | null, + callId: number + ): Promise { + return this.dataSource.getBlankQuestionaryStepsByCallId(callId); + } + async getQuestionaryStepsOrDefault( agent: UserWithRole | null, questionaryId: number, diff --git a/apps/user-office-backend/src/resolvers/queries/BlankQuestionaryStepsByCallIdQuery.ts b/apps/user-office-backend/src/resolvers/queries/BlankQuestionaryStepsByCallIdQuery.ts new file mode 100644 index 0000000000..715f11f7d3 --- /dev/null +++ b/apps/user-office-backend/src/resolvers/queries/BlankQuestionaryStepsByCallIdQuery.ts @@ -0,0 +1,18 @@ +import { Arg, Ctx, Int, Query, Resolver } from 'type-graphql'; + +import { ResolverContext } from '../../context'; +import { QuestionaryStep } from '../types/QuestionaryStep'; + +@Resolver() +export class BlankQuestionaryStepsByCallIdQuery { + @Query(() => [QuestionaryStep], { nullable: true }) + blankQuestionaryStepsByCallId( + @Ctx() context: ResolverContext, + @Arg('callId', () => Int) callId: number + ) { + return context.queries.questionary.getBlankQuestionaryStepsByCallId( + context.user, + callId + ); + } +}