From 2394473dc208090582f696e3f96f1d274250fe55 Mon Sep 17 00:00:00 2001 From: uptown Date: Sat, 26 Aug 2023 09:23:23 -0700 Subject: [PATCH] feat: added ability to answer --- apps/backend/src/app/app.controller.ts | 13 +++---- apps/backend/src/app/app.model.ts | 7 +--- apps/website/src/modules/qna/Question.svelte | 41 ++++++++++++++++++++ apps/website/src/modules/qna/Topic.svelte | 10 ++--- apps/website/src/modules/qna/Topics.svelte | 18 +++++++-- 5 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 apps/website/src/modules/qna/Question.svelte diff --git a/apps/backend/src/app/app.controller.ts b/apps/backend/src/app/app.controller.ts index 541413e..508e437 100644 --- a/apps/backend/src/app/app.controller.ts +++ b/apps/backend/src/app/app.controller.ts @@ -74,11 +74,13 @@ export class AppController { }, }, }, + include: { + answers: true, + }, }); return { ...question, - answerCount: 0, voteCount: 0, }; } @@ -120,6 +122,7 @@ export class AppController { answers: { select: { id: true, + value: true, }, }, }, @@ -157,10 +160,7 @@ export class AppController { }, }); - return { - ...answer, - voteCount: 0, - }; + return answer; } @ApiResponse({ type: Answer, status: 200, isArray: true }) @@ -206,7 +206,6 @@ export class AppController { return { ...vote.question, voteCount: vote.question.votes.length, - answerCount: vote.question.answers.length, }; } @@ -232,7 +231,7 @@ export class AppController { return { ...vote.answer, - voteCount: vote.answer.votes.length, + // voteCount: vote.answer.votes.length, }; } } diff --git a/apps/backend/src/app/app.model.ts b/apps/backend/src/app/app.model.ts index 44904e9..2ec20b9 100644 --- a/apps/backend/src/app/app.model.ts +++ b/apps/backend/src/app/app.model.ts @@ -20,10 +20,10 @@ export class Question { title: string; @ApiProperty() - answerCount: number; + voteCount: number; @ApiProperty() - voteCount: number; + answers: Answer[]; } export class Page { @@ -62,7 +62,4 @@ export class Answer { @ApiProperty() value: string; - - @ApiProperty() - voteCount: number; } diff --git a/apps/website/src/modules/qna/Question.svelte b/apps/website/src/modules/qna/Question.svelte new file mode 100644 index 0000000..c308953 --- /dev/null +++ b/apps/website/src/modules/qna/Question.svelte @@ -0,0 +1,41 @@ + + +
+ {question.title}
+ Votes: {question.voteCount} | Answers: {question.answers.length} + +
addAnswer(question.id, form.answer)}> +