Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/forms response #115

Merged
merged 21 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1c07429
Refactor getAllForms and getFormById methods to include subQuestions
siasktv Mar 8, 2024
afbbd56
Merge branch 'dev' of https://github.com/chingu-x/chingu-dashboard-be…
siasktv Mar 8, 2024
3101c4a
Modified response to return in/forms and /forms/id
siasktv Mar 8, 2024
8148504
Updated CHANGELOG.md
siasktv Mar 8, 2024
b087581
Update response in /forms /forms/id
siasktv Mar 11, 2024
1168e2d
Updated /forms /formsId response
siasktv Mar 21, 2024
08cdba7
Updated /forms /formsId response to properly include subQuestions und…
siasktv Mar 21, 2024
c1ae4a0
Merge remote-tracking branch 'origin/dev' into features/forms-response
siasktv Mar 24, 2024
4c60c77
Refactor form response classes and update form select query
siasktv Mar 24, 2024
37dede6
Delete prisma/migrations/20240305172254_1222/migration.sql
siasktv Mar 24, 2024
fbc8bdd
Merge branch 'dev' into features/forms-response
cherylli Mar 25, 2024
a740da8
Merge remote-tracking branch 'origin/dev' into features/forms-response
siasktv Mar 26, 2024
68888e9
Merge branch 'features/forms-response' of https://github.com/chingu-x…
siasktv Mar 26, 2024
198b6e3
Update src/forms/forms.response.ts
siasktv Mar 26, 2024
590d904
Refactor code
siasktv Mar 26, 2024
738dc6c
Change data/form in forms/service
siasktv Mar 26, 2024
ff4808b
Change data/form in forms/service
siasktv Mar 26, 2024
abfe53d
Merge branch 'dev' into features/forms-response
siasktv Mar 28, 2024
7dc0ef1
Merge branch 'dev' into features/forms-response
siasktv Apr 3, 2024
cc17c13
Refactor code and fix bugs
siasktv Apr 3, 2024
3ccbe10
Merge branch 'dev' into features/forms-response
siasktv Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Another example [here](https://co-pilot.dev/changelog)
- Update changelog ([#104](https://github.com/chingu-x/chingu-dashboard-be/pull/104))
- Update test.yml to run e2e tests on pull requests to the main branch [#105](https://github.com/chingu-x/chingu-dashboard-be/pull/105)
- Update email templates to use domain in environment variables [#110](https://github.com/chingu-x/chingu-dashboard-be/pull/110)
-Update /forms /forms/id response to include subQuestions [#115](https://github.com/chingu-x/chingu-dashboard-be/pull/115)
- Add role and permission guard to some existing routes (features, forms, ideations, teams) [#112](https://github.com/chingu-x/chingu-dashboard-be/pull/112)

### Fixed
Expand Down
28 changes: 28 additions & 0 deletions prisma/migrations/20240305172254_1222/migration.sql
siasktv marked this conversation as resolved.
Show resolved Hide resolved
siasktv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- CreateTable
CREATE TABLE "FormResponseCheckin" (
"id" SERIAL NOT NULL,
"voyageTeamMemberId" INTEGER NOT NULL,
"sprintId" INTEGER NOT NULL,
"adminComments" TEXT,
"feedbackSent" BOOLEAN NOT NULL DEFAULT false,
"responseGroupId" INTEGER NOT NULL,
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "FormResponseCheckin_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "FormResponseCheckin_responseGroupId_key" ON "FormResponseCheckin"("responseGroupId");

-- CreateIndex
CREATE UNIQUE INDEX "FormResponseCheckin_voyageTeamMemberId_sprintId_key" ON "FormResponseCheckin"("voyageTeamMemberId", "sprintId");

-- AddForeignKey
ALTER TABLE "FormResponseCheckin" ADD CONSTRAINT "FormResponseCheckin_voyageTeamMemberId_fkey" FOREIGN KEY ("voyageTeamMemberId") REFERENCES "VoyageTeamMember"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FormResponseCheckin" ADD CONSTRAINT "FormResponseCheckin_sprintId_fkey" FOREIGN KEY ("sprintId") REFERENCES "Sprint"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FormResponseCheckin" ADD CONSTRAINT "FormResponseCheckin_responseGroupId_fkey" FOREIGN KEY ("responseGroupId") REFERENCES "ResponseGroup"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
35 changes: 34 additions & 1 deletion src/forms/forms.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ class Response {
responseGroupId: number;
}

class subQuestion {
siasktv marked this conversation as resolved.
Show resolved Hide resolved
@ApiProperty({ example: 1 })
id: number;

@ApiProperty({ example: 1 })
order: number;

@ApiProperty()
inputType: InputType;

@ApiProperty({ example: "Changes to be made for the next sprint?" })
text: string;

@Optional()
@ApiProperty({
example:
"Share your thoughts on what could be changed for the next sprint",
})
description: string;

@ApiProperty({ example: false })
answerRequired: boolean;

@Optional()
@ApiProperty({ example: null })
multipleAllowed: boolean;

@Optional()
@ApiProperty({ example: null })
optionGroup: OptionGroup;
}

class Question {
@ApiProperty({ example: 1 })
id: number;
Expand Down Expand Up @@ -97,8 +129,9 @@ class Question {
@ApiProperty({ example: null })
optionGroup: OptionGroup;

@Optional()
@ApiProperty({ isArray: true })
responses: Response;
subQuestions: subQuestion;
}

export class FormResponse {
Expand Down
59 changes: 53 additions & 6 deletions src/forms/forms.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { PrismaService } from "../prisma/prisma.service";
import { Prisma, Question } from "@prisma/client";

export const formSelect = {
id: true,
Expand All @@ -12,6 +13,9 @@ export const formSelect = {
title: true,
description: true,
questions: {
orderBy: {
order: "asc",
},
select: {
id: true,
order: true,
Expand All @@ -35,31 +39,74 @@ export const formSelect = {
},
},
},
subQuestions: true,
},
},
};
} as Prisma.FormSelect;

@Injectable()
export class FormsService {
constructor(private prisma: PrismaService) {}

getAllForms() {
return this.prisma.form.findMany({
async getAllForms() {
const data = await this.prisma.form.findMany({
siasktv marked this conversation as resolved.
Show resolved Hide resolved
select: formSelect,
});

const subQuestionsIds = [];

data.forEach((form) => {
form.questions.forEach((question) => {
const currentQuestion = question as Question & {
subQuestions: Question[];
};
currentQuestion.subQuestions.forEach((subQuestion) => {
subQuestionsIds.push(subQuestion.id);
});
});
});

for (let i = 0; i < data.length; i++) {
const form = data[i];
const filteredQuestions = form.questions.filter(
(i) => !subQuestionsIds.includes(i.id),
);

form.questions = filteredQuestions;
}

return data;
}

async getFormById(formId: number) {
const form = await this.prisma.form.findUnique({
const data = await this.prisma.form.findUnique({
siasktv marked this conversation as resolved.
Show resolved Hide resolved
where: {
id: formId,
},
select: formSelect,
});
if (!form)
if (!data)
throw new NotFoundException(
`Invalid formId: Form (id:${formId}) does not exist.`,
);
return form;
const subQuestionsIds = [];

data.questions.forEach((question) => {
const currentQuestion = question as Question & {
subQuestions: Question[];
};
currentQuestion.subQuestions.forEach((subQuestion) => {
subQuestionsIds.push(subQuestion.id);
});
});

const filteredQuestions = data.questions.filter(
(i) => !subQuestionsIds.includes(i.id),
);

data.questions = filteredQuestions;

return data;
}
}
//
Loading