function does not return .then

On a single page on my site, there is a bit of math that is performed often. I thought the logical thing to do was to create a function to run this math to save an extraordinary amount of lines. All of this math appears in another function, so I decided to call a function within a function.

This is the code calling the function within an async function.
(I’ve tried both separately in an ‘await’ and within the promise of the “.get”)

  await wixData.get("Fleet", flight1.aircraft)
    .then((r) =>{
      aircraft1 = r;
      capacityArrayMaker(aircraft1, flight1)
        .then((test) => {
          console.log(test);
        });
    });

Here is a small snippet of the function, the whole thing is much larger and repetitive.

function capacityArrayMaker(fleet, aircraft) {
  let itemArray = new Object();
  var tempV;
  var tempW;
  itemArray = {property: "then"}
  //p1
  tempV = +fleet.p1V - +aircraft.p1V;
  tempW = +fleet.p1W - +aircraft.p1W;
  itemArray[1] = {volume: tempV, weigt: tempW};

  return itemArray;
  
}

The Issue: the ‘.then’ says the following message
“property ‘then’ does not exist on type ‘Object’” so I change the object to an array and I get “property ‘then’ does not exist on type ‘any[]’”.

The desired outcome: I’d like to call the function processing math and it return an array with all the results.

Any ideas? I’m sure it’s due to my lack of know in functions and syntax.

I should clarify, the

itemArray = {property: "then"}

was an attempt to “fix” the issue. Not needed as part of the code.

But the capacityArrayMaker function is not a Promise so it should NOT have the then() method.

Also you’re mixing await and .then() for the query.find() and you should not.

Thanks for the response.

Is there a tutorial or something for making a function a promise? Or what is the best way to return the Array/Object to the original function.

Also, there are multiple query.find() within the first function and the others need this to finish before proceeding, so is it still used incorrectly in that scenario?

@michael64893 You can find plenty of tutorials and explanations for JavaScript Promises on the web.
The .find() method is a Promise, an what you can do is either:

function x(){
    return query1()
    .then(res => {
        //some code with the res
        return query2()
    })
    .then(res => {
        //some code with the res
        return query3()
    })
    .catch(err => err);
}

Alternatively

async function x(){
    const res1 = await query1();
    //some code with res1
    const res2 = await query2();
    //some code with the res2
    return query3()
}

(but with the first option it’s easier to catch errors)

Here are some articles: