mirror of
https://github.com/dsoaress/link-free.git
synced 2026-11-25 12:28:35 +00:00
refactor: some adjustments
This commit is contained in:
52 files changed
+417
-481
No files matched your search
+4
-29
@@ -1,34 +1,9 @@
|
||||
import { Prisma } from '@prisma/client'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import nc from 'next-connect'
|
||||
|
||||
import { prisma } from '../../services/prisma'
|
||||
import { prisma } from 'services/prisma'
|
||||
// import { authMiddleware } from '../../utils/authMiddleware'
|
||||
import { ExceptionError } from '../../utils/error'
|
||||
import { ExceptionError } from 'utils/error'
|
||||
import { nc } from 'utils/nc'
|
||||
|
||||
const handler = nc<NextApiRequest, NextApiResponse>({
|
||||
onNoMatch: (_req, res) => {
|
||||
res.status(404).json({ error: 'Not found' })
|
||||
},
|
||||
onError: (err, _req, res) => {
|
||||
if (err instanceof ExceptionError) {
|
||||
res.status(err.status).json({
|
||||
status: err.status,
|
||||
error: err.message
|
||||
})
|
||||
} else if (err instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
res.status(400).json({
|
||||
status: 400,
|
||||
error: err.message
|
||||
})
|
||||
} else {
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
error: err.message
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
const handler = nc
|
||||
.get(async (_req, res) => {
|
||||
const response = await prisma.data.findUnique({
|
||||
where: { id: 1 }
|
||||
|
||||
Reference in new issue
Block a user