Y
Y
yanis_kondakov2018-02-01 09:16:31
Database
yanis_kondakov, 2018-02-01 09:16:31

How to work with cookies and database at the same time?

Good day.
Suppose the database stores tasks with a due date. You need to somehow (no matter how) mark these tasks in the database when the deadline has passed, i.e. when the task is overdue.
Without a database, I just did this (if this is not possible, then correct)

componentWillMount() {
  setInterval(() => {
    const newTodos = this.markExpiredTodos();
    bake_cookie('todos', newTodos); // переписываем cookies
  }, 10000);
}
markExpiredTodos() {
  const allTodos = read_cookie('todos'); // получаем текущие данные из cookies
  allTodos.forEach((todo) => {
    // проверяем сроки и помечаем
  });
  return allTodos;
}

Now there are databases and APIs.
componentWillMount() {
  this.props.fetchTodos();
  this.interval = setInterval(() => {
    const newTodos = this.markExpiredTodos();
    this.props.saveTodos(newTodos); // отправляем запрос к БД вместо работы с cookies
  }, 10000);
}

How to do it better? Also work with cookies and set another setInterval to send a request to the database or make queries to the database right away? And can generally work with time on the server? Or is there some other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-02-03
@yanis_kondakov

You are approaching the problem from the wrong side.
Write to the database timestamp deadLineDate , by the date of creation and determine the status.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question