Implement per-bill proof of payment and update field names
Frontend changes: - Added ViewBillCard proof of payment upload for per-bill mode - Conditional rendering based on proofOfPaymentType - File upload with PDF validation and loading states - Download link to /share/proof-of-payment/per-bill/ - Updated LocationCard to use new utilBillsProofOfPayment field structure Backend changes: - Updated locationActions with improved file validation - File size validation using MAX_PROOF_OF_PAYMENT_UPLOAD_SIZE_KB - PDF type validation before database operations - Enhanced serializeAttachment with FileAttachment type - Updated database projections for optimized queries - Updated monthActions to use consolidated field name - Updated proof-of-payment download route with new field names Data structure migration: - Replaced utilBillsProofOfPaymentAttachment + utilBillsProofOfPaymentUploadedAt with single utilBillsProofOfPayment object containing uploadedAt - Consistent use of FileAttachment type across all upload functions Translations: - Added upload-proof-of-payment-legend and upload-proof-of-payment-label to bill-edit-form section in both English and Croatian This completes the proof of payment feature implementation for both combined (location-level) and per-bill modes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import { getDbClient } from '@/app/lib/dbClient';
|
||||
import { BillingLocation } from '@/app/lib/db-types';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export async function GET(request: Request, { params:{ id } }: { params: { id:string } }) {
|
||||
const locationID = id;
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
const location = await dbClient.collection<BillingLocation>("lokacije")
|
||||
.findOne({ _id: locationID }, {
|
||||
projection: {
|
||||
utilBillsProofOfPaymentAttachment: 1,
|
||||
}
|
||||
});
|
||||
|
||||
if(!location?.utilBillsProofOfPaymentAttachment) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
// Convert fileContentsBase64 from Base64 string to binary
|
||||
const fileContentsBuffer = Buffer.from(location.utilBillsProofOfPaymentAttachment.fileContentsBase64, 'base64');
|
||||
|
||||
// Convert fileContentsBuffer to format that can be sent to the client
|
||||
const fileContents = new Uint8Array(fileContentsBuffer);
|
||||
|
||||
return new Response(fileContents, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `attachment; filename="${location.utilBillsProofOfPaymentAttachment.fileName}"`,
|
||||
'Last-Modified': `${location.utilBillsProofOfPaymentAttachment.fileLastModified}`
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user