-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
28 lines (25 loc) · 804 Bytes
/
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
const news = require("./news.json");
const categories = require("./categories.json");
const content = require("./content.json");
const items = require("./items.json");
const { nanoid } = require("nanoid");
const filterNonUnique = (array, property) =>
array.filter(
(value, index, self) =>
self.findIndex((item) => item[property] === value[property]) === index
);
module.exports = () => {
const data = {
news: news.news.map((item) => ({
...item,
views: Math.floor(Math.random() * 10000),
content: content.content,
})),
categories: filterNonUnique(
news.news.reduce((acc, current) => [...acc, ...current.categories], []),
"contentId"
).slice(1),
options: items.data.map((item) => ({ id: nanoid(), label: item })),
};
return data;
};