V
V
vetsmen2019-09-25 15:14:00
JavaScript
vetsmen, 2019-09-25 15:14:00

What is the best way to organize the query structure?

Task: Get the user's balance, execute some logic and update the balance for this user (or rollback).
The structure is now like this: There is a class with custom logic and there is a class for working with database queries.
Question: Is it normal if I drag a transaction into custom logic like:

@Transaction()
    public async test(userId, userRepository) {
        await userRepository.findOne(userId);
        ... // some logic
        await userRepository.update(userId, ...);
    }

Where some logic is a rather voluminous piece of custom logic.
Or is it better for me to do it in a class with a database and transfer custom logic to it?
After all, I initially had the following project structure: all work with the database is in a separate class, and dragging a transaction into a class that is not intended for this seems to me somehow not right.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question