Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 21 additions & 2 deletions src/forms/dto/form-submition.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from "class-transformer";
import { Transform, Type, plainToInstance } from "class-transformer";
import {
IsArray,
IsEmail,
Expand All @@ -22,7 +22,8 @@ export class ParticipantAttributeDto {
"- text/select: string\n" +
"- number: number\n" +
"- multiSelect/block: string[] (Array of UUIDs or options)\n" +
"- checkbox: boolean",
"- checkbox: boolean\n" +
"- for files write filename with extension (e.g., 'document.pdf')",
})
@IsOptional()
value?: unknown;
Expand All @@ -33,12 +34,14 @@ export class FormSubmitionDto {
@IsOptional()
@IsString()
@IsEmail()
@Transform(({ value }) => (value === "" ? undefined : (value as string)))
email?: string;

@ApiPropertyOptional()
@IsOptional()
@IsString()
@IsUUID()
@Transform(({ value }) => (value === "" ? undefined : (value as string)))
participantId?: string;

@ApiProperty({
Expand All @@ -48,5 +51,21 @@ export class FormSubmitionDto {
@IsArray()
@ValidateNested({ each: true })
@Type(() => ParticipantAttributeDto)
@Transform(({ value }) => {
if (value === null || value === undefined || value === "") {
return [];
}
if (typeof value === "string") {
try {
const parsed: unknown = JSON.parse(value);
const array = Array.isArray(parsed) ? parsed : [parsed];
return plainToInstance(ParticipantAttributeDto, array);
} catch {
return value as unknown;
}
}

return value as unknown;
})
attributes: ParticipantAttributeDto[];
}
52 changes: 51 additions & 1 deletion src/forms/forms-public.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import {
} from "@nestjs/common";
import {
ApiBadRequestResponse,
ApiBody,
ApiConsumes,
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiTags,
getSchemaPath,
} from "@nestjs/swagger";

import { FormSubmitionDto } from "./dto/form-submition.dto";
import {
FormSubmitionDto,
ParticipantAttributeDto,
} from "./dto/form-submition.dto";
import { FormsService } from "./forms.service";
import { UploadFiles } from "./utils/upload-files-decorator";

Expand Down Expand Up @@ -48,6 +54,50 @@ export class FormsPublicController {
@ApiOperation({ summary: "Submit a form for an event" })
@ApiParam({ name: "eventSlug", description: "Event slug of the event" })
@ApiParam({ name: "id", description: "UUID of the form" })
@ApiConsumes("multipart/form-data")
@ApiBody({
schema: {
type: "object",
Comment on lines +57 to +60
properties: {
email: {
type: "string",
format: "email",
nullable: true,
description: "Participant's email",
example: "user@example.com",
},
participantId: {
type: "string",
format: "uuid",
nullable: true,
description: "UUID of the participant",
example: "123e4567-e89b-12d3-a456-426614174000",
},
attributes: {
type: "array",
description:
"Array of participant attributes with their values. \n" +
"For each attribute, the value must match the attribute type:\n" +
"- text/select: string\n" +
"- number: number\n" +
"- multiSelect/block: string[] (Array of UUIDs or options)\n" +
"- checkbox: boolean\n" +
"- for files write filename with extension (e.g., 'document.pdf')",
items: {
$ref: getSchemaPath(ParticipantAttributeDto),
},
Comment on lines +84 to +88
},
Comment on lines +76 to +89
files: {
type: "array",
description: "Optional files to attach to the submission",
items: {
type: "string",
format: "binary",
},
},
},
},
})
@ApiOkResponse({ description: "Form submitted successfully." })
@ApiNotFoundResponse({ description: "Event or Form not found." })
@ApiBadRequestResponse({ description: "Form is closed." })
Expand Down
Loading