import { Injectable } from '@nestjs/common' ; import { concatMap , from , last , Observable , of } from 'rxjs' ; import { drive_v3 } from 'googleapis' ; import { EntityType , WatermarkedType , } from '@dark-rush-photography/shared/types' ; import { findGoogleDriveFolders$ } from '@dark-rush-photography/api/util' ; import { EntityCreateOneForFolderProvider } from './entity-create-one-for-folder.provider' ; @ Injectable ( ) export class EntityCreateAllForFolderProvider { constructor ( private readonly entityCreateOneForFolderProvider ) { } createAllEntitiesForFolder$ ( googleDrive , folderId , entityType , watermarkedType , group , initialSlug ? ) { return findGoogleDriveFolders$ ( googleDrive , folderId ) . pipe ( concatMap ( ( entityFolders ) => { if ( entityFolders . length === 0 ) return of ( undefined ) ; return from ( entityFolders ) . pipe ( concatMap ( ( entityFolder ) => this . entityCreateOneForFolderProvider . createOneEntityForFolder$ ( entityFolder , entityType , watermarkedType , group , initialSlug ) ) , last ( ) ) ; } ) ) ; } }