Merge pull request #46 from Photowall/148-add-mutations-for-categories
This commit is contained in:
@@ -621,4 +621,32 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
promises.push(query);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
async addCategoriesToProduct(
|
||||
productId,
|
||||
categoryIds,
|
||||
): Promise<Promise<void>[]> {
|
||||
const promises = categoryIds.map((categoryId) =>
|
||||
this.knex('product_category').insert({
|
||||
product_id: productId,
|
||||
category_id: categoryId,
|
||||
}),
|
||||
);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
async removeCategoriesFromProduct(
|
||||
productId,
|
||||
categoryIds,
|
||||
): Promise<Promise<void>[]> {
|
||||
const promises = categoryIds.map((categoryId) =>
|
||||
this.knex('product_category')
|
||||
.where({
|
||||
product_id: productId,
|
||||
category_id: categoryId,
|
||||
})
|
||||
.del(),
|
||||
);
|
||||
return Promise.all(promises);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user