Add mass edit of visible, browsable and blacklisting (#86)
* Add massedit WIP * Add massedit * Review comments * Remove more debug
This commit is contained in:
@@ -463,6 +463,39 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
return Promise.all(promises);
|
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
|
* @function updateFocusPoint
|
||||||
* @description Updates the focus point on a motif
|
* @description Updates the focus point on a motif
|
||||||
|
|||||||
@@ -416,4 +416,41 @@ export const productMutationTypeDefs = {
|
|||||||
);
|
);
|
||||||
return (<ProductAPI>dataSources.productApi).getProduct(productId);
|
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',
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -518,4 +518,14 @@ type Mutation {
|
|||||||
removeCategoriesFromProduct(productId: Int!, categoryIds: [Int]!): Product
|
removeCategoriesFromProduct(productId: Int!, categoryIds: [Int]!): Product
|
||||||
|
|
||||||
updateProductComments(productId: Int!, comments: String!): Product
|
updateProductComments(productId: Int!, comments: String!): Product
|
||||||
|
|
||||||
|
massUpdatePublishing(
|
||||||
|
productIds: [Int]!
|
||||||
|
visible: Boolean
|
||||||
|
browsable: Boolean
|
||||||
|
): StringResult
|
||||||
|
massUpdateBlacklisting(
|
||||||
|
productIds: [Int]!
|
||||||
|
markets: [ProductBlacklistingInput]
|
||||||
|
): StringResult
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user