-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
617 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { NextResponse } from "next/server"; | ||
import { prisma } from "@/app/lib/config/prisma"; | ||
import { StatusCodes } from "http-status-codes"; | ||
|
||
export async function PATCH( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
let tagId: number | undefined; | ||
let itemId: number | undefined; | ||
try { | ||
const json = await request.json(); | ||
tagId = json.tagId; | ||
itemId = json.itemId; | ||
|
||
console.debug("Received data:", { tagId, itemId }); | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ error: `Error parsing request body, ${error}` }, | ||
{ status: StatusCodes.BAD_REQUEST } | ||
); | ||
} | ||
|
||
try { | ||
if (tagId !== undefined) { | ||
const tag = await prisma.tag.findUnique({ | ||
where: { id: tagId }, | ||
}); | ||
if (tag === null) { | ||
return NextResponse.json( | ||
{ error: "Tag not found" }, | ||
{ status: StatusCodes.NOT_FOUND } | ||
); | ||
} | ||
} | ||
|
||
if (itemId !== undefined) { | ||
const item = await prisma.item.findUnique({ | ||
where: { id: itemId }, | ||
}); | ||
if (item === null) { | ||
return NextResponse.json( | ||
{ error: "Item not found" }, | ||
{ status: StatusCodes.NOT_FOUND } | ||
); | ||
} | ||
} | ||
|
||
const updated = await prisma.itemRelation.update({ | ||
where: { id: Number(params.id) }, | ||
data: { tagId, itemId }, | ||
}); | ||
|
||
return NextResponse.json(updated); | ||
} catch (error) { | ||
console.error("Error update item relation:", error); | ||
return NextResponse.json( | ||
{ error: "Error updating item relation" }, | ||
{ status: StatusCodes.INTERNAL_SERVER_ERROR } | ||
); | ||
} | ||
} | ||
|
||
export async function DELETE( | ||
_request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
try { | ||
const deleted = await prisma.tagRelation.delete({ | ||
where: { id: Number(params.id) }, | ||
}); | ||
|
||
return NextResponse.json(deleted); | ||
} catch (error) { | ||
console.error("Error deleting item relation:", error); | ||
return NextResponse.json( | ||
{ error: "Error deleting item relation" }, | ||
{ status: StatusCodes.INTERNAL_SERVER_ERROR } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.