add slug and fix missing admin error

https://github.com/ohmyform/ohmyform/issues/100
This commit is contained in:
Michael Schramm 2020-06-19 11:34:25 +02:00
parent 76969b0da1
commit 7d14e393b4
7 changed files with 27 additions and 2 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- default index.html for api without bundled ui
- slug for form fields can now be saved
### Changed
@ -18,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- bug in settings resolver with nullable fields
- bug if user was deleted and form still exists
### Security

View File

@ -19,6 +19,7 @@ export const matchType = {
color: /^#([A-F0-9]{6}|[A-F0-9]{3})$/i,
url: /((([A-Z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/i,
email: /.+@.+\..+/,
slug: /^[a-z0-9_]+$/,
}
export const validatePassword = (password: string): true | string => {

View File

@ -15,6 +15,9 @@ export class FormFieldInput {
@Field()
readonly type: string
@Field({ nullable: true })
readonly slug?: string
@Field()
readonly description: string

View File

@ -12,6 +12,9 @@ export class FormFieldModel {
@Field()
readonly title: string
@Field({ nullable: true })
readonly slug?: string
@Field()
readonly type: string
@ -36,6 +39,7 @@ export class FormFieldModel {
constructor(document: FormFieldDocument) {
this.id = document.id
this.title = document.title
this.slug = document.slug
this.type = document.type
this.description = document.description
this.required = document.required

View File

@ -126,7 +126,7 @@ export class FormResolver {
return new PageModel(form.endPage)
}
@ResolveField('admin', () => UserModel)
@ResolveField('admin', () => UserModel, { nullable: true })
@Roles('admin')
async getAdmin(
@Parent() parent: FormModel,
@ -139,6 +139,10 @@ export class FormResolver {
await form.execPopulate()
}
if (!form.admin) {
return null
}
return new UserModel(form.admin)
}
}

View File

@ -1,5 +1,5 @@
import { Document, Schema } from 'mongoose';
import { fieldTypes } from '../config/fields';
import { fieldTypes, matchType } from '../config/fields'
import { FieldOption } from './embedded/field.option';
import { LogicJump } from './embedded/logic.jump';
import { RatingField } from './embedded/rating.field';
@ -9,6 +9,7 @@ export const FormFieldSchemaName = 'FormField'
export interface FormFieldDocument extends Document {
title: string
description: string
slug?: string
logicJump: any
rating: any
options: any
@ -27,6 +28,12 @@ export const FormFieldSchema = new Schema({
type: String,
default: '',
},
slug: {
type: String,
required: false,
match: matchType.slug,
trim: true,
},
logicJump: {
type: LogicJump,
},

View File

@ -49,6 +49,10 @@ export class FormUpdateService {
field.set('required', nextField.required)
field.set('value', nextField.value)
if (nextField.slug !== undefined) {
field.set('slug', nextField.slug)
}
if (nextField.logicJump !== undefined) {
field.set('logicJump', nextField.logicJump)
}