Totalcount modal should be updated in case the current date is less than the last totalcount date
try {
const product = await prisma.product.findUnique({
where: {
id,
},
});
const res = await prisma.$transaction(async (tx) => {
// this one is independent
await tx.product.update({
where: {
id,
},
data: {
quantity: newQuantity,
},
});
//
await tx.issueItem.create({
data: {
productId: id,
issuedToId: parseInt(issuedTo),
issuedQuantity: issueQuantity,
issuedAt: dateOfIssue,
jobCard,
},
});
let currentDate = dateOfIssue;
// await updateTotalStockCount(issueQuantity, currentDate, operation, tx);
// const record = await tx.totalStockCount.findMany({
const record = await tx.totalStockCount.findMany({
orderBy: {
date: "desc",
},
take: 1,
});
console.log("latestrecord:", record);
if (record.length > 0 && isBefore(currentDate, record[0].date)) {
console.log("Current Date:", currentDate);
console.log("before teh latest date");
// should throw error
return new NextResponse("ERROR issuing item", { status: 401 });
}
});
return NextResponse.json("Issued item successfully", { status: 201 });
} catch (error) {
console.log("ERROR: ", error);
return new NextResponse("SOMETHIHG WENT WRONG", { status: 401 });
}
the current date in the if condition if (record.length > 0 && isBefore(currentDate, record[0].date))
is being logged but stil no error is thrown why is that?