diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index b689453..d9a5be9 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -630,6 +630,17 @@ export const uploadUtilBillsProofOfPayment = async (locationID: string, formData noStore(); try { + + // check if attachment already exists for the location + const dbClient = await getDbClient(); + + const existingLocation = await dbClient.collection("lokacije") + .findOne({ _id: locationID }, { projection: { utilBillsProofOfPaymentAttachment: 1 } }); + + if (existingLocation?.utilBillsProofOfPaymentAttachment) { + return { success: false, error: 'An attachment already exists for this location' }; + } + const file = formData.get('utilBillsProofOfPaymentAttachment') as File; // Validate file type @@ -643,8 +654,6 @@ export const uploadUtilBillsProofOfPayment = async (locationID: string, formData return { success: false, error: 'Invalid file' }; } - const dbClient = await getDbClient(); - // Update the location with the attachment await dbClient.collection("lokacije") .updateOne(