import { StockMoved } from '../events/stock-moved' ; import { Register } from '@boostercloud/framework-types' ; import { ProductAvailabilityChanged } from '../events/product-availability-changed' ; import { Booster , EventHandler } from '@boostercloud/framework-core' ; import { Product } from '../entities/product' ; @ EventHandler ( StockMoved ) export class HandleAvailability { public static async handle ( event , register ) { event . getOrigin ( ) ; const product = await Booster . entity ( Product , event . productID ) ; if ( ! product ) { return ; } product . getId ( ) ; if ( event . origin == 'provider' ) { register . events ( new ProductAvailabilityChanged ( event . productID , event . quantity ) ) ; } else if ( event . destination == 'customer' ) { register . events ( new ProductAvailabilityChanged ( event . productID , - event . quantity ) ) ; } } }