Add keyword mutation for product (#19)
This commit is contained in:
@@ -55,18 +55,28 @@ ORDER BY keywords.value
|
||||
.then((row) => this.getType(row));
|
||||
}
|
||||
|
||||
/**
|
||||
* category keywords
|
||||
*
|
||||
async setProductKeywords(
|
||||
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
|
||||
FROM category_keyword
|
||||
JOIN keywords ON category_keyword.keyword_id = keywords.id;
|
||||
|
||||
|
||||
texts:
|
||||
FROM categorydata cd
|
||||
JOIN categorydatakeys cdk ON cd.datakey_id = cdk.id
|
||||
|
||||
|
||||
*
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -94,4 +94,11 @@ export const productMutationTypeDefs = {
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
async productKeywords(_, { productId, keywordIds }, { dataSources }) {
|
||||
await (<KeywordAPI>dataSources.keywordApi).setProductKeywords(
|
||||
productId,
|
||||
keywordIds,
|
||||
);
|
||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -289,9 +289,15 @@ enum Orientation {
|
||||
enum ProductGroup {
|
||||
PHOTO_WALLPAPER
|
||||
CANVAS
|
||||
"""
|
||||
WALLPAPER is tiling
|
||||
"""
|
||||
WALLPAPER
|
||||
OLD_REMOVED
|
||||
DO_IT_YOURSELF_FRAME
|
||||
"""
|
||||
Not used
|
||||
"""
|
||||
DESIGNER_WALLPAPER
|
||||
POSTER
|
||||
FRAMED_PRINT
|
||||
@@ -396,4 +402,5 @@ type Mutation {
|
||||
productId: Int!
|
||||
markets: [ProductBlacklistingInput]
|
||||
): Product
|
||||
productKeywords(productId: Int!, keywordIds: [Int]): Product
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user