-
Notifications
You must be signed in to change notification settings - Fork 487
/
product-variant.create.handler.ts
45 lines (37 loc) · 1.63 KB
/
product-variant.create.handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { ICommandHandler, CommandHandler } from '@nestjs/cqrs';
import { ProductVariant } from '../../product-variant.entity';
import { ProductVariantCreateCommand } from '../product-variant.create.command';
import { ProductVariantService } from '../../product-variant.service';
import { ProductVariantPriceService } from '../../../product-variant-price/product-variant-price.service';
import { ProductVariantSettingService } from '../../../product-settings/product-settings.service';
@CommandHandler(ProductVariantCreateCommand)
export class ProductVariantCreateHandler
implements ICommandHandler<ProductVariantCreateCommand> {
constructor(
private productVariantService: ProductVariantService,
private productVariantPriceService: ProductVariantPriceService,
private productVariantSettingsService: ProductVariantSettingService
) {}
public async execute(
command?: ProductVariantCreateCommand
): Promise<ProductVariant[]> {
const { productInput } = command;
const arrVariants = [];
for await (const productOption of productInput.options) {
const newProductVariant = new ProductVariant();
//tstodo
newProductVariant.billingInvoicingPolicy = 'policy';
newProductVariant.internalReference =
productOption.name + productOption.code;
newProductVariant.settings = await this.productVariantSettingsService.createDefaultVariantSettings();
newProductVariant.price = await this.productVariantPriceService.createDefaultProductVariantPrice();
newProductVariant.product = productInput;
arrVariants.push(
await this.productVariantService.createVariant(
newProductVariant
)
);
}
return arrVariants;
}
}