import { OrganizationService as OrganizationServiceAbstraction } from "../abstractions/organization.service" ; import { StateService } from "../abstractions/state.service" ; import { OrganizationData } from "../models/data/organizationData" ; import { Organization } from "../models/domain/organization" ; export class OrganizationService implements OrganizationServiceAbstraction { constructor ( private stateService ) { } async get ( id ) { const organizations = await this . stateService . getOrganizations ( ) ; if ( organizations == null || ! organizations . hasOwnProperty ( id ) ) { return null ; } return new Organization ( organizations [ id ] ) ; } async getByIdentifier ( identifier ) { const organizations = await this . getAll ( ) ; if ( organizations == null || organizations . length === 0 ) { return null ; } return organizations . find ( ( o ) => o . identifier === identifier ) ; } async getAll ( userId ? ) { const organizations = await this . stateService . getOrganizations ( { userId : userId } ) ; const response = [ ] ; for ( const id in organizations ) { if ( organizations . hasOwnProperty ( id ) && ! organizations [ id ] . isProviderUser ) { response . push ( new Organization ( organizations [ id ] ) ) ; } } return response ; } async save ( organizations ) { return await this . stateService . setOrganizations ( organizations ) ; } async canManageSponsorships ( ) { const orgs = await this . getAll ( ) ; return orgs . some ( ( o ) => o . familySponsorshipAvailable || o . familySponsorshipFriendlyName !== null ) ; } }