import { Command } from '@boostercloud/framework-core' ; import { ProductCreated } from '../events/product-created' ; import { Register , UUID } from '@boostercloud/framework-types' ; import { UserWithEmail , Admin } from '../roles' ; import { SKU } from '../common/sku' ; @ Command ( { authorize : [ Admin , UserWithEmail ] , } ) export class CreateProduct { public constructor ( readonly sku , readonly displayName , readonly description , readonly priceInCents , readonly currency , readonly productID ? ) { } public static async handle ( command , register ) { const productID = command . productID ?? UUID . generate ( ) ; register . events ( new ProductCreated ( productID , command . sku , command . displayName , command . description , { cents : command . priceInCents , currency : command . currency , } ) ) ; } }