summaryrefslogtreecommitdiff
path: root/frontend/app/data/dataGenerator.js
blob: 1a171cfd8168fe09411cd79b3e12a52733e32e4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import _ from 'lodash';
import users from './raw/users';
import articles from './raw/articles';
import notifications from './raw/notifications';
import conversations from './raw/conversations';

const populateArticles = () => {
  articles.forEach(article => {
    const userArticle = article;
    const userId = articles.indexOf(article) % users.length;
    userArticle.user = _.find(users, x => x.id === userId) || users[0];
    userArticle.comments.map(comment => {
      const userComment = comment;
      const commentUserId = article.comments.indexOf(comment) % users.length;
      userComment.user = _.find(users, x => x.id === commentUserId) || users[0];
      return userComment;
    });
    return userArticle;
  });
};

const populateNotifications = () => {
  notifications.map(notification => {
    const userNotification = notification;
    const userId = notifications.indexOf(notification) % users.length;
    userNotification.user = _.find(users, x => x.id === userId) || users[0];
    return userNotification;
  });
};

const populateConversations = () => {
  conversations.map(conversation => {
    const userConversation = conversation;
    userConversation.withUser = _.find(users, x => x.id === conversation.withUserId) || users[0];
    return userConversation;
  });
};

const populate = () => {
  populateArticles();
  populateNotifications();
  populateConversations();
};

export default populate;