Skip to content

Commit

Permalink
Added question module
Browse files Browse the repository at this point in the history
  • Loading branch information
maikofelix47 committed Jul 10, 2023
1 parent d1e9060 commit 47f97ca
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 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 @@ -14,6 +14,7 @@ import { EncountersModule } from '../encounters/encounters.module';
import { PatientStatisticsModule } from '../patient-statistics/patient-statistics.module';
import { UsersModule } from '../users/users.module';
import { AuthModule } from '../auth/auth.module';
import { QuestionModule } from '../question/question.module';

@Module({
imports: [
Expand All @@ -28,6 +29,7 @@ import { AuthModule } from '../auth/auth.module';
PatientStatisticsModule,
UsersModule,
AuthModule,
QuestionModule,
],
controllers: [AppController],
providers: [PrismaService, AppService],
Expand Down
3 changes: 3 additions & 0 deletions apps/back-end/src/question/dtos/create-question.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CreateQuestionDto {
question: string;
}
18 changes: 18 additions & 0 deletions apps/back-end/src/question/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 { QuestionController } from './question.controller';

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

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

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

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
19 changes: 19 additions & 0 deletions apps/back-end/src/question/question.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Body, Controller, Get, Post } from '@nestjs/common';
import { Question } from '@prisma/client';
import { CreateQuestionDto } from './dtos/create-question.dto';
import { QuestionService } from './question.service';

@Controller('question')
export class QuestionController {
constructor(private questionService: QuestionService) {}
@Get()
findAll(): Promise<Question[]> {
return this.questionService.findAll();
}

@Post()
createOne(@Body() body: CreateQuestionDto) {
const { question } = body;
return this.questionService.createOne(question);
}
}
10 changes: 10 additions & 0 deletions apps/back-end/src/question/question.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { QuestionController } from './question.controller';
import { QuestionService } from './question.service';
import { PrismaService } from '../app/prisma/prisma.service';

@Module({
controllers: [QuestionController],
providers: [QuestionService, PrismaService],
})
export class QuestionModule {}
18 changes: 18 additions & 0 deletions apps/back-end/src/question/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 { QuestionService } from './question.service';

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

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

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

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

@Injectable()
export class QuestionService {
constructor(private prismaService: PrismaService) {}
findAll() {
return this.prismaService.question.findMany();
}
createOne(question: string) {
return this.prismaService.question.create({
data: {
question: question,
},
});
}
}

0 comments on commit 47f97ca

Please sign in to comment.