Promise nesting problem, the next then uses the return value of the previous then.

  node.js, question

Promise Nested Writing of ES6 in nodejs
I intend to implement the following functions: insert the master record, return the insertId, and then insert the detail record

testObject.insertMain(code,name)
 .then((result)=>{
 var insertId = result.insertId;
 testObject.insertDetail(insertId,........)
 .then((result1)=>{
 testObject.func3(......)
 .then(..)
 .catch(..)
 })
 .catch(..)
 .catch(..)

This logic seems to have entered infinite nested logic again. Ask for advice on how to write correctly!

testObject.insertMain(code,name)
 .then((result)=>{
 var insertId = result.insertId;
 return insertId;
 })
 .then(function(insertId){
 return testObject.insertDetail(insertId);
 })
 .then(function(detail){
 console.log(detail);
 })
 .catch(..)