Skip to content

Commit

Permalink
feat: Created new Graphql Query for fetching blank questionary steps …
Browse files Browse the repository at this point in the history
…with Call Id in Backend.
  • Loading branch information
yoganandaness committed Jun 2, 2023
1 parent 6c98714 commit 334d5f2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface QuestionaryDataSource {
getQuestionary(questionary_id: number): Promise<Questionary | null>;
getQuestionarySteps(questionaryId: number): Promise<QuestionaryStep[]>;
getBlankQuestionarySteps(templateId: number): Promise<QuestionaryStep[]>;
getBlankQuestionaryStepsByCallId(callId: number): Promise<QuestionaryStep[]>;
getAnswers(questionId: string): Promise<AnswerBasic[]>;
getTemplates(questionId: string): Promise<Template[]>;
getIsCompleted(questionaryId: number): Promise<boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -262,6 +264,22 @@ export default class PostgresQuestionaryDataSource
return this.getQuestionaryStepsWithTemplateId(0, templateId);
}

async getBlankQuestionaryStepsByCallId(
callId: number
): Promise<QuestionaryStep[]> {
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,
Expand Down
7 changes: 7 additions & 0 deletions apps/user-office-backend/src/queries/QuestionaryQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export default class QuestionaryQueries {
return this.dataSource.getBlankQuestionarySteps(templateId);
}

async getBlankQuestionaryStepsByCallId(
agent: UserWithRole | null,
callId: number
): Promise<QuestionaryStep[]> {
return this.dataSource.getBlankQuestionaryStepsByCallId(callId);
}

async getQuestionaryStepsOrDefault(
agent: UserWithRole | null,
questionaryId: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
);
}
}

0 comments on commit 334d5f2

Please sign in to comment.