R
R
ragnar_ok2019-08-06 17:14:13
MySQL
ragnar_ok, 2019-08-06 17:14:13

How to save user answers to open questions of the questionnaire (not prepared in advance)?

I am designing a MySQL database for storing questionnaires and user responses to the questions of these questionnaires. Based on the data from the database, JSON is formed. We develop REST API.
The user fills in the data ( name, email, position, tel...) and thus receives user.id. Then he answers the questions (table question) of the questionnaires (table survey). As a result, the user's responses are stored in the table answer.
The user's response can be pre-prepared in a table options. Or maybe not prepared. Therefore, in addition to the table answer_optionsthat contains the user-selected answers (many-to-many), the table answercontains the fields:
- text(the answer to the question as text),
-num(answer to the question as a number),
- yn(answer to the question as a boolean).
The table input_typescontains the type of the form element (for example, <input type="text"/>.
The table insert_typescontains the field name in the table answer( yn, text, numor options).
The API outputs the question like this:

{
    "id": 1,
    "label": "Годовой оборот компании?",
    "placeholder": "Введите число",
    "required": true,
    "input_type": {
      "name": "text"
    },
    "insert_type": {
      "name": "num"
    }
  }

The front looks insert_typeand can send such a response object to the question:
{
        "user": 1,
        "question": 1,
        "num": 100
    }

The API reads the object and stores it in a table answer(the property is numstored in answer.num)
I don't like the fact that the front has to look at insert_type. How is it customary to save user responses to open questions of the questionnaire (not prepared in advance)?
5d498b3422c39783121428.png

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