feat: add api logger to survey-sale api
This commit is contained in:
parent
a2e6c2343a
commit
5d5ba2e82a
@ -6,6 +6,7 @@ import { sessionOptions } from '@/libs/session'
|
||||
import { cookies } from 'next/headers'
|
||||
import type { SessionData } from '@/types/Auth'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { loggerWrapper } from '@/libs/api-wrapper'
|
||||
|
||||
/**
|
||||
* @description 조사 매물 조회 에러 메시지
|
||||
@ -128,11 +129,11 @@ const fetchSurvey = async (id: number) => {
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
export async function getSurveySaleDetail(request: NextRequest): Promise<NextResponse> {
|
||||
try {
|
||||
const cookieStore = await cookies()
|
||||
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
||||
const { id } = await params
|
||||
const id = request.nextUrl.pathname.split('/').pop() ?? ''
|
||||
const { searchParams } = new URL(request.url)
|
||||
const isPdf = searchParams.get('isPdf') === 'true'
|
||||
|
||||
@ -228,9 +229,9 @@ const getNewSrlNo = async (srlNo: string, storeId: string, role: string) => {
|
||||
* ...
|
||||
* }
|
||||
* */
|
||||
export async function PUT(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
export async function updateSurveySaleDetail(request: NextRequest): Promise<NextResponse> {
|
||||
try {
|
||||
const { id } = await params
|
||||
const id = request.nextUrl.pathname.split('/').pop() ?? ''
|
||||
const body = await request.json()
|
||||
const { detailInfo, ...basicInfo } = body.survey
|
||||
|
||||
@ -257,6 +258,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
|
||||
return NextResponse.json({ error: 'データ保存に失敗しました。' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {DELETE} /api/survey-sales/:id 조사 매물 삭제 API
|
||||
* @apiName DELETE /api/survey-sales/:id
|
||||
@ -275,9 +277,9 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
|
||||
* {
|
||||
* "message": "success"
|
||||
*/
|
||||
export async function DELETE(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
export async function deleteSurveySaleDetail(request: NextRequest): Promise<NextResponse> {
|
||||
try {
|
||||
const { id } = await params
|
||||
const id = request.nextUrl.pathname.split('/').pop() ?? ''
|
||||
|
||||
await prisma.$transaction(async (tx: Prisma.TransactionClient) => {
|
||||
// @ts-ignore
|
||||
@ -343,9 +345,9 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export async function PATCH(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
export async function submitSurveySaleDetail(request: NextRequest): Promise<NextResponse> {
|
||||
try {
|
||||
const { id } = await params
|
||||
const id = request.nextUrl.pathname.split('/').pop() ?? ''
|
||||
const body = await request.json()
|
||||
// @ts-ignore
|
||||
const survey = await prisma.SD_SURVEY_SALES_BASIC_INFO.update({
|
||||
@ -364,3 +366,8 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
|
||||
return NextResponse.json({ error: 'データ保存に失敗しました。' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export const GET = loggerWrapper(getSurveySaleDetail)
|
||||
export const PUT = loggerWrapper(updateSurveySaleDetail)
|
||||
export const DELETE = loggerWrapper(deleteSurveySaleDetail)
|
||||
export const PATCH = loggerWrapper(submitSurveySaleDetail)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/libs/prisma'
|
||||
import { convertToSnakeCase } from '@/utils/common-utils'
|
||||
import { loggerWrapper } from '@/libs/api-wrapper'
|
||||
/**
|
||||
* @description 검색 파라미터 타입
|
||||
*/
|
||||
@ -192,7 +193,7 @@ const checkSession = (params: SearchParams) => {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
export async function GET(request: Request) {
|
||||
export async function getSurveySales(request: Request) {
|
||||
try {
|
||||
/** URL 파라미터 파싱 */
|
||||
const { searchParams } = new URL(request.url)
|
||||
@ -273,7 +274,7 @@ export async function GET(request: Request) {
|
||||
*
|
||||
* @apiError {Number} 500 서버 오류
|
||||
*/
|
||||
export async function PUT(request: Request) {
|
||||
export async function updateSurveySales(request: Request) {
|
||||
try {
|
||||
/** 요청 바디 파싱 */
|
||||
const body = await request.json()
|
||||
@ -335,7 +336,7 @@ export async function PUT(request: Request) {
|
||||
*
|
||||
* @apiError {Number} 500 서버 오류
|
||||
*/
|
||||
export async function POST(request: Request) {
|
||||
export async function createSurveySales(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
|
||||
@ -393,3 +394,7 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ error: 'データ保存に失敗しました。' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export const GET = loggerWrapper(getSurveySales)
|
||||
export const PUT = loggerWrapper(updateSurveySales)
|
||||
export const POST = loggerWrapper(createSurveySales)
|
||||
Loading…
x
Reference in New Issue
Block a user