From efab961a29f1973a5021410880ef5d0af428d20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arwid=20Thornstr=C3=B6m?= Date: Fri, 21 Feb 2025 10:24:40 +0100 Subject: [PATCH] added ref4 (#169) --- queries.graphql | 1 + src/datasources/product-api.ts | 5 +++-- src/datasources/sql/products-sql.ts | 3 ++- src/schema.graphql | 2 ++ src/types/product-types.ts | 2 ++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/queries.graphql b/queries.graphql index 08a2b6a..5957d1d 100644 --- a/queries.graphql +++ b/queries.graphql @@ -206,6 +206,7 @@ ref1 ref2 ref3 + ref4 wallpaperTypes keywords { id diff --git a/src/datasources/product-api.ts b/src/datasources/product-api.ts index e241766..152fb3e 100644 --- a/src/datasources/product-api.ts +++ b/src/datasources/product-api.ts @@ -350,10 +350,10 @@ export class ProductAPI extends BaseSQLDataSource { async searchByReferences(name: string): Promise> { ScopeAccess.validate(this.user).all([Scopes.PRODUCTS_READ]); - const query = sql.referenceProducts(); // ref1, ref2, ref3 + const query = sql.referenceProducts(); // ref1, ref2, ref3, ref4 return this.knex - .raw(query, [name, name, name]) + .raw(query, [name, name, name, name]) .then((data) => data.rows.map((row) => this.createProductFromRow(row))); } @@ -556,6 +556,7 @@ export class ProductAPI extends BaseSQLDataSource { ref1: info.ref1, ref2: info.ref2, ref3: info.ref3, + ref4: info.ref4, }) .where({ productid: productId }), this.updateProductField(productId, 'artNo', info.artNo), diff --git a/src/datasources/sql/products-sql.ts b/src/datasources/sql/products-sql.ts index 1a29950..40c0277 100644 --- a/src/datasources/sql/products-sql.ts +++ b/src/datasources/sql/products-sql.ts @@ -17,6 +17,7 @@ SELECT products.productid AS id, products.ref1, products.ref2, products.ref3, + products.ref4, ( SELECT json_agg( json_build_object( @@ -200,7 +201,7 @@ export function referenceProducts() { return ( baseQuery + /* sql */ ` - WHERE LOWER(products.ref1) LIKE ? OR LOWER(products.ref2) LIKE ? OR LOWER(products.ref3) LIKE ? ORDER BY products.inserted DESC` + WHERE LOWER(products.ref1) LIKE ? OR LOWER(products.ref2) LIKE ? OR LOWER(products.ref3) LIKE ? OR LOWER(products.ref4) LIKE ? ORDER BY products.inserted DESC` ); } diff --git a/src/schema.graphql b/src/schema.graphql index 4bf40c9..443c050 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -266,6 +266,7 @@ type Product { ref1: String ref2: String ref3: String + ref4: String related: [Product] wallpaperTypes: [ProductWallpaperType]! fields: ProductFields @@ -423,6 +424,7 @@ input ProductInfoInput { ref1: String! ref2: String! ref3: String! + ref4: String! designerId: Int browsable: Boolean! visible: Boolean! diff --git a/src/types/product-types.ts b/src/types/product-types.ts index cee4a0d..e6ced48 100644 --- a/src/types/product-types.ts +++ b/src/types/product-types.ts @@ -13,6 +13,7 @@ export interface ProductInfoInput { ref1: string; ref2: string; ref3: string; + ref4: string; designerId: Maybe; browsable: boolean; visible: boolean; @@ -145,6 +146,7 @@ export interface Product { ref1: string; ref2: string; ref3: string; + ref4: string; orientation?: Orientation; printProducts: [PrintProduct]; blacklisting: [ProductBlacklist];