Skip to content

Commit

Permalink
Added form-qquestion feature
Browse files Browse the repository at this point in the history
  • Loading branch information
maikofelix47 committed Jul 20, 2023
1 parent 0c45965 commit b395ced
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 17 deletions.
2 changes: 2 additions & 0 deletions apps/back-end/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { QuestionModule } from '../question/question.module';
import { AnswerTypeModule } from '../answer-type/answer-type.module';
import { AnswerModule } from '../answer/answer.module';
import { FormModule } from '../form/form.module';
import { FormQuestionModule } from '../form-question/form-question.module';

@Module({
imports: [
Expand All @@ -36,6 +37,7 @@ import { FormModule } from '../form/form.module';
AnswerTypeModule,
AnswerModule,
FormModule,
FormQuestionModule,
],
controllers: [AppController],
providers: [PrismaService, AppService],
Expand Down
18 changes: 18 additions & 0 deletions apps/back-end/src/form-question/form-question.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FormQuestionController } from './form-question.controller';

describe('FormQuestionController', () => {
let controller: FormQuestionController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [FormQuestionController],
}).compile();

controller = module.get<FormQuestionController>(FormQuestionController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
22 changes: 22 additions & 0 deletions apps/back-end/src/form-question/form-question.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { FormService } from '../form/form.service';
import { FormQuestionService } from './form-question.service';

@UseGuards(JwtAuthGuard)
@Controller('form-question')
export class FormQuestionController {
constructor(
private formQuestionService: FormQuestionService,
private formService: FormService
) {}
@Get()
findMany() {
return this.formQuestionService.findMany();
}
@Get(':formUuid')
findFormQuestions(@Query() formUuid: string) {
console.log('formUuid', formUuid);
return this.formService.findFormQuestionsByUuid(formUuid);
}
}
11 changes: 11 additions & 0 deletions apps/back-end/src/form-question/form-question.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { PrismaService } from '../app/prisma/prisma.service';
import { FormService } from '../form/form.service';
import { FormQuestionController } from './form-question.controller';
import { FormQuestionService } from './form-question.service';

@Module({
controllers: [FormQuestionController],
providers: [FormQuestionService, PrismaService, FormService],
})
export class FormQuestionModule {}
18 changes: 18 additions & 0 deletions apps/back-end/src/form-question/form-question.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FormQuestionService } from './form-question.service';

describe('FormQuestionService', () => {
let service: FormQuestionService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [FormQuestionService],
}).compile();

service = module.get<FormQuestionService>(FormQuestionService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
26 changes: 26 additions & 0 deletions apps/back-end/src/form-question/form-question.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../app/prisma/prisma.service';

@Injectable()
export class FormQuestionService {
constructor(private prismaService: PrismaService) {}
findMany() {
return this.prismaService.formQuestion.findMany({
select: {
uuid: true,
form: {
select: {
uuid: true,
name: true,
},
},
question: {
select: {
uuid: true,
question: true,
},
},
},
});
}
}
22 changes: 22 additions & 0 deletions apps/back-end/src/form/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,26 @@ export class FormService {
},
});
}
findFormQuestionsByUuid(uuid: string) {
return this.prismaService.form.findFirstOrThrow({
where: {
uuid: uuid,
},
select: {
uuid: true,
name: true,
formQuestions: {
select: {
uuid: true,
question: {
select: {
uuid: true,
question: true,
},
},
},
},
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Replace this with your own classes
*
* e.g.
* .container {
* }
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render } from '@testing-library/react';

import FormBuilder from './form-builder';

describe('FormBuilder', () => {
it('should render successfully', () => {
const { baseElement } = render(<FormBuilder />);
expect(baseElement).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useLoaderData } from 'react-router-dom';

/* eslint-disable-next-line */
export interface FormBuilderProps {}

export function FormBuilder(props: FormBuilderProps) {
const data = useLoaderData() as { formUuid: string };
return (
<div>
<h1>Welcome to FormBuilder!</h1>
</div>
);
}

export default FormBuilder;
14 changes: 13 additions & 1 deletion apps/front-end/src/app/components/forms/form-list/form-list.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import React from 'react';
import { Button } from 'antd';
import { EditOutlined } from '@ant-design/icons';
import TableList from '../../table-list/table-list';
import { useForm } from '../../../resources/hooks/use-form';
import ErrorAlert from '../../error/error-alert';
import Loader from '../../loader/loader';
import { useNavigate } from 'react-router-dom';

const FormList: React.FC = () => {
const { forms, error, isLoading, isError } = useForm();
const navigate = useNavigate();

const editHandler = (formUuid: string) => {
navigate(`./${formUuid}`);
};

if (isError) {
return <ErrorAlert error={error} />;
Expand Down Expand Up @@ -39,7 +47,11 @@ const FormList: React.FC = () => {
key: form.uuid,
form: form.name,
encounterType: form.encounterType.name,
action: '',
action: (
<Button type="default" onClick={() => editHandler(form.uuid)}>
<EditOutlined />
</Button>
),
};
})}
/>
Expand Down
9 changes: 9 additions & 0 deletions apps/front-end/src/app/routes/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import FormDashboard from '../pages/form-dashboard/form-dashboard';
import Questions from '../pages/questions/questions';
import AnswerType from '../pages/answer-type/answer-type';
import Forms from '../pages/forms/forms';
import FormBuilder from '../components/forms/form-builder/form-builder';

export const appRouter = createBrowserRouter([
{
Expand Down Expand Up @@ -87,6 +88,14 @@ export const appRouter = createBrowserRouter([
path: 'forms',
element: <Forms />,
},
{
path: 'forms/:formUuid',
element: <FormBuilder />,
loader: ({ params }) => {
console.log('params', params);
return params;
},
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- CreateTable
CREATE TABLE "FormQuestion" (
"id" SERIAL NOT NULL,
"formId" INTEGER NOT NULL,
"questionId" INTEGER NOT NULL,
"uuid" TEXT NOT NULL,
"voided" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

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

-- AddForeignKey
ALTER TABLE "FormQuestion" ADD CONSTRAINT "FormQuestion_formId_fkey" FOREIGN KEY ("formId") REFERENCES "Form"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FormQuestion" ADD CONSTRAINT "FormQuestion_questionId_fkey" FOREIGN KEY ("questionId") REFERENCES "Question"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
46 changes: 30 additions & 16 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,16 @@ model User {
}

model Question {
id Int @id @default(autoincrement())
question String
answerType AnswerType @relation(fields: [answerTypeId], references: [id])
answerTypeId Int
uuid String @default(uuid())
voided Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
answers Answer[]
id Int @id @default(autoincrement())
question String
answerType AnswerType @relation(fields: [answerTypeId], references: [id])
answerTypeId Int
uuid String @default(uuid())
voided Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
answers Answer[]
formQuestions FormQuestion[]
}

model AnswerType {
Expand Down Expand Up @@ -206,12 +207,25 @@ model Answer {
}

model Form {
id Int @id @default(autoincrement())
name String @unique
encounterType EncounterType @relation(fields: [encounterTypeId], references: [id])
id Int @id @default(autoincrement())
name String @unique
encounterType EncounterType @relation(fields: [encounterTypeId], references: [id])
encounterTypeId Int
uuid String @default(uuid())
voided Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
uuid String @default(uuid())
voided Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
formQuestions FormQuestion[]
}

model FormQuestion {
id Int @id @default(autoincrement())
form Form @relation(fields: [formId], references: [id])
formId Int
question Question @relation(fields: [questionId], references: [id])
questionId Int
uuid String @default(uuid())
voided Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

0 comments on commit b395ced

Please sign in to comment.