diff --git a/src/app.module.ts b/src/app.module.ts index ddef965..41524a5 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,6 +4,7 @@ import { MongooseModule } from '@nestjs/mongoose'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { ParticipantModule } from './participant/participant.module'; +import { QuestionModule } from './question/question.module'; // import { TestModule } from './test/test.module'; @Module({ @@ -13,6 +14,7 @@ import { ParticipantModule } from './participant/participant.module'; }), MongooseModule.forRoot(process.env.MONGODB_URI || 'mongodb://localhost:27017/db'), ParticipantModule, + QuestionModule ], controllers: [AppController], providers: [AppService], diff --git a/src/question/entity/attachment.entity.ts b/src/attachment/entity/attachment.entity.ts similarity index 90% rename from src/question/entity/attachment.entity.ts rename to src/attachment/entity/attachment.entity.ts index 8d488ff..b500af5 100644 --- a/src/question/entity/attachment.entity.ts +++ b/src/attachment/entity/attachment.entity.ts @@ -18,9 +18,10 @@ export class Attachment extends BaseEntity { @Prop({ type: String, + enum: ['png', 'pdf', 'csv', 'jpg'], required: true, }) - fileType: string; + fileType: 'png' | 'pdf' | 'csv' | 'jpg'; @Prop({ type: String, diff --git a/src/option/dto/create-option.dto.ts b/src/option/dto/create-option.dto.ts new file mode 100644 index 0000000..abc28b4 --- /dev/null +++ b/src/option/dto/create-option.dto.ts @@ -0,0 +1,26 @@ +import { IsString, IsOptional, ValidateNested } from 'class-validator'; +import { Type } from 'class-transformer'; + +class MetadataEntryDto { + @IsString() + key: string; + + @IsString() + value: string; +} + +class MetadataDto { + @ValidateNested({ each: true }) + @Type(() => MetadataEntryDto) + entries: MetadataEntryDto[]; +} + +export class CreateOptionDto { + @IsString() + text: string; + + @ValidateNested() + @Type(() => MetadataDto) + @IsOptional() + metadata?: MetadataDto; +} \ No newline at end of file diff --git a/src/option/dto/update-option.dto.ts b/src/option/dto/update-option.dto.ts new file mode 100644 index 0000000..2808811 --- /dev/null +++ b/src/option/dto/update-option.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateOptionDto } from './create-option.dto'; + +export class UpdateOptionDto extends PartialType(CreateOptionDto) {} diff --git a/src/question/entity/option.entity.ts b/src/option/entity/option.entity.ts similarity index 100% rename from src/question/entity/option.entity.ts rename to src/option/entity/option.entity.ts diff --git a/src/option/option.controller.ts b/src/option/option.controller.ts new file mode 100644 index 0000000..390c499 --- /dev/null +++ b/src/option/option.controller.ts @@ -0,0 +1,42 @@ +import { Controller, Get, Post, Patch, Delete, Param, Body, UsePipes, ValidationPipe } from '@nestjs/common'; +import { ParseUUIDPipe } from '@nestjs/common'; +import { OptionService } from './option.service'; +import { CreateOptionDto } from './dto/create-option.dto'; +import { UpdateOptionDto } from './dto/update-option.dto'; +import { Option } from './entity/option.entity'; +import { Paginate, Paginated, PaginateQuery } from 'nestjs-paginate'; + +@Controller('options') +export class OptionController { + constructor(private readonly optionService: OptionService) {} + + @Post() + @UsePipes(new ValidationPipe({ transform: true })) + async create(@Body() body: CreateOptionDto): Promise