add field options, rating and logic jump

This commit is contained in:
Michael Schramm 2020-06-02 12:30:57 +02:00
parent 5f8e9bc291
commit 8683a10a3b
12 changed files with 186 additions and 11 deletions

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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,
},
title: {
alias: 'option_title',
// eslint-disable-next-line @typescript-eslint/camelcase
option_id: {
alias: 'key',
type: String,
},
value: {
alias: 'option_value',
// eslint-disable-next-line @typescript-eslint/camelcase
option_title: {
alias: 'title',
type: String,
},
// eslint-disable-next-line @typescript-eslint/camelcase
option_value: {
alias: 'value',
type: String,
trim: true,
},

View File

@ -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,

View File

@ -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: {

View File

@ -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
}))