forked from programared2023/ProgramaRed-Back
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (65 loc) · 2.01 KB
/
index.js
File metadata and controls
71 lines (65 loc) · 2.01 KB
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
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |
// | \_| ''\---/'' |_/ |
// \ .-\__ '-' ___/-. /
// ___'. .' /--.--\ `. .'___
// ."" '< `.___\_<|>_/___.' >' "".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `_. \_ __\ /__ _/ .-` / /
// =====`-.____`.___ \_____/___.-`___.-'=====
// `=---='
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const server = require('./src/app.js');
const { conn } = require('./src/db.js');
const { users, posts, randomDates } = require('./dumbdata.js')
const port = process.env.PORT || 3001;
function createUsers() {
users.map(async u => {
await conn.model('User').create({
username: u.username,
email: u.email,
password: u.password
})
// console.log(user.toJSON());
})
}
function createPosts() {
posts.map(async p => {
let rand = new Promise((resolve) => resolve(Math.floor(Math.random() * 10)))
let post = await conn.model('Post').create({
title: p.title,
description: p.description,
file: p.file,
UserId: p.userId,
publishDate: new Date(randomDates[await rand])
})
p.tags.map(async t => {
const [tag, _] = await conn.model('Tag').findOrCreate({
name: t.name,
where: {
name: t.name
}
})
// console.log(tag.toJSON());
post.addTag(tag)
})
// console.log(post.toJSON());
})
}
// Syncing all the models at once.
conn.sync({ force: false }).then(async () => {
console.log('db connected')
//createUsers()
//createPosts()
server.listen(port, () => {
console.log(`server listening at ${port}`); // eslint-disable-line no-console
});
});