diff --git a/src/dto/form/form.field.input.ts b/src/dto/form/form.field.input.ts index f4151b6..10e8624 100644 --- a/src/dto/form/form.field.input.ts +++ b/src/dto/form/form.field.input.ts @@ -1,4 +1,8 @@ import { Field, ID, InputType } from '@nestjs/graphql'; +import { FormFieldOptionInput } from './form.field.option.input'; +import { FormFieldRatingInput } from './form.field.rating.input'; +import { LogicJumpInput } from './logic.jump.input'; +import { LogicJumpModel } from './logic.jump.model'; @InputType() export class FormFieldInput { @@ -19,4 +23,13 @@ export class FormFieldInput { @Field() readonly value: string + + @Field(() => [FormFieldOptionInput], { nullable: true }) + readonly options: [FormFieldOptionInput] + + @Field(() => LogicJumpInput, { nullable: true }) + readonly logicJump: LogicJumpModel + + @Field(() => FormFieldRatingInput, { nullable: true }) + readonly rating: FormFieldRatingInput } diff --git a/src/dto/form/form.field.model.ts b/src/dto/form/form.field.model.ts index 26e9d0c..37a5f8f 100644 --- a/src/dto/form/form.field.model.ts +++ b/src/dto/form/form.field.model.ts @@ -1,5 +1,8 @@ import { Field, ID, ObjectType } from '@nestjs/graphql'; import { FormFieldDocument } from '../../schema/form.field.schema'; +import { FormFieldOptionModel } from './form.field.option.model'; +import { FormFieldRatingModel } from './form.field.rating.model'; +import { LogicJumpModel } from './logic.jump.model'; @ObjectType('FormField') export class FormFieldModel { @@ -21,6 +24,15 @@ export class FormFieldModel { @Field() readonly value: string + @Field(() => [FormFieldOptionModel]) + readonly options: [FormFieldOptionModel] + + @Field(() => LogicJumpModel) + readonly logicJump: LogicJumpModel + + @Field(() => FormFieldRatingModel, { nullable: true }) + readonly rating: FormFieldRatingModel + constructor(document: FormFieldDocument) { this.id = document.id this.title = document.title @@ -28,5 +40,8 @@ export class FormFieldModel { this.description = document.description this.required = document.required this.value = document.value + this.options = document.options ? document.options.map(option => new FormFieldOptionModel(option)) : [] + this.logicJump = new LogicJumpModel(document.logicJump) + this.rating = document.rating ? new FormFieldRatingModel(document.rating) : null } } diff --git a/src/dto/form/form.field.option.input.ts b/src/dto/form/form.field.option.input.ts new file mode 100644 index 0000000..e2377c2 --- /dev/null +++ b/src/dto/form/form.field.option.input.ts @@ -0,0 +1,13 @@ +import { Field, InputType } from '@nestjs/graphql'; + +@InputType() +export class FormFieldOptionInput { + @Field({ nullable: true }) + readonly key: string + + @Field({ nullable: true }) + readonly title: string + + @Field() + readonly value: string +} diff --git a/src/dto/form/form.field.option.model.ts b/src/dto/form/form.field.option.model.ts new file mode 100644 index 0000000..a8021dd --- /dev/null +++ b/src/dto/form/form.field.option.model.ts @@ -0,0 +1,20 @@ +import { Field, ObjectType } from '@nestjs/graphql'; +import { FieldOptionDocument } from '../../schema/embedded/field.option'; + +@ObjectType('FormFieldOption') +export class FormFieldOptionModel { + @Field({ nullable: true }) + readonly key: string + + @Field({ nullable: true }) + readonly title: string + + @Field() + readonly value: string + + constructor(option: FieldOptionDocument) { + this.key = option.key + this.title = option.title + this.value = option.value + } +} diff --git a/src/dto/form/form.field.rating.input.ts b/src/dto/form/form.field.rating.input.ts new file mode 100644 index 0000000..ea350b1 --- /dev/null +++ b/src/dto/form/form.field.rating.input.ts @@ -0,0 +1,11 @@ +import { Field, InputType } from '@nestjs/graphql'; +import { GraphQLInt } from 'graphql'; + +@InputType() +export class FormFieldRatingInput { + @Field(() => GraphQLInt, { nullable: true }) + readonly steps: number + + @Field({ nullable: true }) + readonly shape: string +} diff --git a/src/dto/form/form.field.rating.model.ts b/src/dto/form/form.field.rating.model.ts new file mode 100644 index 0000000..74b4d74 --- /dev/null +++ b/src/dto/form/form.field.rating.model.ts @@ -0,0 +1,17 @@ +import { Field, ObjectType } from '@nestjs/graphql'; +import { GraphQLInt } from 'graphql'; +import { RatingFieldDocument } from '../../schema/embedded/rating.field'; + +@ObjectType('FormFieldRating') +export class FormFieldRatingModel { + @Field(() => GraphQLInt, { nullable: true }) + readonly steps: number + + @Field({ nullable: true }) + readonly shape: string + + constructor(option: RatingFieldDocument) { + this.steps = option.steps + this.shape = option.shape + } +} diff --git a/src/dto/form/logic.jump.input.ts b/src/dto/form/logic.jump.input.ts new file mode 100644 index 0000000..fa2618e --- /dev/null +++ b/src/dto/form/logic.jump.input.ts @@ -0,0 +1,19 @@ +import { Field, ID, InputType } from '@nestjs/graphql'; + +@InputType() +export class LogicJumpInput { + @Field(() => ID, { nullable: true }) + readonly fieldA: string + + @Field({ nullable: true }) + readonly valueB: string + + @Field({ nullable: true }) + readonly expressionString: string + + @Field(() => ID, { nullable: true }) + readonly jumpTo: string + + @Field({ nullable: true }) + readonly enabled: boolean +} diff --git a/src/dto/form/logic.jump.model.ts b/src/dto/form/logic.jump.model.ts new file mode 100644 index 0000000..48ac7f6 --- /dev/null +++ b/src/dto/form/logic.jump.model.ts @@ -0,0 +1,33 @@ +import { Field, ID, ObjectType } from '@nestjs/graphql'; +import { LogicJumpDocument } from '../../schema/embedded/logic.jump'; + +@ObjectType('LogicJump') +export class LogicJumpModel { + @Field(() => ID, { nullable: true }) + readonly fieldA: string + + @Field({ nullable: true }) + readonly valueB: string + + @Field({ nullable: true }) + readonly expressionString: string + + @Field(() => ID, { nullable: true }) + readonly jumpTo: string + + @Field() + readonly enabled: boolean + + constructor(document: LogicJumpDocument) { + if (!document) { + this.enabled = false + return + } + + this.fieldA = document.fieldA + this.valueB = document.valueB + this.expressionString = document.expressionString + this.jumpTo = document.jumpTo + this.enabled = !!document.enabled + } +} diff --git a/src/schema/embedded/field.option.ts b/src/schema/embedded/field.option.ts index b9f71c2..f6ea880 100644 --- a/src/schema/embedded/field.option.ts +++ b/src/schema/embedded/field.option.ts @@ -1,16 +1,25 @@ -import { SchemaDefinition } from 'mongoose'; +import { Document, SchemaDefinition } from 'mongoose'; + +export interface FieldOptionDocument extends Document { + readonly key?: string + readonly title?: string + readonly value: string +} export const FieldOption: SchemaDefinition = { - id: { - alias: 'option_id', - type: Number, + // eslint-disable-next-line @typescript-eslint/camelcase + option_id: { + alias: 'key', + type: String, }, - title: { - alias: 'option_title', + // eslint-disable-next-line @typescript-eslint/camelcase + option_title: { + alias: 'title', type: String, }, - value: { - alias: 'option_value', + // eslint-disable-next-line @typescript-eslint/camelcase + option_value: { + alias: 'value', type: String, trim: true, }, diff --git a/src/schema/embedded/logic.jump.ts b/src/schema/embedded/logic.jump.ts index 43be689..c34ecf0 100644 --- a/src/schema/embedded/logic.jump.ts +++ b/src/schema/embedded/logic.jump.ts @@ -1,6 +1,14 @@ -import { Schema, SchemaDefinition } from 'mongoose'; +import { Document, Schema, SchemaDefinition } from 'mongoose'; import { FormFieldSchemaName } from '../form.field.schema'; +export interface LogicJumpDocument extends Document { + readonly expressionString?: string + readonly fieldA?: string + readonly valueB?: string + readonly jumpTo?: string + readonly enabled?: boolean +} + export const LogicJump: SchemaDefinition = { expressionString: { type: String, diff --git a/src/schema/embedded/rating.field.ts b/src/schema/embedded/rating.field.ts index 0a16c5c..a61b131 100644 --- a/src/schema/embedded/rating.field.ts +++ b/src/schema/embedded/rating.field.ts @@ -1,4 +1,9 @@ -import { SchemaDefinition } from 'mongoose'; +import { Document, SchemaDefinition } from 'mongoose'; + +export interface RatingFieldDocument extends Document { + readonly steps?: number + readonly shape?: string +} export const RatingField: SchemaDefinition = { steps: { diff --git a/src/service/form/form.update.service.ts b/src/service/form/form.update.service.ts index c5fd387..7a474f2 100644 --- a/src/service/form/form.update.service.ts +++ b/src/service/form/form.update.service.ts @@ -49,6 +49,18 @@ export class FormUpdateService { field.set('required', nextField.required) field.set('value', nextField.value) + if (nextField.logicJump !== undefined) { + field.set('logicJump', nextField.logicJump) + } + + if (nextField.options !== undefined) { + field.set('options', nextField.options) + } + + if (nextField.rating !== undefined) { + field.set('rating', nextField.rating) + } + return field }))