Add mass edit of visible, browsable and blacklisting (#86)

* Add massedit WIP

* Add massedit

* Review comments

* Remove more debug
This commit is contained in:
Niklas Fondberg
2021-12-03 11:48:10 +01:00
committed by GitHub
parent 8096e4730c
commit 8cea3b5db6
3 changed files with 80 additions and 0 deletions
+33
View File
@@ -463,6 +463,39 @@ export class ProductAPI extends BaseSQLDataSource {
return Promise.all(promises);
}
/**
* @function massUpdatePublishing
* @description Mass update visible and browsable
*/
async massUpdatePublishing(
productIds: Array<number>,
visible: boolean,
browsable: boolean,
) {
return this.knex
.table('product-products')
.update({
browsable: browsable ? 1 : 0,
visible: visible ? 1 : 0,
})
.whereIn('productid', productIds);
}
/**
* @function massUpdateBlacklisting
* @description Mass update blacklisting
*/
async massUpdateBlacklisting(
productIds: Array<number>,
markets: Array<ProductBlacklistMarketInput>,
) {
const promises = productIds.map((pId) =>
this.updateBlacklisting(pId, markets),
);
return Promise.all(promises);
}
/**
* @function updateFocusPoint
* @description Updates the focus point on a motif
+37
View File
@@ -416,4 +416,41 @@ export const productMutationTypeDefs = {
);
return (<ProductAPI>dataSources.productApi).getProduct(productId);
},
/**
* @function massUpdatePublishing
* @description Mutate the publishing for products
*/
async massUpdatePublishing(
_,
{ productIds, visible, browsable },
{ dataSources, auth },
) {
checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).massUpdatePublishing(
productIds,
visible,
browsable,
);
return {
value: 'OK',
};
},
/**
* @function massUpdateBlacklisting
* @description Mutate the blacklisting for products
*/
async massUpdateBlacklisting(
_,
{ productIds, markets },
{ dataSources, auth },
) {
checkAccess(['products.write'], auth);
await (<ProductAPI>dataSources.productApi).massUpdateBlacklisting(
productIds,
markets,
);
return {
value: 'OK',
};
},
};
+10
View File
@@ -518,4 +518,14 @@ type Mutation {
removeCategoriesFromProduct(productId: Int!, categoryIds: [Int]!): Product
updateProductComments(productId: Int!, comments: String!): Product
massUpdatePublishing(
productIds: [Int]!
visible: Boolean
browsable: Boolean
): StringResult
massUpdateBlacklisting(
productIds: [Int]!
markets: [ProductBlacklistingInput]
): StringResult
}