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
27 changes: 22 additions & 5 deletions apps/backend/src/orders/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,33 @@ export class OrdersController {
},
})
@UseInterceptors(
FilesInterceptor('photos', 10, { storage: multer.memoryStorage() }),
FilesInterceptor('photos', 10, {
storage: multer.memoryStorage(),
limits: {
fileSize: 5 * 1024 * 1024, // 5 MB in bytes
},
}),
)
async confirmDelivery(
@Param('orderId', ParseIntPipe) orderId: number,
@Body() body: ConfirmDeliveryDto,
@UploadedFiles() photos?: Express.Multer.File[],
): Promise<Order> {
const uploadedPhotoUrls =
photos && photos.length > 0 ? await this.awsS3Service.upload(photos) : [];

return this.ordersService.confirmDelivery(orderId, body, uploadedPhotoUrls);
try {
const uploadedPhotoUrls =
photos && photos.length > 0
? await this.awsS3Service.upload(photos)
: [];
return this.ordersService.confirmDelivery(
orderId,
body,
uploadedPhotoUrls,
);
} catch (err: any) {
if (err.code === 'LIMIT_FILE_SIZE') {
throw new BadRequestException('Each photo must be 5 MB or smaller');
}
throw err;
}
}
}
56 changes: 35 additions & 21 deletions apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
OrderSummary,
UserDto,
OrderDetails,
ConfirmDeliveryDto,
FoodRequestSummaryDto,
OrderWithoutRelations,
Assignments,
} from 'types/types';

Expand Down Expand Up @@ -158,6 +161,12 @@ export class ApiClient {
.then((response) => response.data);
}

public async getPantryOrders(pantryId: number): Promise<Order[]> {
return this.axiosInstance
.get(`/api/pantries/${pantryId}/orders`)
.then((response) => response.data);
}

public async getPantry(pantryId: number): Promise<Pantry> {
return this.get(`/api/pantries/${pantryId}`) as Promise<Pantry>;
}
Expand Down Expand Up @@ -215,6 +224,32 @@ export class ApiClient {
.then((response) => response.data);
}

public async confirmOrderDelivery(
orderId: number,
dto: ConfirmDeliveryDto,
photos: File[],
): Promise<OrderWithoutRelations> {
const formData = new FormData();

// DTO fields
formData.append('dateReceived', dto.dateReceived);
if (dto.feedback) {
formData.append('feedback', dto.feedback);
}

// files (must be key = "photos")
for (const file of photos) {
formData.append('photos', file);
}

const { data } = await this.axiosInstance.patch(
`/api/orders/${orderId}/confirm-delivery`,
formData,
);

return data;
}

public async postManufacturer(
data: ManufacturerApplicationDto,
): Promise<AxiosResponse<void>> {
Expand Down Expand Up @@ -283,27 +318,6 @@ export class ApiClient {
return data as FoodRequest[];
}

public async confirmDelivery(
requestId: number,
data: FormData,
): Promise<void> {
try {
const response = await this.axiosInstance.post(
`/api/requests/${requestId}/confirm-delivery`,
data,
);

if (response.status === 200) {
alert('Delivery confirmation submitted successfully');
window.location.href = '/request-form';
} else {
alert(`Failed to submit: ${response.statusText}`);
}
} catch (error) {
alert(`Error submitting delivery confirmation: ${error}`);
}
}

public async getCurrentUserPantryId(): Promise<number> {
const data = await this.get('/api/pantries/my-id');
return data as number;
Expand Down
9 changes: 9 additions & 0 deletions apps/frontend/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ForgotPasswordPage from '@containers/forgotPasswordPage';
import ProtectedRoute from '@components/protectedRoute';
import Unauthorized from '@containers/unauthorized';
import { Authenticator } from '@aws-amplify/ui-react';
import PantryOrderManagement from '@containers/pantryOrderManagement';
import FoodManufacturerApplication from '@containers/foodManufacturerApplication';
import { submitManufacturerApplicationForm } from '@components/forms/manufacturerApplicationForm';
import AssignedPantries from '@containers/volunteerAssignedPantries';
Expand Down Expand Up @@ -161,6 +162,14 @@ const router = createBrowserRouter([
</ProtectedRoute>
),
},
{
path: '/pantry-order-management',
element: (
<ProtectedRoute>
<PantryOrderManagement />
</ProtectedRoute>
),
},
{
path: '/confirm-delivery',
action: submitDeliveryConfirmationFormModal,
Expand Down
4 changes: 4 additions & 0 deletions apps/frontend/src/chakra-ui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ declare module '@chakra-ui/react' {
extends ComponentPropsStrictChildren {}
export interface MenuRadioItemProps extends ComponentPropsLenientChildren {}

// FileUpload components
export interface FileUploadDropzoneProps
extends ComponentPropsLenientChildren {}

// Dialog components
export interface DialogCloseTriggerProps
extends ComponentPropsStrictChildren {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ export const submitDeliveryConfirmationFormModal: ActionFunction = async ({
}

try {
await ApiClient.confirmDelivery(
parseInt(requestId, 10),
confirmDeliveryData,
);
// confirm delivery endpoint is deprecated and has been deleted. TODO: refactor this
// await ApiClient.confirmDelivery(
// parseInt(requestId, 10),
// confirmDeliveryData,
// );
alert('Delivery confirmation submitted successfully');
} catch (error) {
alert(`Error submitting delivery confirmation: ${error}`);
Expand Down
Loading