fix field resolvers, add start and end page to create
This commit is contained in:
parent
ef7cd7b3fb
commit
d86b02cf2e
@ -22,6 +22,8 @@ Template for next version
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- add start and end page to form create call
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- notifications / hooks / pages and buttons encode and decode their ids
|
- notifications / hooks / pages and buttons encode and decode their ids
|
||||||
@ -29,6 +31,9 @@ Template for next version
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- missing encode / decode for form fields within submissions (https://github.com/ohmyform/ui/commit/30ff2c96bca20c1641d9cbb96c34cce934e1afea#r68602651)
|
- missing encode / decode for form fields within submissions (https://github.com/ohmyform/ui/commit/30ff2c96bca20c1641d9cbb96c34cce934e1afea#r68602651)
|
||||||
|
- form field resolvers were missing
|
||||||
|
- node-gyp update to enable build on osx 12.3
|
||||||
|
- creating of new fields
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { Field, InputType } from '@nestjs/graphql'
|
import { Field, InputType } from '@nestjs/graphql'
|
||||||
|
import { PageInput } from './page.input'
|
||||||
|
|
||||||
@InputType('FormCreateInput')
|
@InputType('FormCreateInput')
|
||||||
export class FormCreateInput {
|
export class FormCreateInput {
|
||||||
@ -19,4 +20,10 @@ export class FormCreateInput {
|
|||||||
|
|
||||||
@Field({ nullable: true })
|
@Field({ nullable: true })
|
||||||
readonly layout: string
|
readonly layout: string
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
readonly startPage: PageInput
|
||||||
|
|
||||||
|
@Field({ nullable: true })
|
||||||
|
readonly endPage: PageInput
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,6 @@ export class PageInput {
|
|||||||
@Field({ nullable: true })
|
@Field({ nullable: true })
|
||||||
readonly buttonText?: string
|
readonly buttonText?: string
|
||||||
|
|
||||||
@Field(() => [ButtonInput])
|
@Field(() => [ButtonInput], { nullable: true })
|
||||||
readonly buttons: ButtonInput[]
|
readonly buttons: ButtonInput[]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { FormNotificationModel } from '../../dto/form/form.notification.model'
|
|||||||
import { PageModel } from '../../dto/form/page.model'
|
import { PageModel } from '../../dto/form/page.model'
|
||||||
import { UserModel } from '../../dto/user/user.model'
|
import { UserModel } from '../../dto/user/user.model'
|
||||||
import { FormEntity } from '../../entity/form.entity'
|
import { FormEntity } from '../../entity/form.entity'
|
||||||
|
import { FormFieldEntity } from '../../entity/form.field.entity'
|
||||||
import { PageEntity } from '../../entity/page.entity'
|
import { PageEntity } from '../../entity/page.entity'
|
||||||
import { UserEntity } from '../../entity/user.entity'
|
import { UserEntity } from '../../entity/user.entity'
|
||||||
import { FormService } from '../../service/form/form.service'
|
import { FormService } from '../../service/form/form.service'
|
||||||
@ -37,10 +38,14 @@ export class FormResolver {
|
|||||||
|
|
||||||
return form.fields
|
return form.fields
|
||||||
.sort((a,b) => a.idx - b.idx)
|
.sort((a,b) => a.idx - b.idx)
|
||||||
.map(field => new FormFieldModel(
|
.map(field => {
|
||||||
|
cache.add(cache.getCacheKey(FormFieldEntity.name, field.id), field)
|
||||||
|
|
||||||
|
return new FormFieldModel(
|
||||||
this.idService.encode(field.id),
|
this.idService.encode(field.id),
|
||||||
field,
|
field,
|
||||||
))
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResolveField(() => [FormHookModel])
|
@ResolveField(() => [FormHookModel])
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { FormCreateMutation } from './form.create.mutation'
|
import { FormCreateMutation } from './form.create.mutation'
|
||||||
import { FormDeleteMutation } from './form.delete.mutation'
|
import { FormDeleteMutation } from './form.delete.mutation'
|
||||||
|
import { FormFieldResolver } from './form.field.resolver'
|
||||||
import { FormListQuery } from './form.list.query'
|
import { FormListQuery } from './form.list.query'
|
||||||
import { FormQuery } from './form.query'
|
import { FormQuery } from './form.query'
|
||||||
import { FormResolver } from './form.resolver'
|
import { FormResolver } from './form.resolver'
|
||||||
@ -11,6 +12,7 @@ import { PageResolver } from './page.resolver'
|
|||||||
export const formResolvers = [
|
export const formResolvers = [
|
||||||
FormCreateMutation,
|
FormCreateMutation,
|
||||||
FormDeleteMutation,
|
FormDeleteMutation,
|
||||||
|
FormFieldResolver,
|
||||||
FormQuery,
|
FormQuery,
|
||||||
FormResolver,
|
FormResolver,
|
||||||
FormListQuery,
|
FormListQuery,
|
||||||
|
|||||||
@ -3,13 +3,16 @@ import { InjectRepository } from '@nestjs/typeorm'
|
|||||||
import { Repository } from 'typeorm'
|
import { Repository } from 'typeorm'
|
||||||
import { FormCreateInput } from '../../dto/form/form.create.input'
|
import { FormCreateInput } from '../../dto/form/form.create.input'
|
||||||
import { FormEntity } from '../../entity/form.entity'
|
import { FormEntity } from '../../entity/form.entity'
|
||||||
|
import { PageEntity } from '../../entity/page.entity'
|
||||||
import { UserEntity } from '../../entity/user.entity'
|
import { UserEntity } from '../../entity/user.entity'
|
||||||
|
import { FormPageCreateService } from './form.page.create.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormCreateService {
|
export class FormCreateService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(FormEntity)
|
@InjectRepository(FormEntity)
|
||||||
private readonly formRepository: Repository<FormEntity>
|
private readonly formRepository: Repository<FormEntity>,
|
||||||
|
private readonly formPageCreateService: FormPageCreateService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,9 +26,14 @@ export class FormCreateService {
|
|||||||
form.language = input.language || 'en'
|
form.language = input.language || 'en'
|
||||||
form.design.layout = input.layout
|
form.design.layout = input.layout
|
||||||
|
|
||||||
|
|
||||||
|
form.endPage = this.formPageCreateService.create(input.endPage)
|
||||||
|
form.startPage = this.formPageCreateService.create(input.startPage)
|
||||||
|
|
||||||
form.admin = admin
|
form.admin = admin
|
||||||
|
|
||||||
return await this.formRepository.save(form)
|
return await this.formRepository.save(form)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
44
src/service/form/form.page.create.service.ts
Normal file
44
src/service/form/form.page.create.service.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import { PageInput } from '../../dto/form/page.input'
|
||||||
|
import { PageButtonEntity } from '../../entity/page.button.entity'
|
||||||
|
import { PageEntity } from '../../entity/page.entity'
|
||||||
|
import { IdService } from '../id.service'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class FormPageCreateService {
|
||||||
|
constructor(
|
||||||
|
private readonly idService: IdService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public create(input: PageInput): PageEntity {
|
||||||
|
const page = new PageEntity()
|
||||||
|
page.show = Boolean(input?.show)
|
||||||
|
page.buttons = []
|
||||||
|
|
||||||
|
if (!input) {
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
page.title = input.title
|
||||||
|
page.buttonText = input.buttonText
|
||||||
|
page.paragraph = input.paragraph
|
||||||
|
|
||||||
|
if (input.buttons !== undefined) {
|
||||||
|
page.buttons = input.buttons.map(buttonInput => {
|
||||||
|
const button = new PageButtonEntity()
|
||||||
|
button.page = page
|
||||||
|
button.url = buttonInput.url
|
||||||
|
button.action = buttonInput.action
|
||||||
|
button.text = buttonInput.text
|
||||||
|
button.color = buttonInput.color
|
||||||
|
button.bgColor = buttonInput.bgColor
|
||||||
|
button.activeColor = buttonInput.activeColor
|
||||||
|
|
||||||
|
return button
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
}
|
||||||
73
src/service/form/form.page.update.service.ts
Normal file
73
src/service/form/form.page.update.service.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import { PageInput } from '../../dto/form/page.input'
|
||||||
|
import { PageButtonEntity } from '../../entity/page.button.entity'
|
||||||
|
import { PageEntity } from '../../entity/page.entity'
|
||||||
|
import { IdService } from '../id.service'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class FormPageUpdateService {
|
||||||
|
constructor(
|
||||||
|
private readonly idService: IdService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(page: PageEntity, input: PageInput): PageEntity {
|
||||||
|
if (!page) {
|
||||||
|
page = new PageEntity()
|
||||||
|
page.show = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.show !== undefined) {
|
||||||
|
page.show = input.show
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.title !== undefined) {
|
||||||
|
page.title = input.title
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.paragraph !== undefined) {
|
||||||
|
page.paragraph = input.paragraph
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.buttonText !== undefined) {
|
||||||
|
page.buttonText = input.buttonText
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.buttons !== undefined) {
|
||||||
|
page.buttons = input.buttons.map(buttonInput => {
|
||||||
|
const entity = this.findByIdInList(
|
||||||
|
page?.buttons,
|
||||||
|
buttonInput.id,
|
||||||
|
new PageButtonEntity()
|
||||||
|
)
|
||||||
|
|
||||||
|
entity.page = page
|
||||||
|
entity.url = buttonInput.url
|
||||||
|
entity.action = buttonInput.action
|
||||||
|
entity.text = buttonInput.text
|
||||||
|
entity.color = buttonInput.color
|
||||||
|
entity.bgColor = buttonInput.bgColor
|
||||||
|
entity.activeColor = buttonInput.activeColor
|
||||||
|
|
||||||
|
return entity
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private findByIdInList<T extends { id: number }>(list: T[], id: string, fallback: T): T {
|
||||||
|
if (!list || /^NEW-/.test(id)) {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
const found = list.find((value) => value.id === this.idService.decode(id))
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
return found
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ import { FormNotificationEntity } from '../../entity/form.notification.entity'
|
|||||||
import { PageButtonEntity } from '../../entity/page.button.entity'
|
import { PageButtonEntity } from '../../entity/page.button.entity'
|
||||||
import { PageEntity } from '../../entity/page.entity'
|
import { PageEntity } from '../../entity/page.entity'
|
||||||
import { IdService } from '../id.service'
|
import { IdService } from '../id.service'
|
||||||
|
import { FormPageUpdateService } from './form.page.update.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormUpdateService {
|
export class FormUpdateService {
|
||||||
@ -22,6 +23,7 @@ export class FormUpdateService {
|
|||||||
@InjectRepository(FormHookEntity)
|
@InjectRepository(FormHookEntity)
|
||||||
private readonly formHookRepository: Repository<FormHookEntity>,
|
private readonly formHookRepository: Repository<FormHookEntity>,
|
||||||
private readonly idService: IdService,
|
private readonly idService: IdService,
|
||||||
|
private readonly pageService: FormPageUpdateService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,87 +263,11 @@ export class FormUpdateService {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (input.startPage !== undefined) {
|
if (input.startPage !== undefined) {
|
||||||
if (!form.startPage) {
|
form.startPage = this.pageService.update(form.startPage, input.startPage)
|
||||||
form.startPage = new PageEntity()
|
|
||||||
form.startPage.show = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.startPage.show !== undefined) {
|
|
||||||
form.startPage.show = input.startPage.show
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.startPage.title !== undefined) {
|
|
||||||
form.startPage.title = input.startPage.title
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.startPage.paragraph !== undefined) {
|
|
||||||
form.startPage.paragraph = input.startPage.paragraph
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.startPage.buttonText !== undefined) {
|
|
||||||
form.startPage.buttonText = input.startPage.buttonText
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.startPage.buttons !== undefined) {
|
|
||||||
form.startPage.buttons = input.startPage.buttons.map(buttonInput => {
|
|
||||||
const entity = this.findByIdInList(
|
|
||||||
form.startPage?.buttons,
|
|
||||||
buttonInput.id,
|
|
||||||
new PageButtonEntity()
|
|
||||||
)
|
|
||||||
entity.page = form.startPage
|
|
||||||
entity.url = buttonInput.url
|
|
||||||
entity.action = buttonInput.action
|
|
||||||
entity.text = buttonInput.text
|
|
||||||
entity.color = buttonInput.color
|
|
||||||
entity.bgColor = buttonInput.bgColor
|
|
||||||
entity.activeColor = buttonInput.activeColor
|
|
||||||
|
|
||||||
return entity
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.endPage !== undefined) {
|
if (input.endPage !== undefined) {
|
||||||
if (!form.endPage) {
|
form.endPage = this.pageService.update(form.endPage, input.endPage)
|
||||||
form.endPage = new PageEntity()
|
|
||||||
form.endPage.show = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.endPage.show !== undefined) {
|
|
||||||
form.endPage.show = input.endPage.show
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.endPage.title !== undefined) {
|
|
||||||
form.endPage.title = input.endPage.title
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.endPage.paragraph !== undefined) {
|
|
||||||
form.endPage.paragraph = input.endPage.paragraph
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.endPage.buttonText !== undefined) {
|
|
||||||
form.endPage.buttonText = input.endPage.buttonText
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.endPage.buttons !== undefined) {
|
|
||||||
form.endPage.buttons = input.endPage.buttons.map(buttonInput => {
|
|
||||||
const entity = this.findByIdInList(
|
|
||||||
form.endPage?.buttons,
|
|
||||||
buttonInput.id,
|
|
||||||
new PageButtonEntity()
|
|
||||||
)
|
|
||||||
entity.page = form.endPage
|
|
||||||
entity.url = buttonInput.url
|
|
||||||
entity.action = buttonInput.action
|
|
||||||
entity.text = buttonInput.text
|
|
||||||
entity.color = buttonInput.color
|
|
||||||
entity.bgColor = buttonInput.bgColor
|
|
||||||
entity.activeColor = buttonInput.activeColor
|
|
||||||
|
|
||||||
return entity
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.formRepository.save(form)
|
await this.formRepository.save(form)
|
||||||
@ -350,7 +276,7 @@ export class FormUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private findByIdInList<T extends { id: number }>(list: T[], id: string, fallback: T): T {
|
private findByIdInList<T extends { id: number }>(list: T[], id: string, fallback: T): T {
|
||||||
if (!list) {
|
if (!list || /^NEW-/.test(id)) {
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { FormCreateService } from './form.create.service'
|
import { FormCreateService } from './form.create.service'
|
||||||
import { FormDeleteService } from './form.delete.service'
|
import { FormDeleteService } from './form.delete.service'
|
||||||
import { FormFieldService } from './form.field.service'
|
import { FormFieldService } from './form.field.service'
|
||||||
|
import { FormPageCreateService } from './form.page.create.service'
|
||||||
|
import { FormPageUpdateService } from './form.page.update.service'
|
||||||
import { FormService } from './form.service'
|
import { FormService } from './form.service'
|
||||||
import { FormStatisticService } from './form.statistic.service'
|
import { FormStatisticService } from './form.statistic.service'
|
||||||
import { FormUpdateService } from './form.update.service'
|
import { FormUpdateService } from './form.update.service'
|
||||||
@ -9,6 +11,8 @@ export const formServices = [
|
|||||||
FormCreateService,
|
FormCreateService,
|
||||||
FormDeleteService,
|
FormDeleteService,
|
||||||
FormFieldService,
|
FormFieldService,
|
||||||
|
FormPageCreateService,
|
||||||
|
FormPageUpdateService,
|
||||||
FormService,
|
FormService,
|
||||||
FormStatisticService,
|
FormStatisticService,
|
||||||
FormUpdateService,
|
FormUpdateService,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user