Skip to content

Instantly share code, notes, and snippets.

@eabald
Created April 24, 2022 20:03
beforeOperation: async ({ resolvedData, item, context }) => {
if (resolvedData?.products) {
const dbItems = await context.query.Cart.findOne({
where: { id: item ? (item.id as string) : '' },
query: 'products { id }',
});
if (dbItems.products.length) {
await context.query.CartProduct.deleteMany({
where: dbItems.products.map((el: { id: string }) => ({
id: el.id,
})),
});
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment