import { ProductUpdated , ProductUpdateReason } from '../../../events/product-updated' ; import { ProductUpdatedV1 , ProductUpdatedV2 , ProductUpdatedV3 , ProductUpdatedV4 } from './schema-versions' ; import { Migrates , ToVersion } from '@boostercloud/framework-core' ; @ Migrates ( ProductUpdated ) export class ProductUpdatedMigration { @ ToVersion ( 2 , { fromSchema : ProductUpdatedV1 , toSchema : ProductUpdatedV2 } ) public addReasonField ( oldEvent ) { const defaultReason = 'CatalogChange' ; return new ProductUpdatedV2 ( oldEvent . product , defaultReason ) ; } @ ToVersion ( 3 , { fromSchema : ProductUpdatedV2 , toSchema : ProductUpdatedV3 } ) public changeReasonFieldToEnum ( oldEvent ) { const defaultReason = ProductUpdateReason . CatalogChange ; let reasonAsEnum = ProductUpdateReason [ oldEvent . reason as ProductUpdateReason ] ; if ( ! reasonAsEnum ) { reasonAsEnum = defaultReason ; } return new ProductUpdatedV3 ( oldEvent . product , reasonAsEnum ) ; } @ ToVersion ( 4 , { fromSchema : ProductUpdatedV3 , toSchema : ProductUpdatedV4 } ) public expandProductFields ( oldEvent ) { return new ProductUpdatedV4 ( oldEvent . product . id , oldEvent . product . sku , oldEvent . product . name , oldEvent . product . description , oldEvent . product . price , oldEvent . product . pictures , oldEvent . product . deleted , oldEvent . reason ) ; } }