change default form layout to card

This commit is contained in:
Michael Schramm 2022-03-01 15:17:39 +01:00
parent 4a19bd5ca4
commit 5bc6047507
4 changed files with 89 additions and 12 deletions

View File

@ -9,12 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- allow one field nested data to be submitted
### Changed
### Fixed
- only update user fields in update mutation if they changed
- form delete
- field submission without value field
### Security

View File

@ -2,8 +2,12 @@ import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, RelationId } from 't
import { FormFieldEntity } from './form.field.entity'
import { SubmissionEntity } from './submission.entity'
export interface SubmissionFieldContent {
[key: string]: string | string[] | number | number[] | boolean | boolean[]
type Simple = string | number | boolean
export type SubmissionFieldContent = Simple | Simple[] | {
[key: string]: Simple | Simple[] | {
[key: string]: Simple | Simple[]
}
}
@Entity({ name: 'submission_field' })

View File

@ -79,8 +79,8 @@ export class SubmissionNotificationService {
return fallback
}
if (typeof data.value === 'string') {
return data.value
if (typeof data === 'string') {
return data
}
return fallback

View File

@ -84,7 +84,7 @@ export class SubmissionSetFieldService {
field: SubmissionFieldEntity,
data: string
): SubmissionFieldContent {
let raw: { [key: string]: unknown }
let raw: SubmissionFieldContent
const context = {
field: field.fieldId,
@ -92,21 +92,49 @@ export class SubmissionSetFieldService {
}
try {
raw = JSON.parse(data) as { [key: string]: unknown }
raw = JSON.parse(data) as SubmissionFieldContent
} catch (e) {
this.logger.warn(context, 'received invalid data for field')
return { value: null }
}
if (typeof raw !== 'object' || Array.isArray(raw)) {
this.logger.warn(context, 'only object supported for data')
return { value: null }
if (Array.isArray(raw)) {
return raw.map((row: unknown, index) => {
switch (typeof row) {
case 'number':
case 'string':
case 'boolean':
case 'undefined':
return row
}
if (row === null) {
return row
}
this.logger.warn({
...context,
path: `${index}`,
}, 'invalid data in array')
valid = false
return null
})
}
if (
[
'number',
'string',
'boolean',
'undefined',
].includes(typeof raw)
) {
return raw
}
// now ensure data structure
const result = {
value: null,
}
const result = {}
let valid = true
@ -147,6 +175,48 @@ export class SubmissionSetFieldService {
return
}
if (typeof value === 'object') {
result[String(key)] = {}
for (const subKey of Object.keys(value)) {
const subValue = raw[String(key)][String(subKey)]
switch (typeof subValue) {
case 'number':
case 'string':
case 'boolean':
result[String(key)][String(subKey)] = subValue
return
}
if (Array.isArray(subValue)) {
result[String(key)][String(subKey)] = subValue.map((row: unknown, index) => {
switch (typeof row) {
case 'number':
case 'string':
case 'boolean':
case 'undefined':
return row
}
if (row === null) {
return row
}
this.logger.warn({
...context,
path: `${key}/${subKey}/${index}`,
}, 'invalid data in array')
valid = false
return null
})
return
}
}
}
this.logger.warn({
...context,
path: String(key),