I'm writing an endpoint which modifies caption in a firebase entry; then collects all Typesense entries related to the firebase entry and fixes them too.
My code works exactly as I'd want it to. But I ended up going one level deeper with the .then() nesting than I would have liked to, resulting in 2 .catch() statements instead of one.
It somehow feels this is formally wrong and I'd love to fix it, but I don't know how to get myself "out" of it.
db.collection('posts').doc(post.id)
  .update({
    caption: post.caption
  })
  .then((data) => {
    // tsense collect all with fireId
    let searchParameters = {
      q: '*',
      filter_by: `fireId:=${post.id}`
    }
    TsenseClient.collections(Collection).documents().search(searchParameters)
      .then((data) => {
        console.log(data);
        return data
      })
      .then((tsenses) => {
        // tsense update all with fireId
        let tsenseUpdates = []
        tsenses.hits.forEach((hit) => {
          let doc = {
            "caption": post.caption
          }
          tsenseUpdates.push(TsenseClient.collections(Collection).documents(hit.id).search(searchParameters))
        })
        return Promise.allSettled(tsenseUpdates)
      })
      .then((tsenseUpdates) => {
        response.send('Update done.')
      })
      .catch((err) => {
        console.log(err);
      })
  })
  .catch((err) => {
    console.log(err);
  })
 
     
     
     
    