import { Inject , Injectable } from '@nestjs/common' ; import { concatMap , map , Observable } from 'rxjs' ; import { CronProcessTable } from '../tables/cron-process.table' ; import { loadCronProcessUpdate } from '../cron-processes/cron-process-load.functions' ; import { loadWebSocketCronProcessResponse } from '../cron-processes/web-socket-load-cron-process-response.functions' ; import { CronProcessRepositoryProvider } from './cron-process-repository.provider' ; import { WebSocketMessageProvider } from './web-socket-message.provider' ; @ Injectable ( ) export class CronProcessStateUpdateProvider { constructor ( @ Inject ( CronProcessRepositoryProvider . name ) private readonly cronProcessRepositoryProvider , private readonly webSocketMessageProvider ) { } updateCronProcess$ ( cronProcessTable , cronProcessUpdate ) { return this . cronProcessRepositoryProvider . update$ ( loadCronProcessUpdate ( cronProcessTable , cronProcessUpdate ) ) . pipe ( concatMap ( ( ) => this . webSocketMessageProvider . sendMessage$ ( JSON . stringify ( loadWebSocketCronProcessResponse ( { ... cronProcessTable , ... cronProcessUpdate , } ) ) ) ) , map ( ( ) => undefined ) ) ; } }