How to make transaction with for loops

Hello, i'm learning neo4j and i have a problem for a school project

  1. can someone explain me how to make multiples transactions with for loop?
  2. how to handle .then and .catch (duplicate constraint on neo4j applied ) ?
  3. is it a good example to use Promise.all ?


This is a portion of my code but there is an error :
(node:3622) UnhandledPromiseRejectionWarning: Neo4jError: The transaction has been terminated. Retry your operation in a new transaction,

const createMultiplesCategories=(req,res)=>{
const {allMenus}=req.body
allMenus.forEach(menu => {
const session = driver.session()
const {name,color}=menu
session.writeTransaction(transaction=> {
return (n:CATEGORY{ name:'${name}', color: '${color}' }));

the request JSON(BODY)

{"name":"VEGETARIAN DISHES","color":"bg-light-red"},
{"name":"ICE CRAM","color":"bg-light-green"},