Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/scripts/reconcile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ async function reconcile() {
// Get batch ID at index
const batchIdBytes32 = await contract.getBatchIdByIndex(i);

<<<<<<< HEAD
=======
// Convert bytes32 to string (remove padding)
const batchId = ethers.zeroPadValue(batchIdBytes32, 32).toString();

>>>>>>> upstream/main
// Get full batch data
const onChainBatch = await contract.getBatch(batchIdBytes32);

Expand All @@ -59,14 +62,21 @@ async function reconcile() {
const readableBatchId = ethers.toUtf8String(batchIdBytes32);

// Map blockchain stage (uint8) to string
<<<<<<< HEAD
const stageName = getStageName(0);
=======
const stageName = getStageName(Number(onChainBatch.quantity) > 0 ? 0 : 0); // Stage is in updates, not CropBatch struct
>>>>>>> upstream/main

// Update or insert batch in MongoDB
await Batch.updateOne(
{ batchId: readableBatchId },
{
$set: {
<<<<<<< HEAD
=======
// Keep local data but update sync status
>>>>>>> upstream/main
syncStatus: 'synced',
lastSyncedAt: new Date(),
onChainData: {
Expand Down
7 changes: 7 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ const PORT = process.env.PORT || 3001;

// ==================== MIDDLEWARE FUNCTIONS ====================

<<<<<<< HEAD
// Authentication is handled by middleware imported from './middleware/auth':
// - protect: Verifies JWT and fetches full user from MongoDB
// - adminOnly: Checks if user has admin role
=======
// Authentication is handled by middleware imported from './middleware/auth'
// - protect: Verifies JWT and fetches full user from - adminOnly: MongoDB
// Checks if user has admin role
>>>>>>> upstream/main
// - authorizeBatchOwner: Verifies user owns the batch
// - authorizeRoles: Role-based authorization

Expand Down Expand Up @@ -343,6 +349,7 @@ async function generateBatchId(session = null) {
return `CROP-${currentYear}-${String(counter.seq).padStart(4, '0')}`;
}


async function generateQRCode(batchId) {
try {
return await QRCode.toDataURL(batchId, {
Expand Down
Loading