Blame view

mock/chatMessage.js 776 Bytes
93a68cfa1   Jatinder Singh   first commit
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
  const Faker = require('faker');
  const Fs = require('fs');
  const range = (start, end) => new Array(end - start).fill(start).map((el, i) => start + i);
  const randomInt  = (max) => Math.floor(Math.random() * max) + 1;
  // chats
  const chats = JSON.parse(Fs.readFileSync('./static/data/chat.json', 'UTF-8'));
  const chatIds = [];
  const messages = [];
  chats.forEach((item) => {
    item.users.forEach((userId) => {
      range(0, randomInt(4)).forEach(() => {
        messages.push(
          {
            'uuid': Faker.random.uuid(),
            'chatId': item.uuid,
            'text': Faker.lorem.sentence(),
            'userId': userId,
            'created_at': Faker.date.recent(),
          }
        );
      });
    });
  
  });
  // users
  
  
  module.exports = () => {
    return {
      data: messages
    };
  };