-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (55 loc) · 1.67 KB
/
index.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
const express = require('express');
const db = require("./models");
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.send('Hello World 2!');
})
app.get('/getSample', async (req, res) => {
const lastSample = await db.Main.findOne({
order: [ [ 'createdAt', 'DESC' ]],
raw: true,
});
console.log(`latest id ${lastSample.id}`);
res.send(lastSample);
});
app.get('/createSample', async (req, res) => {
const sampleMains = await db.Main.create({ name: "sample test"});
res.send(sampleMains.dataValues);
});
app.get('/fillDatabase', async (req, res) => {
var qtdSamples = parseInt(req.query.qtdSamples, 10);
const latestSample = await db.Main.findOne({
order: [ [ 'createdAt', 'DESC' ]],
raw: true,
});
let sampleMain = latestSample == null ? 0 : latestSample.id;
for (let sample = 1; sample < qtdSamples + 1; sample++) {
try{
sampleMain = await db.Main.create({ name: `sample ${sample}`});
console.log(sampleMain.dataValues);
}catch(err){
console.log(err);
}
}
res.send(sampleMain.dataValues);
});
app.post('/eval', async (req, res) => {
/*
THIS IS NOT RECOMENDED FOR PRODUCTION.
THE GOAL HERE IS MAINLY FOR TESTING PURPOSES.
*/
console.log(req.body)
const result = await eval(req.body.query);
res.json({ status: "running" });
});
db.sequelize.sync({ force: false }).then(function () {
app.listen(process.env.DB_PORT, function () {
console.log("server is successfully running!");
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
})