Skip to content

Commit 9361a32

Browse files
committed
Fixed optional photo uploading
1 parent 6f0e232 commit 9361a32

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

apps/backend/src/foodRequests/request.controller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,15 @@ export class FoodRequestsController {
125125
async confirmDelivery(
126126
@Param('requestId', ParseIntPipe) requestId: number,
127127
@Body() body: { dateReceived: string; feedback: string },
128-
@UploadedFiles() photos: Express.Multer.File[],
128+
@UploadedFiles() photos?: Express.Multer.File[],
129129
): Promise<FoodRequest> {
130-
if (!photos || photos.length === 0) {
131-
throw new Error('No photos uploaded');
132-
}
133-
134130
const formattedDate = new Date(body.dateReceived);
135131
if (isNaN(formattedDate.getTime())) {
136132
throw new Error('Invalid date format for deliveryDate');
137133
}
138134

139-
const uploadedPhotoUrls = await this.awsS3Service.upload(photos);
135+
const uploadedPhotoUrls =
136+
photos && photos.length > 0 ? await this.awsS3Service.upload(photos) : [];
140137

141138
return this.requestsService.updateDeliveryDetails(
142139
requestId,

apps/frontend/src/components/forms/deliveryConfirmationModalButton.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ export const submitDeliveryConfirmationFormModal: ActionFunction = async ({
149149

150150
confirmDeliveryData.append('feedback', form.get('feedback') as string);
151151

152-
globalPhotos.forEach((photo) => {
153-
confirmDeliveryData.append('photos', photo);
154-
});
152+
if (globalPhotos.length > 0) {
153+
globalPhotos.forEach((photo) => {
154+
confirmDeliveryData.append('photos', photo);
155+
});
156+
}
155157

156158
try {
157159
const response = await fetch(

0 commit comments

Comments
 (0)