Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #841/update product and variants
- Loading branch information
1 parent
ff9bf28
commit b2fb817
Showing
25 changed files
with
368 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
apps/api/src/app/product/commands/handlers/product.update.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ICommandHandler, CommandHandler } from '@nestjs/cqrs'; | ||
import { ProductService } from '../../../product/product.service'; | ||
import { ProductOptionService } from '../../../product-option/product-option.service'; | ||
import { Product } from '../../product.entity'; | ||
import { ProductUpdateCommand } from '../product.update.command'; | ||
|
||
@CommandHandler(ProductUpdateCommand) | ||
export class ProductUpdateHandler | ||
implements ICommandHandler<ProductUpdateCommand> { | ||
constructor( | ||
private productOptionService: ProductOptionService, | ||
private productService: ProductService | ||
) {} | ||
|
||
public async execute(command?: ProductUpdateCommand): Promise<Product> { | ||
const { productUpdateRequest } = command; | ||
|
||
const product = await this.productService.saveProduct( | ||
productUpdateRequest | ||
); | ||
|
||
//todo manage options | ||
|
||
return product; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/api/src/app/product/commands/product.update.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ICommand } from '@nestjs/cqrs'; | ||
import { Product } from '../../product/product.entity'; | ||
|
||
export class ProductUpdateCommand implements ICommand { | ||
static readonly type = '[Product] Update'; | ||
|
||
constructor( | ||
public readonly id: string, | ||
public readonly productUpdateRequest: Product | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/gauzy/src/app/@core/services/product-variant-price.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { ProductVariantPrice } from '@gauzy/models'; | ||
import { first } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class ProductVariantPriceService { | ||
PRODUCT_VARIANT_PRICE_URL = '/api/product-variant-prices'; | ||
|
||
constructor(private http: HttpClient) {} | ||
|
||
updateProductVariantPrice( | ||
productVariantPrice: ProductVariantPrice | ||
): Promise<ProductVariantPrice> { | ||
return this.http | ||
.put<ProductVariantPrice>( | ||
`${this.PRODUCT_VARIANT_PRICE_URL}/${productVariantPrice.id}`, | ||
productVariantPrice | ||
) | ||
.pipe(first()) | ||
.toPromise(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/gauzy/src/app/@core/services/product-variant-settings.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { ProductVariantSettings } from '@gauzy/models'; | ||
import { first } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class ProductVariantSettingsService { | ||
PRODUCT_VARIANT_SETTINGS_URL = '/api/product-variant-settings'; | ||
|
||
constructor(private http: HttpClient) {} | ||
|
||
updateProductVariantSettings( | ||
productVariantSettings: ProductVariantSettings | ||
): Promise<ProductVariantSettings> { | ||
return this.http | ||
.put<ProductVariantSettings>( | ||
`${this.PRODUCT_VARIANT_SETTINGS_URL}/${productVariantSettings.id}`, | ||
productVariantSettings | ||
) | ||
.pipe(first()) | ||
.toPromise(); | ||
} | ||
|
||
getProductVariantSettings(): Promise<ProductVariantSettings[]> { | ||
return this.http | ||
.get<ProductVariantSettings[]>(this.PRODUCT_VARIANT_SETTINGS_URL) | ||
.pipe(first()) | ||
.toPromise(); | ||
} | ||
} |
Oops, something went wrong.