Prisma, findMany function sucks
Archived 2 years ago
C
cablemanagment.
Hello guys if i do the findmany function from prisma on my model i get the error: Unexpected end of JSON input. Code:
```const { PrismaClient } = require('@prisma/client');
const express = require('express');
const cors = require('cors');
const app = express();
var bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(cors());
const port = 3001;
const prisma = new PrismaClient()
async function upload(title, doxinfo, owner){
const status = await prisma.dox.create({
data: {
title: title,
doxinfo: doxinfo,
owner: owner
}
})
console.log(status)
}
async function doxes(){
const doxesdata = await prisma.dox.findMany()
return doxesdata
}
app.get('/', (req, res) => {
res.send('Hello, Express!');
});
app.post('/upload', (req, res) => {
const {title, doxinfo, owner} = req.body
try{
upload(title, doxinfo,owner)
}catch(e){
console.log(e)
}
res.send("Success")
})
app.get('/doxes', async (req, res) => {
try {
const doxesData = await doxes();
res.send(doxesData)
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
// Start the server
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});```
