45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { prisma } from '@/libs/prisma'
|
|
|
|
export async function POST(request: Request) {
|
|
const body = await request.json()
|
|
// @ts-ignore
|
|
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.create({
|
|
data: body,
|
|
})
|
|
return NextResponse.json(res)
|
|
}
|
|
|
|
export async function GET() {
|
|
try {
|
|
// @ts-ignore
|
|
const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany()
|
|
return NextResponse.json(res)
|
|
} catch (error) {
|
|
console.error(error)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
// export async function GET(request: Request) {
|
|
// // @ts-ignore
|
|
// const res = await prisma.SD_SERVEY_SALES_BASIC_INFO.findMany({
|
|
// include: {
|
|
// detail_info: true,
|
|
// },
|
|
// })
|
|
// return NextResponse.json(res)
|
|
// }
|
|
|
|
export async function PUT(request: Request) {
|
|
const body = await request.json()
|
|
console.log('🚀 ~ PUT ~ body:', body)
|
|
const detailInfo = { ...body.detail_info, basic_info_id: body.id }
|
|
console.log('🚀 ~ PUT ~ detailInfo:', detailInfo)
|
|
// @ts-ignore
|
|
const res = await prisma.SD_SERVEY_SALES_DETAIL_INFO.create({
|
|
data: detailInfo,
|
|
})
|
|
return NextResponse.json({ message: 'Survey sales updated successfully' })
|
|
}
|