import { DemoChildGenerator } from "../children/demo-data-generators/demo-child-generator.service" ; import { DemoDataGenerator } from "../../core/demo-data/demo-data-generator" ; import { Injectable } from "@angular/core" ; import { Child } from "../children/model/child" ; import { faker } from "../../core/demo-data/faker" ; import { EducationalMaterial } from "./model/educational-material" ; import { materials } from "./model/materials" ; export class DemoEducationMaterialConfig { minCount : number ; maxCount : number ; } /**
 * Generate EducationalMaterial records.
 * Builds upon the generated demo Child entities.
 */ @ Injectable ( ) export class DemoEducationalMaterialGeneratorService extends DemoDataGenerator < EducationalMaterial > { /**
     * This function returns a provider object to be used in an Angular Module configuration:
     *   `providers: [DemoEducationalMaterialGeneratorService.provider()]`
     */ static provider ( config ) { return [ { provide : DemoEducationalMaterialGeneratorService , useClass : DemoEducationalMaterialGeneratorService , } , { provide : DemoEducationMaterialConfig , useValue : config } , ] ; } constructor ( private config , private demoChildren ) { super ( ) ; } public generateEntities ( ) { const data = [ ] ; for ( const child of this . demoChildren . entities ) { const count = faker . datatype . number ( { min : this . config . minCount , max : this . config . maxCount , } ) ; for ( let i = 1 ; i < count ; i ++ ) { data . push ( this . generateEducationalMaterialEntity ( child ) ) ; } const specialMaterial = this . generateEducationalMaterialEntity ( child ) ; specialMaterial . materialType = faker . random . arrayElement ( materials . filter ( ( material ) => material . hasOwnProperty ( "color" ) ) ) ; specialMaterial . materialAmount = 1 ; data . push ( specialMaterial ) ; } return data ; } private generateEducationalMaterialEntity ( child ) { const entity = new EducationalMaterial ( ) ; entity . child = child . getId ( ) ; entity . date = faker . date . between ( child . admissionDate , faker . getEarlierDateOrToday ( child . dropoutDate ) ) ; entity . materialAmount = faker . random . arrayElement ( [ 1 , 1 , 1 , 2 , 3 ] ) ; entity . materialType = faker . random . arrayElement ( materials ) ; return entity ; } }