TypeError: The "payload argument must be of type object. Received null at log"
Unanswered
Pampas Deerhound posted this in #help-forum
Pampas DeerhoundOP
Hi there, I have faced an error while creating a project. This is a file in the route.js. I am using prisma database to connect. I have checked all those npx prisma migrate and they still came out with this error.
Please help me ASAP. Thank you everyone!
Please help me ASAP. Thank you everyone!
3 Replies
Pampas DeerhoundOP
import db from "@/lib/db";
import { NextResponse } from "next/server";
export async function POST(request) {
try {
const { name, description, categoryId, sku, barcode, qty, unitId, brandId, sellingPrice,
buyingPrice, supplierId, reOrderPoint, location, imageURL, weight, dimensions,taxRate, notes
} = await request.json();
const newItemData = await db.category.create({
data:{
title: name,
description: description ,
categoryId:categoryId ,
sku: sku ,
barcode: barcode,
quantity: qty,
unitId: unitId,
brandId: brandId,
sellingPrice: sellingPrice,
buyingPrice: buyingPrice ,
supplierId:supplierId ,
reOrderPoint: reOrderPoint ,
location: location,
imageURL: imageURL,
weight:weight,
dimensions: dimensions,
taxRate: taxRate ,
notes: notes,
}
});
console.log(item);
return NextResponse.json(item);
} catch (error) {
console.log(error);
return NextResponse.json({
error,
message: "Failed to create a category"
}, {
status: 500
});
}
}
import { NextResponse } from "next/server";
export async function POST(request) {
try {
const { name, description, categoryId, sku, barcode, qty, unitId, brandId, sellingPrice,
buyingPrice, supplierId, reOrderPoint, location, imageURL, weight, dimensions,taxRate, notes
} = await request.json();
const newItemData = await db.category.create({
data:{
title: name,
description: description ,
categoryId:categoryId ,
sku: sku ,
barcode: barcode,
quantity: qty,
unitId: unitId,
brandId: brandId,
sellingPrice: sellingPrice,
buyingPrice: buyingPrice ,
supplierId:supplierId ,
reOrderPoint: reOrderPoint ,
location: location,
imageURL: imageURL,
weight:weight,
dimensions: dimensions,
taxRate: taxRate ,
notes: notes,
}
});
console.log(item);
return NextResponse.json(item);
} catch (error) {
console.log(error);
return NextResponse.json({
error,
message: "Failed to create a category"
}, {
status: 500
});
}
}
export async function GET(request) {
try {
console.log("Fetching warehouses...");
const categories = await db.category.findMany({
orderBy: { createdAt: 'desc' } // Latest warehouses first
});
return NextResponse.json(categories)
console.log("Warehouses Retrieved:", warehousesList);
return NextResponse.json(warehousesList, { status: 200 }); // 200 OK
} catch (error) {
console.error("Error fetching categories:", error.message);
return NextResponse.json(
{ message: "Failed to fetch categories", error: error.message },
{ status: 400 }
);
}
}
try {
console.log("Fetching warehouses...");
const categories = await db.category.findMany({
orderBy: { createdAt: 'desc' } // Latest warehouses first
});
return NextResponse.json(categories)
console.log("Warehouses Retrieved:", warehousesList);
return NextResponse.json(warehousesList, { status: 200 }); // 200 OK
} catch (error) {
console.error("Error fetching categories:", error.message);
return NextResponse.json(
{ message: "Failed to fetch categories", error: error.message },
{ status: 400 }
);
}
}
Here is my code ya