fix build
This commit is contained in:
parent
27aa5ebfb0
commit
c71e87ec50
@ -1,8 +1,5 @@
|
||||
import { Field, ID, ObjectType } from '@nestjs/graphql'
|
||||
import { FormFieldEntity } from '../../entity/form.field.entity'
|
||||
import { FormFieldLogicModel } from './form.field.logic.model'
|
||||
import { FormFieldOptionModel } from './form.field.option.model'
|
||||
import { FormFieldRatingModel } from './form.field.rating.model'
|
||||
|
||||
@ObjectType('FormField')
|
||||
export class FormFieldModel {
|
||||
@ -32,15 +29,6 @@ export class FormFieldModel {
|
||||
@Field({ nullable: true })
|
||||
readonly defaultValue: string
|
||||
|
||||
@Field(() => [FormFieldOptionModel])
|
||||
readonly options: FormFieldOptionModel[]
|
||||
|
||||
@Field(() => [FormFieldLogicModel])
|
||||
readonly logic: FormFieldLogicModel[]
|
||||
|
||||
@Field(() => FormFieldRatingModel, { nullable: true })
|
||||
readonly rating: FormFieldRatingModel
|
||||
|
||||
constructor(id: string, document: FormFieldEntity) {
|
||||
this._id = document.id
|
||||
this.id = id
|
||||
@ -51,8 +39,5 @@ export class FormFieldModel {
|
||||
this.description = document.description
|
||||
this.required = document.required
|
||||
this.defaultValue = document.defaultValue
|
||||
this.options = document.options?.map(option => new FormFieldOptionModel(option)) || []
|
||||
this.logic = document.logic?.map(logic => new FormFieldLogicModel(logic)) || []
|
||||
this.rating = document.rating ? new FormFieldRatingModel(document.rating) : null
|
||||
}
|
||||
}
|
||||
|
||||
73
src/resolver/form/form.field.resolver.ts
Normal file
73
src/resolver/form/form.field.resolver.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { Context, Parent, ResolveField, Resolver } from '@nestjs/graphql'
|
||||
import { FormFieldLogicModel } from '../../dto/form/form.field.logic.model'
|
||||
import { FormFieldModel } from '../../dto/form/form.field.model'
|
||||
import { FormFieldOptionModel } from '../../dto/form/form.field.option.model'
|
||||
import { FormFieldRatingModel } from '../../dto/form/form.field.rating.model'
|
||||
import { FormFieldEntity } from '../../entity/form.field.entity'
|
||||
import { IdService } from '../../service/id.service'
|
||||
import { ContextCache } from '../context.cache'
|
||||
|
||||
@Resolver(FormFieldModel)
|
||||
export class FormFieldResolver {
|
||||
constructor(
|
||||
private readonly idService: IdService,
|
||||
) {
|
||||
}
|
||||
|
||||
@ResolveField(() => [FormFieldOptionModel])
|
||||
async options(
|
||||
@Parent() parent: FormFieldModel,
|
||||
@Context('cache') cache: ContextCache,
|
||||
): Promise<FormFieldOptionModel[]> {
|
||||
const field = await cache.get<FormFieldEntity>(cache.getCacheKey(
|
||||
FormFieldEntity.name,
|
||||
parent._id
|
||||
))
|
||||
|
||||
if (!field.options) {
|
||||
return []
|
||||
}
|
||||
|
||||
return field.options.map(option => new FormFieldOptionModel(
|
||||
this.idService.encode(option.id),
|
||||
option,
|
||||
))
|
||||
}
|
||||
|
||||
@ResolveField(() => [FormFieldLogicModel])
|
||||
async logic(
|
||||
@Parent() parent: FormFieldModel,
|
||||
@Context('cache') cache: ContextCache,
|
||||
): Promise<FormFieldLogicModel[]> {
|
||||
const field = await cache.get<FormFieldEntity>(cache.getCacheKey(
|
||||
FormFieldEntity.name,
|
||||
parent._id
|
||||
))
|
||||
|
||||
if (!field.logic) {
|
||||
return []
|
||||
}
|
||||
|
||||
return field.logic.map(logic => new FormFieldLogicModel(
|
||||
this.idService.encode(logic.id),
|
||||
logic,
|
||||
))
|
||||
}
|
||||
|
||||
@ResolveField(() => FormFieldRatingModel, { nullable: true })
|
||||
async rating(
|
||||
@Parent() parent: FormFieldModel,
|
||||
@Context('cache') cache: ContextCache,
|
||||
): Promise<FormFieldRatingModel> {
|
||||
const field = await cache.get<FormFieldEntity>(cache.getCacheKey(
|
||||
FormFieldEntity.name,
|
||||
parent._id
|
||||
))
|
||||
|
||||
if (!field.rating) {
|
||||
return null
|
||||
}
|
||||
|
||||
return new FormFieldRatingModel(field.rating)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user