I want to upload some files, add them to a database and return the ids of the new objects.
fn: async function (inputs) {
  let docIds = []
  let settings = {...}
  await inputs.filesToUpload.upload(settings, async (err, files) => {
    if (err)
        throw {'invalid': 'The provided data is invalid.'}
    for (let i = 0; i < files.length; i += 1) {
        let newDocument = await Document.create({
          name: file.filename
        }).fetch()
        docIds.push(newDocument.id)
    }
  })
  return {
    ids: docIds
  }
})
Unfortunately, the controller doesn't wait for the objects to be created in the database and returns {ids: []} immediately, only then the documents are uploaded and objects created. I have tried using passing the ids as a callback and promise but the controller always executes return without waiting for the results.
 
     
    