Merge branch 'dev' of https://git.hanasys.jp/qcast3/onsitesurvey into feature/survey

This commit is contained in:
Dayoung 2025-05-07 09:00:35 +09:00
commit daf9f31733
9 changed files with 251 additions and 0 deletions

View File

@ -0,0 +1,16 @@
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)
}

View File

@ -0,0 +1,17 @@
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)
}

View File

@ -0,0 +1,34 @@
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 })
}
}

View File

@ -0,0 +1,12 @@
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' })
}

View File

@ -0,0 +1,72 @@
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' })
}

View File

@ -0,0 +1,33 @@
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' })
}

View File

@ -0,0 +1,23 @@
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 })
}
}

View File

@ -0,0 +1,7 @@
import { NextResponse } from 'next/server'
import { prisma } from '@/libs/prisma'
export const GET = async () => {
const users = await prisma.user.findMany()
return NextResponse.json(users)
}

37
src/app/api/user/route.ts Normal file
View File

@ -0,0 +1,37 @@
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)
}