import { EntitySchemaDatatype } from "../../../core/entity/schema/entity-schema-datatype" ; import { ChildPhotoService } from "./child-photo.service" ; import { EntitySchemaField } from "../../../core/entity/schema/entity-schema-field" ; import { EntitySchemaService } from "../../../core/entity/schema/entity-schema.service" ; import { Entity } from "../../../core/entity/model/entity" ; import { Photo } from "./photo" ; import { SafeUrl } from "@angular/platform-browser" ; import { BehaviorSubject } from "rxjs" ; /**
 * Dynamically load the child's photo through the ChildPhotoService during Entity loading process.
 */ export class PhotoDatatype implements EntitySchemaDatatype { public readonly name = "photo" ; public readonly editComponent = "EditPhoto" ; public transformToDatabaseFormat ( value , schema ) { if ( value . path === schema . defaultValue ) { return undefined ; } else { return value . path ; } } public transformToObjectFormat ( value , schemaField , schemaService , parent ) { if ( typeof parent [ "photoFile" ] === "string" && parent [ "photoFile" ] . trim ( ) !== "" ) { value = parent [ "photoFile" ] ; } return { path : value , photo : new BehaviorSubject < SafeUrl > ( ChildPhotoService . getImageFromAssets ( value ) ) , } ; } }