AddProduct mutation (#59)
This commit is contained in:
Generated
+11
@@ -27,6 +27,7 @@
|
|||||||
"pg": "^8.7.1",
|
"pg": "^8.7.1",
|
||||||
"pg-hstore": "^2.3.4",
|
"pg-hstore": "^2.3.4",
|
||||||
"prettier": "^2.3.2",
|
"prettier": "^2.3.2",
|
||||||
|
"slug": "^5.1.0",
|
||||||
"stringcase": "^4.3.1",
|
"stringcase": "^4.3.1",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"typescript": "^4.4.2",
|
"typescript": "^4.4.2",
|
||||||
@@ -11616,6 +11617,11 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/slug": {
|
||||||
|
"version": "5.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/slug/-/slug-5.1.0.tgz",
|
||||||
|
"integrity": "sha512-IS39jKR6m+puU8zWgH6ruwx1sfzFNJ6Ai5PKIlUqd0X8C3ca7PB49Cvm0uayqgEt1jgaojO2wWEsQJngnh7fDA=="
|
||||||
|
},
|
||||||
"node_modules/snapdragon": {
|
"node_modules/snapdragon": {
|
||||||
"version": "0.8.2",
|
"version": "0.8.2",
|
||||||
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
|
||||||
@@ -22648,6 +22654,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"slug": {
|
||||||
|
"version": "5.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/slug/-/slug-5.1.0.tgz",
|
||||||
|
"integrity": "sha512-IS39jKR6m+puU8zWgH6ruwx1sfzFNJ6Ai5PKIlUqd0X8C3ca7PB49Cvm0uayqgEt1jgaojO2wWEsQJngnh7fDA=="
|
||||||
|
},
|
||||||
"snapdragon": {
|
"snapdragon": {
|
||||||
"version": "0.8.2",
|
"version": "0.8.2",
|
||||||
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"pg": "^8.7.1",
|
"pg": "^8.7.1",
|
||||||
"pg-hstore": "^2.3.4",
|
"pg-hstore": "^2.3.4",
|
||||||
"prettier": "^2.3.2",
|
"prettier": "^2.3.2",
|
||||||
|
"slug": "^5.1.0",
|
||||||
"stringcase": "^4.3.1",
|
"stringcase": "^4.3.1",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"typescript": "^4.4.2",
|
"typescript": "^4.4.2",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { BaseSQLDataSource } from './BaseSQLDataSource';
|
import { BaseSQLDataSource } from './BaseSQLDataSource';
|
||||||
import { camelcase } from 'stringcase';
|
import { camelcase } from 'stringcase';
|
||||||
|
import slug from 'slug';
|
||||||
import * as sql from './sql';
|
import * as sql from './sql';
|
||||||
import {
|
import {
|
||||||
Product,
|
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(
|
async updateProductInfo(
|
||||||
productId: number,
|
productId: number,
|
||||||
info: ProductInfoInput,
|
info: ProductInfoInput,
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ export const productQueryTypeDefs = {
|
|||||||
///////////////////
|
///////////////////
|
||||||
// Mutations below
|
// Mutations below
|
||||||
export const productMutationTypeDefs = {
|
export const productMutationTypeDefs = {
|
||||||
|
async addProduct(_, { name, batch }, { dataSources }) {
|
||||||
|
const id = await (<ProductAPI>dataSources.productApi).addProduct(
|
||||||
|
name,
|
||||||
|
batch,
|
||||||
|
);
|
||||||
|
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||||
|
},
|
||||||
async productInfo(_, { productId, info }, { dataSources }) {
|
async productInfo(_, { productId, info }, { dataSources }) {
|
||||||
await (<ProductAPI>dataSources.productApi).updateProductInfo(
|
await (<ProductAPI>dataSources.productApi).updateProductInfo(
|
||||||
productId,
|
productId,
|
||||||
|
|||||||
@@ -431,6 +431,7 @@ type IdNumberResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
|
addProduct(name: String!, batch: String): Product
|
||||||
productInfo(productId: Int!, info: ProductInfoInput!): Product
|
productInfo(productId: Int!, info: ProductInfoInput!): Product
|
||||||
productFocusPoint(
|
productFocusPoint(
|
||||||
productId: Int!
|
productId: Int!
|
||||||
|
|||||||
Reference in New Issue
Block a user