hi there i’ll start and say im not a web developer so i dont know how to code. im using chat gpt and bard
i want that this code will get the list of item id's from a specific collection id from my databse
can please someone help me with the correct code?
the code im using now:
import * as ecomValidations from 'interfaces-ecommerce-v1-validations-provider';
export const getValidationViolations = async (options, context) => {
let violations = [];
const source = options.sourceInfo.source;
const severity = source === ecomValidations.Source.CART ? ecomValidations.Severity.ERROR : ecomValidations.Severity.ERROR;
const validItemIds = ['39791f1e-9d2d-bd67-24f3-d6e179ee0b6e', '0b91f1b3-221e-ae04-9cda-4dc9a33e8b33'];
const minimumTotalQuantity = 8;
const validLineItems = options.validationInfo.lineItems.filter(lineItem => validItemIds.includes(lineItem.catalogReference?.catalogItemId));
const validQuantitySum = validLineItems.reduce((partialSum, lineItem) => partialSum + lineItem.quantity, 0);
if (validQuantitySum < minimumTotalQuantity) {
violations.push({
severity,
target: { other: { name: ecomValidations.NameInOther.OTHER_DEFAULT } },
description: `You must purchase at least ${minimumTotalQuantity} items from the available selection.`,
});
}
return { violations };
};