Merge branch 'dev' of https://git.hanasys.jp/qcast3/onsitesurvey into feature/survey
This commit is contained in:
commit
daf9f31733
16
src/app/api/suitable/category/route.ts
Normal file
16
src/app/api/suitable/category/route.ts
Normal 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)
|
||||
}
|
||||
17
src/app/api/suitable/detail/route.ts
Normal file
17
src/app/api/suitable/detail/route.ts
Normal 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)
|
||||
}
|
||||
34
src/app/api/suitable/list/route.ts
Normal file
34
src/app/api/suitable/list/route.ts
Normal 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 })
|
||||
}
|
||||
}
|
||||
12
src/app/api/suitable/route.ts
Normal file
12
src/app/api/suitable/route.ts
Normal 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' })
|
||||
}
|
||||
72
src/app/api/survey-sale/[id]/route.ts
Normal file
72
src/app/api/survey-sale/[id]/route.ts
Normal 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' })
|
||||
}
|
||||
33
src/app/api/survey-sale/route.ts
Normal file
33
src/app/api/survey-sale/route.ts
Normal 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' })
|
||||
}
|
||||
23
src/app/api/user/create/route.ts
Normal file
23
src/app/api/user/create/route.ts
Normal 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 })
|
||||
}
|
||||
}
|
||||
7
src/app/api/user/list/route.ts
Normal file
7
src/app/api/user/list/route.ts
Normal 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
37
src/app/api/user/route.ts
Normal 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)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user