fix for create

This commit is contained in:
Michael Schramm 2020-05-29 18:12:49 +02:00
parent 414bc04782
commit eb5bc26e5c
3 changed files with 14 additions and 21 deletions

View File

@ -1,23 +1,8 @@
import { Field, ID, InputType } from '@nestjs/graphql';
import { FormFieldInput } from './form.field.input';
import { FormUpdateInput } from './form.update.input';
@InputType('FormCreateInput')
export class FormCreateInput {
export class FormCreateInput extends FormUpdateInput {
@Field(() => ID, { nullable: true })
readonly id: string
@Field()
readonly title: string
@Field()
readonly language: string
@Field()
readonly showFooter: boolean
@Field()
readonly isLive: boolean
@Field(() => [FormFieldInput], { nullable: true })
readonly fields: FormFieldInput[]
}

View File

@ -4,15 +4,21 @@ import { Model } from 'mongoose';
import { FormCreateInput } from '../../dto/form/form.create.input';
import { FormDocument, FormSchemaName } from '../../schema/form.schema';
import { UserDocument } from '../../schema/user.schema';
import { FormUpdateService } from './form.update.service';
@Injectable()
export class FormCreateService {
constructor(
@InjectModel(FormSchemaName) private formModel: Model<FormDocument>,
@InjectModel(FormSchemaName) private readonly formModel: Model<FormDocument>,
private readonly updateService: FormUpdateService,
) {
}
async create(admin: UserDocument, input: FormCreateInput): Promise<FormDocument> {
return null
const form = await this.formModel.create({
admin
})
return await this.updateService.update(form, input)
}
}

View File

@ -26,6 +26,10 @@ export class FormUpdateService {
form.set('showFooter', input.showFooter)
}
if (input.isLive !== undefined) {
form.set('isLive', input.isLive)
}
const fieldMapping = {}
if (input.fields !== undefined) {
@ -48,8 +52,6 @@ export class FormUpdateService {
return field
}))
console.log('field mapping', fieldMapping)
form.set('fields', nextFields)
}