mirror of
https://github.com/dsoaress/link-free.git
synced 2026-08-17 15:06:06 +01:00
fix: some details
This commit is contained in:
@@ -1,32 +1,45 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import nc from 'next-connect'
|
||||
|
||||
import { prisma } from '../../services/prisma'
|
||||
|
||||
const handler = nc<NextApiRequest, NextApiResponse>()
|
||||
const handler = nc<NextApiRequest, NextApiResponse>({
|
||||
onNoMatch: (_req, res) => {
|
||||
res.status(404).json({ error: 'Not found' })
|
||||
},
|
||||
onError: (err, _req, res) => {
|
||||
res.status(500).json({ error: err.message })
|
||||
}
|
||||
})
|
||||
.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')
|
||||
const response = await prisma.data.findUnique({
|
||||
where: { id: 1 }
|
||||
})
|
||||
|
||||
if (!response) {
|
||||
throw new Error('No data found')
|
||||
}
|
||||
|
||||
res.status(200).json(response?.data)
|
||||
})
|
||||
|
||||
.put(async (req, res) => {
|
||||
const { data } = req.body
|
||||
|
||||
if (!data) {
|
||||
throw new Error('No data provided')
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await prisma.data.update({
|
||||
where: {
|
||||
id: 1
|
||||
},
|
||||
where: { id: 1 },
|
||||
data: { data: JSON.stringify(req.body.data) }
|
||||
})
|
||||
|
||||
res.status(200).json(response)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).send('Internal server error')
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
res.status(500).json({ error: err.message })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user