Add keyword mutation for product (#19)

This commit is contained in:
Niklas Fondberg
2021-09-03 09:51:49 +02:00
committed by GitHub
parent cb4a7c40b7
commit 596d21dce8
3 changed files with 33 additions and 9 deletions
+18 -8
View File
@@ -55,18 +55,28 @@ ORDER BY keywords.value
.then((row) => this.getType(row)); .then((row) => this.getType(row));
} }
/** async setProductKeywords(
* category keywords productId: number,
* keywordIds: Array<number>,
): Promise<any> {
await this.knex('product_keyword').where('product_id', productId).del();
const fieldsToInsert = keywordIds.map((keywordId) => ({
product_id: productId,
keyword_id: keywordId,
}));
return this.knex('product_keyword').insert(fieldsToInsert);
}
}
/*
category keywords:
SELECT category_keyword.category_id, keywords.value SELECT category_keyword.category_id, keywords.value
FROM category_keyword FROM category_keyword
JOIN keywords ON category_keyword.keyword_id = keywords.id; JOIN keywords ON category_keyword.keyword_id = keywords.id;
texts:
FROM categorydata cd FROM categorydata cd
JOIN categorydatakeys cdk ON cd.datakey_id = cdk.id JOIN categorydatakeys cdk ON cd.datakey_id = cdk.id
*
*/ */
}
+7
View File
@@ -94,4 +94,11 @@ export const productMutationTypeDefs = {
); );
return (<ProductAPI>dataSources.productApi).getProduct(productId); return (<ProductAPI>dataSources.productApi).getProduct(productId);
}, },
async productKeywords(_, { productId, keywordIds }, { dataSources }) {
await (<KeywordAPI>dataSources.keywordApi).setProductKeywords(
productId,
keywordIds,
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
}; };
+7
View File
@@ -289,9 +289,15 @@ enum Orientation {
enum ProductGroup { enum ProductGroup {
PHOTO_WALLPAPER PHOTO_WALLPAPER
CANVAS CANVAS
"""
WALLPAPER is tiling
"""
WALLPAPER WALLPAPER
OLD_REMOVED OLD_REMOVED
DO_IT_YOURSELF_FRAME DO_IT_YOURSELF_FRAME
"""
Not used
"""
DESIGNER_WALLPAPER DESIGNER_WALLPAPER
POSTER POSTER
FRAMED_PRINT FRAMED_PRINT
@@ -396,4 +402,5 @@ type Mutation {
productId: Int! productId: Int!
markets: [ProductBlacklistingInput] markets: [ProductBlacklistingInput]
): Product ): Product
productKeywords(productId: Int!, keywordIds: [Int]): Product
} }