N
N
Nikita Kostrov2019-02-25 14:48:01
Mongoose
Nikita Kostrov, 2019-02-25 14:48:01

How to stop the script if the data from Mongoose came empty?

Good day!
Let me get straight to the question:
This script in the photo receives transactions from the database, and if they exist, it returns an error.
However, the work of the entire script does not stop. How can I make sure that the script below this interaction does not work?
I don't need to do any further work if there is an error. In my case, it will return an error and continue to execute the script. (headers error appears)
5c73d472c715a845335609.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Kostrov, 2019-02-25
@nkostrovsmm

Решил проблему следующим методом:
(async () => {
    const transaction = await GameController.isTransactionCompleted(req.body.transaction_id);

   if (transaction.length !== 0) return bla-bla-bla
});

async isTransactionCreated(transaction_id) => {
    let total_transactions;
    await GameModel.find({ transaction_id: transaction_id }, (error, transaction) => {Ваши извращения из Pomise можно записать в total_transactions и вернуть его же});
};

H
hzzzzl, 2019-02-25
@hzzzzl

if ... else?

if (!data) {
  // ничего нет
} else {
  // всё есть
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question