-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-db.js
123 lines (105 loc) · 2.94 KB
/
api-db.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* eslint-disable */
// API docs: https://indigoapp.restlet.io/
const faker = require('faker');
const fs = require('fs');
// TODO: Improve performances in the app bcz if usersNb / commentsNb increase
// it becomes a nightmare
const usersNb = 50;
const friendsNb = 30;
const commentsNb = 30;
const maxRepliesNb = 20;
const chatroomsNb = 5;
const generateUser = (id) => ({
id,
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
avatar: faker.image.avatar(),
description: faker.lorem.words()
})
const usersBase = [...Array(usersNb)].map((e, id) => generateUser(id));
const users = usersBase.map((user, id) =>
Object.assign({}, user, {
seen: [...Array(Math.floor(Math.random() * friendsNb))].map(() =>
usersBase[Math.floor(Math.random() * usersNb)]
)
})
);
const comments = [...Array(commentsNb)].map((e, id) => {
const author = users[Math.floor(Math.random() * usersNb)];
return (
{
id,
userId: Math.floor(Math.random() * usersNb),
description: faker.lorem.sentences(),
coordinate: {
latitude: 48.8245 + (Math.random() - 0.5) * 0.01,
longitude: 2.2798 + (Math.random() - 0.5) * 0.01,
latitudeDelta: 0.005,
longitudeDelta: 0.005
},
liked: false
}
);
});
const replies = comments
.map(comment =>
[...Array(Math.floor(Math.random() * maxRepliesNb)) + 3].map(() => {
const replier = users[Math.floor(Math.random() * usersNb)];
return ({
id: faker.random.uuid(),
user: replier,
description: faker.lorem.sentences(),
liked: false,
commentId: comment.id
});
})
)
.reduce((prev, next) => [...prev, ...next], []);
const chatrooms = [...Array(chatroomsNb)].map(() => {
const chatUsers = users.filter(() => faker.random.boolean());
return {
id: faker.random.uuid(),
name: faker.company.companyName(),
description: faker.lorem.words(),
users: chatUsers,
color: faker.internet.color(),
coordinate: {
latitude: 48.8245 + (Math.random() - 0.5) * 0.01,
longitude: 2.2798 + (Math.random() - 0.5) * 0.01,
latitudeDelta: 0.005,
longitudeDelta: 0.005
}
}
});
// User management
const userToken = { token: 'mKfeazoJjfezafoJfhezifuhJ' };
const checkUserToken = { status: 'OK' };
const getCurrentUser = {
id: 'currentUserId',
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
avatar: faker.image.avatar(),
description: faker.lorem.words(),
seen: [...Array(Math.floor(Math.random() * friendsNb))].map(() =>
usersBase[Math.floor(Math.random() * usersNb)]
)
};
// TODO: Remove when create user form will be OK
users.push(getCurrentUser);
const currentUserPicture = {
avatar: faker.image.avatar()
};
const db = {
users,
comments,
replies,
chatrooms,
userToken,
checkUserToken,
getCurrentUser,
currentUserPicture
};
module.exports = function() {
return db;
}
// fs.writeFile("./db.json", JSON.stringify(db));