B
B
BogdanZots2021-10-15 20:51:04
Node.js
BogdanZots, 2021-10-15 20:51:04

How to write similar functionality in node js (express)?

It will be easiest for me to explain with a specific example.
User 1 came to the page and has a unique ID (which I take from Beck). User 1 wants to create a task , he creates it and sets id : 1 for it ( id is entered through input on the front side ) . The task gets into the database and it has: 1) its id 2) the id of the user who created it. User 2 visited the page, he also has a unique user id . User 2 wants to create a task with id : 1, but it will not work for him ( id for each task is unique : true) because there is already such a task with such an id, since there is already a task with id 1 from user 1 in the tasks table. That is, I need to somehow connect users and task IDs so that this task id is considered for each user separately, and not for two / three / many at once. Maybe I'm thinking in the wrong direction, how is this even solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-10-15
@BogdanZots

node.js and express have nothing to do with it, but what does it have to do with it - it's a database, and you didn't specify which database you are using.
In most databases that can unique, indexes are used for this, and indexes can be built not only on 1 field, but also on a group of fields. In your case, the unique index should consist of two fields - user_id and task_id, which will make them unique in pairs.
PS It seems to me not a good idea to let the user set the id himself, especially for those entities that the user can create more than one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question