Compare commits
No commits in common. "3cf55e1a9ee2302f6464c791a03c2798fa9aab67" and "9255d3fab7b45e8ca6cddd3672c21a38829a09ee" have entirely different histories.
3cf55e1a9e
...
9255d3fab7
@ -1,16 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function GET() {
|
|
||||||
// @ts-ignore
|
|
||||||
const roofMaterialCategory = await prisma.MS_SUITABLE.findMany({
|
|
||||||
select: {
|
|
||||||
roof_material: true,
|
|
||||||
},
|
|
||||||
distinct: ['roof_material'],
|
|
||||||
orderBy: {
|
|
||||||
roof_material: 'asc',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return NextResponse.json(roofMaterialCategory)
|
|
||||||
}
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
|
||||||
const { searchParams } = new URL(request.url)
|
|
||||||
const roofMaterial = searchParams.get('roof-material')
|
|
||||||
console.log('🚀 ~ GET ~ roof-material:', roofMaterial)
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const suitables = await prisma.MS_SUITABLE.findMany({
|
|
||||||
where: {
|
|
||||||
roof_material: roofMaterial,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return NextResponse.json(suitables)
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
|
||||||
try {
|
|
||||||
const searchParams = request.nextUrl.searchParams
|
|
||||||
const category = searchParams.get('category')
|
|
||||||
const keyword = searchParams.get('keyword')
|
|
||||||
|
|
||||||
let whereCondition: any = {}
|
|
||||||
if (category) {
|
|
||||||
whereCondition['roof_material'] = category
|
|
||||||
}
|
|
||||||
if (keyword) {
|
|
||||||
whereCondition['product_name'] = {
|
|
||||||
contains: keyword,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log('🚀 ~ /api/suitable/list: ~ prisma where condition:', whereCondition)
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const suitables = await prisma.MS_SUITABLE.findMany({
|
|
||||||
where: whereCondition,
|
|
||||||
orderBy: {
|
|
||||||
product_name: 'asc',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return NextResponse.json(suitables)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ 데이터 조회 중 오류가 발생했습니다:', error)
|
|
||||||
return NextResponse.json({ error: '데이터 조회 중 오류가 발생했습니다' }, { status: 500 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
const body = await request.json()
|
|
||||||
// @ts-ignore
|
|
||||||
const suitables = await prisma.MS_SUITABLE.createMany({
|
|
||||||
data: body,
|
|
||||||
})
|
|
||||||
|
|
||||||
return NextResponse.json({ message: 'Suitable created successfully' })
|
|
||||||
}
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
|
|
||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
|
||||||
const body = await request.json()
|
|
||||||
const { id } = await context.params
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.update({
|
|
||||||
where: { id: Number(id) },
|
|
||||||
data: {
|
|
||||||
detail_info: {
|
|
||||||
create: body,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return NextResponse.json({ message: 'Survey detail created successfully' })
|
|
||||||
}
|
|
||||||
export async function GET(request: Request, context: { params: { id: string } }) {
|
|
||||||
const { id } = await context.params
|
|
||||||
// @ts-ignore
|
|
||||||
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.findUnique({
|
|
||||||
where: { id: Number(id) },
|
|
||||||
include: {
|
|
||||||
detail_info: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return NextResponse.json(survey)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
|
||||||
const { id } = await context.params
|
|
||||||
const body = await request.json()
|
|
||||||
// @ts-ignore
|
|
||||||
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.update({
|
|
||||||
where: { id: Number(id) },
|
|
||||||
data: {
|
|
||||||
...body,
|
|
||||||
detail_info: {
|
|
||||||
update: body.detail_info,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return NextResponse.json(survey)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function DELETE(request: Request, context: { params: { id: string; detail_id: string } }) {
|
|
||||||
const { id, detail_id } = await context.params
|
|
||||||
if (detail_id) {
|
|
||||||
// @ts-ignore
|
|
||||||
const survey = await prisma.SD_SERVEY_SALES_DETAIL_INFO.delete({
|
|
||||||
where: { id: Number(detail_id) },
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// @ts-ignore
|
|
||||||
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.delete({
|
|
||||||
where: { id: Number(id) },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return NextResponse.json({ message: 'Survey deleted successfully' })
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function PATCH(request: Request, context: { params: { id: string } }) {
|
|
||||||
const { id } = await context.params
|
|
||||||
// @ts-ignore
|
|
||||||
const survey = await prisma.SD_SERVEY_SALES_BASIC_INFO.update({
|
|
||||||
where: { id: Number(id) },
|
|
||||||
data: {
|
|
||||||
submission_status: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return NextResponse.json({ message: 'Survey confirmed successfully' })
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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' })
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
try {
|
|
||||||
const body = await request.json()
|
|
||||||
const { username, email, password } = body
|
|
||||||
|
|
||||||
const user = await prisma.user.create({
|
|
||||||
data: {
|
|
||||||
username,
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
updated_at: new Date(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return NextResponse.json(user)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error creating user:', error)
|
|
||||||
return NextResponse.json({ error: 'Error creating user' }, { status: 500 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
|
|
||||||
export const GET = async () => {
|
|
||||||
const users = await prisma.user.findMany()
|
|
||||||
return NextResponse.json(users)
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { prisma } from '@/libs/prisma'
|
|
||||||
import { getIronSession } from 'iron-session'
|
|
||||||
import { cookies } from 'next/headers'
|
|
||||||
import { SessionData, sessionOptions } from '@/libs/session'
|
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
|
||||||
const { username, password } = await request.json()
|
|
||||||
|
|
||||||
console.log('🚀 ~ POST ~ username:', username)
|
|
||||||
console.log('🚀 ~ POST ~ password:', password)
|
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
|
||||||
where: {
|
|
||||||
username: username,
|
|
||||||
password: password,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
console.log('🚀 ~ POST ~ user:', user)
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
return NextResponse.json({ error: 'User not found' }, { status: 404 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const cookieStore = await cookies()
|
|
||||||
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
|
||||||
console.log('start session edit!')
|
|
||||||
session.username = user.username!
|
|
||||||
session.email = user.email!
|
|
||||||
session.isLoggedIn = true
|
|
||||||
console.log('end session edit!')
|
|
||||||
await session.save()
|
|
||||||
console.log('🚀 ~ POST ~ session:', session)
|
|
||||||
|
|
||||||
// return NextResponse.redirect(new URL(process.env.NEXT_PUBLIC_URL!, request.url))
|
|
||||||
return NextResponse.json(user)
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user