A
A
Artem2018-12-09 23:08:30
JavaScript
Artem, 2018-12-09 23:08:30

How to implement visual filter/algorithm constructor?

The task is to make a promotion constructor on the site.
The administrator can add several conditions, for example:
"If the following products are in the cart:", "If the purchase amount", "more", "less", etc.
As an example, I will give the rules for processing letters in Yandex.Mail:
5c0d757e75e23064276111.png
If everything is clear with the frontend, then how to store these conditions in the database, and, most importantly, "run" them?
How to convert "If the following products are in the cart: (Item 1 AND Item2) OR (Item 3 AND Item 4)" to a code?
What is the name of such "constructors"? I couldn't find anything similar in Google.
On the backend - Node.js.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2018-12-10
@ber_enot

I'll put in my 5 kopecks, since at the moment I'm working on about this. My solution is:
Store this filter as a formalized set of rules for query building. Something like

[
    'OR'
    ['like', 'from', '%example%'],
    ['=', 'theme', 'hello'],
    ['like', 'body', 'world']
]

Then I “feed” this array into a ConditionDispatcher object, which, depending on the type of the “provider” (consumer) specified in it, converts this set of rules either into a where-section of a MySQL query, or into a query in MongoDb, or into the code of a function that performs filtering on browser side (javascript).

A
Alexander Taratin, 2018-12-10
@Taraflex

Generate an sql query at once and store it as a string. If there are not very many such requests, you can use not a query string, but create a stored procedure in the database.
Boolean conditions are trivially converted to sql.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question