-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (61 loc) · 1.58 KB
/
index.js
File metadata and controls
79 lines (61 loc) · 1.58 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
72
73
74
75
76
77
78
79
import { PrismaClient } from "@prisma/client";
import express from "express";
import morgan from "morgan";
const PORT = process.env.PORT ?? 8080
const prisma = new PrismaClient()
const bootstrap = async () => {
const app = express()
app.use(morgan())
app.use(express.json())
app.route("/uploadData").post(async (req, res) => {
const { min, max, title, type, options, step } = req.body
try {
const schema = await prisma.schema.create({
data: {
...req.body
}
})
res.json({
schema
})
} catch (error) {
res.json({
error
})
}
})
app.get("/getData/:id", async (req, res) => {
const { id } = req.params
try {
if (!id) {
return res.json({
damn: 'fuck'
})
}
const schema = await prisma.schema.findUniqueOrThrow({
where: {
id: parseInt(id.toString())
}
})
res.json({
schema
})
} catch (error) {
console.log(error)
res.json({
error
})
}
})
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
})
}
await bootstrap().then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})