add field options, rating and logic jump
This commit is contained in:
parent
5f8e9bc291
commit
8683a10a3b
@ -1,4 +1,8 @@
|
|||||||
import { Field, ID, InputType } from '@nestjs/graphql';
|
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()
|
@InputType()
|
||||||
export class FormFieldInput {
|
export class FormFieldInput {
|
||||||
@ -19,4 +23,13 @@ export class FormFieldInput {
|
|||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
readonly value: string
|
readonly value: string
|
||||||
|
|
||||||
|
@Field(() => [FormFieldOptionInput], { nullable: true })
|
||||||
|
readonly options: [FormFieldOptionInput]
|
||||||
|
|
||||||
|
@Field(() => LogicJumpInput, { nullable: true })
|
||||||
|
readonly logicJump: LogicJumpModel
|
||||||
|
|
||||||
|
@Field(() => FormFieldRatingInput, { nullable: true })
|
||||||
|
readonly rating: FormFieldRatingInput
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
import { Field, ID, ObjectType } from '@nestjs/graphql';
|
||||||
import { FormFieldDocument } from '../../schema/form.field.schema';
|
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')
|
@ObjectType('FormField')
|
||||||
export class FormFieldModel {
|
export class FormFieldModel {
|
||||||
@ -21,6 +24,15 @@ export class FormFieldModel {
|
|||||||
@Field()
|
@Field()
|
||||||
readonly value: string
|
readonly value: string
|
||||||
|
|
||||||
|
@Field(() => [FormFieldOptionModel])
|
||||||
|
readonly options: [FormFieldOptionModel]
|
||||||
|
|
||||||
|
@Field(() => LogicJumpModel)
|
||||||
|
readonly logicJump: LogicJumpModel
|
||||||
|
|
||||||
|
@Field(() => FormFieldRatingModel, { nullable: true })
|
||||||
|
readonly rating: FormFieldRatingModel
|
||||||
|
|
||||||
constructor(document: FormFieldDocument) {
|
constructor(document: FormFieldDocument) {
|
||||||
this.id = document.id
|
this.id = document.id
|
||||||
this.title = document.title
|
this.title = document.title
|
||||||
@ -28,5 +40,8 @@ export class FormFieldModel {
|
|||||||
this.description = document.description
|
this.description = document.description
|
||||||
this.required = document.required
|
this.required = document.required
|
||||||
this.value = document.value
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/dto/form/form.field.option.input.ts
Normal file
13
src/dto/form/form.field.option.input.ts
Normal 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
|
||||||
|
}
|
||||||
20
src/dto/form/form.field.option.model.ts
Normal file
20
src/dto/form/form.field.option.model.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/dto/form/form.field.rating.input.ts
Normal file
11
src/dto/form/form.field.rating.input.ts
Normal 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
|
||||||
|
}
|
||||||
17
src/dto/form/form.field.rating.model.ts
Normal file
17
src/dto/form/form.field.rating.model.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/dto/form/logic.jump.input.ts
Normal file
19
src/dto/form/logic.jump.input.ts
Normal 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
|
||||||
|
}
|
||||||
33
src/dto/form/logic.jump.model.ts
Normal file
33
src/dto/form/logic.jump.model.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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 = {
|
export const FieldOption: SchemaDefinition = {
|
||||||
id: {
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||||
alias: 'option_id',
|
option_id: {
|
||||||
type: Number,
|
alias: 'key',
|
||||||
},
|
|
||||||
title: {
|
|
||||||
alias: 'option_title',
|
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
value: {
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||||
alias: 'option_value',
|
option_title: {
|
||||||
|
alias: 'title',
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||||
|
option_value: {
|
||||||
|
alias: 'value',
|
||||||
type: String,
|
type: String,
|
||||||
trim: true,
|
trim: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,6 +1,14 @@
|
|||||||
import { Schema, SchemaDefinition } from 'mongoose';
|
import { Document, Schema, SchemaDefinition } from 'mongoose';
|
||||||
import { FormFieldSchemaName } from '../form.field.schema';
|
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 = {
|
export const LogicJump: SchemaDefinition = {
|
||||||
expressionString: {
|
expressionString: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@ -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 = {
|
export const RatingField: SchemaDefinition = {
|
||||||
steps: {
|
steps: {
|
||||||
|
|||||||
@ -49,6 +49,18 @@ export class FormUpdateService {
|
|||||||
field.set('required', nextField.required)
|
field.set('required', nextField.required)
|
||||||
field.set('value', nextField.value)
|
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
|
return field
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user