Product id is required

This commit is contained in:
Kiran K 2023-11-20 10:53:30 +05:30
parent cf9a051085
commit 7cae8439eb
1 changed files with 13 additions and 2 deletions

View File

@ -23,9 +23,20 @@ export class ProductController {
return product;
}
public async upsert(product: Product) {
public async upsert(params: Partial<Product> & { id: string }) {
await throwIfInvalidLicense(this.opts.boxyhqLicenseKey);
await this.productStore.put(product.id, { ...product });
if (!('id' in params)) {
throw new JacksonError('Provide a product id', 400);
}
const product = (await this.productStore.get(params.id)) as Product;
if (!product) {
await this.productStore.put(params.id, { ...params });
return;
}
await this.productStore.put(product.id, { ...product, ...params });
}
}