|
| 1 | +import { EntityAction, EntityType } from './action' |
| 2 | +import { |
| 3 | + ContentType, |
| 4 | + TaxonomyConceptValidationLink, |
| 5 | + TaxonomyConceptSchemeValidationLink |
| 6 | +} from '../entities/content-type' |
| 7 | + |
| 8 | +export class ContentTypeSetTaxonomyValidationsAction extends EntityAction { |
| 9 | + private contentTypeId: string |
| 10 | + private taxonomyValidations: Array< |
| 11 | + TaxonomyConceptValidationLink | TaxonomyConceptSchemeValidationLink |
| 12 | + > |
| 13 | + |
| 14 | + constructor( |
| 15 | + contentTypeId: string, |
| 16 | + taxonomyValidations?: Array<TaxonomyConceptValidationLink | TaxonomyConceptSchemeValidationLink> |
| 17 | + ) { |
| 18 | + super() |
| 19 | + this.contentTypeId = contentTypeId |
| 20 | + this.taxonomyValidations = taxonomyValidations |
| 21 | + } |
| 22 | + |
| 23 | + getEntityId(): string { |
| 24 | + return this.contentTypeId |
| 25 | + } |
| 26 | + |
| 27 | + getEntityType(): EntityType { |
| 28 | + return EntityType.ContentType |
| 29 | + } |
| 30 | + |
| 31 | + async applyTo(ct: ContentType): Promise<void> { |
| 32 | + ct.setTaxonomyValidations(this.taxonomyValidations) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +export class ContentTypeAddTaxonomyValidationAction extends EntityAction { |
| 37 | + private contentTypeId: string |
| 38 | + private taxonomyId: string |
| 39 | + private linkType: 'TaxonomyConcept' | 'TaxonomyConceptScheme' |
| 40 | + private options: { required?: boolean } |
| 41 | + |
| 42 | + constructor( |
| 43 | + contentTypeId: string, |
| 44 | + taxonomyId: string, |
| 45 | + linkType: 'TaxonomyConcept' | 'TaxonomyConceptScheme', |
| 46 | + options: { required?: boolean } = {} |
| 47 | + ) { |
| 48 | + super() |
| 49 | + this.contentTypeId = contentTypeId |
| 50 | + this.taxonomyId = taxonomyId |
| 51 | + this.linkType = linkType |
| 52 | + this.options = options |
| 53 | + } |
| 54 | + |
| 55 | + getEntityId(): string { |
| 56 | + return this.contentTypeId |
| 57 | + } |
| 58 | + |
| 59 | + getEntityType(): EntityType { |
| 60 | + return EntityType.ContentType |
| 61 | + } |
| 62 | + |
| 63 | + async applyTo(ct: ContentType): Promise<void> { |
| 64 | + ct.addTaxonomyValidation(this.taxonomyId, this.linkType, this.options) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +export class ContentTypeClearTaxonomyValidationsAction extends EntityAction { |
| 69 | + private contentTypeId: string |
| 70 | + |
| 71 | + constructor(contentTypeId: string) { |
| 72 | + super() |
| 73 | + this.contentTypeId = contentTypeId |
| 74 | + } |
| 75 | + |
| 76 | + getEntityId(): string { |
| 77 | + return this.contentTypeId |
| 78 | + } |
| 79 | + |
| 80 | + getEntityType(): EntityType { |
| 81 | + return EntityType.ContentType |
| 82 | + } |
| 83 | + |
| 84 | + async applyTo(ct: ContentType): Promise<void> { |
| 85 | + ct.clearTaxonomyValidations() |
| 86 | + } |
| 87 | +} |
0 commit comments