AddProduct mutation (#59)

This commit is contained in:
Niklas Fondberg
2021-10-05 10:03:13 +02:00
committed by GitHub
parent 4e55166828
commit 491ac6e64e
5 changed files with 38 additions and 0 deletions
+18
View File
@@ -1,5 +1,6 @@
import { BaseSQLDataSource } from './BaseSQLDataSource';
import { camelcase } from 'stringcase';
import slug from 'slug';
import * as sql from './sql';
import {
Product,
@@ -220,6 +221,23 @@ export class ProductAPI extends BaseSQLDataSource {
);
}
async addProduct(name: string, batch: string): Promise<number> {
const path = batch ? batch + ' ' + name : name;
const idres = await this.knex
.table('product-products')
.insert({
path: slug(path),
browsable: 0,
visible: 0,
})
.returning('productid');
const id = idres[0];
this.updateProductField(id, 'artNo', `e${id}`);
await this.updateProductField(id, 'name', name);
await this.updateProductField(id, 'batch', batch);
return id;
}
async updateProductInfo(
productId: number,
info: ProductInfoInput,