(refactor) locationActions: preventing multiple proof of payment uploads
This commit is contained in:
@@ -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<BillingLocation>("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<BillingLocation>("lokacije")
|
||||
.updateOne(
|
||||
|
||||
Reference in New Issue
Block a user