fix(api): await params in Next.js 15 dynamic routes
This commit is contained in:
@@ -5,10 +5,11 @@ const prisma = new PrismaClient();
|
|||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const specialId = parseInt(params.id);
|
const { id } = await params;
|
||||||
|
const specialId = parseInt(id);
|
||||||
|
|
||||||
const special = await prisma.special.findUnique({
|
const special = await prisma.special.findUnique({
|
||||||
where: { id: specialId },
|
where: { id: specialId },
|
||||||
@@ -37,10 +38,11 @@ export async function GET(
|
|||||||
|
|
||||||
export async function PUT(
|
export async function PUT(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const specialId = parseInt(params.id);
|
const { id } = await params;
|
||||||
|
const specialId = parseInt(id);
|
||||||
const { name, maxAttempts, unlockSteps } = await request.json();
|
const { name, maxAttempts, unlockSteps } = await request.json();
|
||||||
|
|
||||||
const special = await prisma.special.update({
|
const special = await prisma.special.update({
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ const prisma = new PrismaClient();
|
|||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const specialId = parseInt(params.id);
|
const { id } = await params;
|
||||||
|
const specialId = parseInt(id);
|
||||||
const { songId, startTime = 0, order } = await request.json();
|
const { songId, startTime = 0, order } = await request.json();
|
||||||
|
|
||||||
const specialSong = await prisma.specialSong.create({
|
const specialSong = await prisma.specialSong.create({
|
||||||
@@ -32,10 +33,11 @@ export async function POST(
|
|||||||
|
|
||||||
export async function PUT(
|
export async function PUT(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const specialId = parseInt(params.id);
|
const { id } = await params;
|
||||||
|
const specialId = parseInt(id);
|
||||||
const { songId, startTime, order } = await request.json();
|
const { songId, startTime, order } = await request.json();
|
||||||
|
|
||||||
const specialSong = await prisma.specialSong.update({
|
const specialSong = await prisma.specialSong.update({
|
||||||
@@ -63,10 +65,11 @@ export async function PUT(
|
|||||||
|
|
||||||
export async function DELETE(
|
export async function DELETE(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const specialId = parseInt(params.id);
|
const { id } = await params;
|
||||||
|
const specialId = parseInt(id);
|
||||||
const { songId } = await request.json();
|
const { songId } = await request.json();
|
||||||
|
|
||||||
await prisma.specialSong.delete({
|
await prisma.specialSong.delete({
|
||||||
|
|||||||
Reference in New Issue
Block a user