-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialDatabase.js
55 lines (50 loc) · 1.87 KB
/
initialDatabase.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
const Tool = require('./models/tool')
const User = require('./models/user')
const { generatePassHash } = require('./utils/auth')
const { INITIALUSER, INITIALUSERPASS } = process.env
const initialTools = async () => {
const results = await Tool.find({})
if (results.length === 0) {
Tool.insertMany([
{
title: "Notion",
link: "https://notion.so",
description: "All in one tool to organize teams and ideas. Write, plan, collaborate, and get organized. ",
tags: ["organization", "planning", "collaboration", "writing", "calendar"]
},
{
title: "json-server",
link: "https://github.com/typicode/jsonserver",
description: "Fake REST API based on a json schema. Useful for mocking and creating APIs for front-end devs to consume in coding challenges.",
tags: ["api", "json", "schema", "node", "github", "rest"]
},
{
title: "fastify",
link: "https://www.fastify.io/",
description: "Extremely fast and simple, low-overhead web framework for NodeJS. Supports HTTP2.",
tags: ["web", "framework", "node", "http2", "https", "localhost"]
}
])
}
}
const initialUser = async () => {
const results = await User.countDocuments({})
if (results === 0) {
const adminUser = new User({
username: INITIALUSER,
password: generatePassHash(INITIALUSERPASS),
roles: ['restrito', 'admin']
})
await adminUser.save()
const restritoUser = new User({
username: 'restrito',
password: generatePassHash('restrito'),
roles: ['restrito']
})
await restritoUser.save()
}
}
module.exports = {
initialTools,
initialUser
}