feat: add prisma

This commit is contained in:
Daniel Soares
2021-12-13 15:34:37 -03:00
parent c7dc121d9e
commit 8c37b851f3
12 changed files with 341 additions and 7 deletions

38
src/pages/api/data.ts Normal file
View File

@@ -0,0 +1,38 @@
import { NextApiRequest, NextApiResponse } from 'next'
import nc from 'next-connect'
import { prisma } from '../../services/prisma'
const { RAILWAY_TOKEN } = process.env
const handler = nc<NextApiRequest, NextApiResponse>()
.get(async (_req, res) => {
try {
const data = await prisma.data.findFirst()
res.status(200).json(data?.data)
} catch (error) {
console.error(error)
res.status(500).send('Internal server error')
}
})
.put(async (req, res) => {
try {
const response = await prisma.data.update({
where: {
id: 1
},
data: { data: JSON.stringify(req.body.data) }
})
if (RAILWAY_TOKEN) {
console.log('railway token', RAILWAY_TOKEN)
}
res.status(200).json(response)
} catch (error) {
console.error(error)
res.status(500).send('Internal server error')
}
})
export default handler