-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-125] Move Food Request Fields #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,30 +5,18 @@ import { | |
| ParseIntPipe, | ||
| Post, | ||
| Body, | ||
| UploadedFiles, | ||
| UseInterceptors, | ||
| BadRequestException, | ||
| NotFoundException, | ||
| } from '@nestjs/common'; | ||
| import { ApiBody } from '@nestjs/swagger'; | ||
| import { RequestsService } from './request.service'; | ||
| import { FoodRequest } from './request.entity'; | ||
| import { AWSS3Service } from '../aws/aws-s3.service'; | ||
| import { FilesInterceptor } from '@nestjs/platform-express'; | ||
| import * as multer from 'multer'; | ||
| import { OrdersService } from '../orders/order.service'; | ||
| import { RequestSize } from './types'; | ||
| import { OrderStatus } from '../orders/types'; | ||
| import { OrderDetailsDto } from './dtos/order-details.dto'; | ||
|
|
||
| @Controller('requests') | ||
| // @UseInterceptors() | ||
| export class RequestsController { | ||
| constructor( | ||
| private requestsService: RequestsService, | ||
| private awsS3Service: AWSS3Service, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's clean up the request.module.ts file if we are removing these. We should not need the AWSS3Module anymore, as well as the Multer one I believe. |
||
| private ordersService: OrdersService, | ||
| ) {} | ||
| constructor(private requestsService: RequestsService) {} | ||
|
|
||
| @Get('/:requestId') | ||
| async getRequest( | ||
|
|
@@ -73,19 +61,6 @@ export class RequestsController { | |
| nullable: true, | ||
| example: 'Urgent request', | ||
| }, | ||
| dateReceived: { | ||
| type: 'string', | ||
| format: 'date-time', | ||
| nullable: true, | ||
| example: null, | ||
| }, | ||
| feedback: { type: 'string', nullable: true, example: null }, | ||
| photos: { | ||
| type: 'array', | ||
| items: { type: 'string' }, | ||
| nullable: true, | ||
| example: [], | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
@@ -96,9 +71,6 @@ export class RequestsController { | |
| requestedSize: RequestSize; | ||
| requestedItems: string[]; | ||
| additionalInformation: string; | ||
| dateReceived: Date; | ||
| feedback: string; | ||
| photos: string[]; | ||
| }, | ||
| ): Promise<FoodRequest> { | ||
| if ( | ||
|
|
@@ -111,84 +83,6 @@ export class RequestsController { | |
| body.requestedSize, | ||
| body.requestedItems, | ||
| body.additionalInformation, | ||
| body.dateReceived, | ||
| body.feedback, | ||
| body.photos, | ||
| ); | ||
| } | ||
|
|
||
| //TODO: delete endpoint, here temporarily as a logic reference for order status impl. | ||
| @Post('/:requestId/confirm-delivery') | ||
| @ApiBody({ | ||
| description: 'Details for a confirmation form', | ||
| schema: { | ||
| type: 'object', | ||
| properties: { | ||
| dateReceived: { | ||
| type: 'string', | ||
| format: 'date-time', | ||
| nullable: true, | ||
| example: new Date().toISOString(), | ||
| }, | ||
| feedback: { | ||
| type: 'string', | ||
| nullable: true, | ||
| example: 'Wonderful shipment!', | ||
| }, | ||
| photos: { | ||
| type: 'array', | ||
| items: { type: 'string' }, | ||
| nullable: true, | ||
| example: [], | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| @UseInterceptors( | ||
| FilesInterceptor('photos', 10, { storage: multer.memoryStorage() }), | ||
| ) | ||
| async confirmDelivery( | ||
| @Param('requestId', ParseIntPipe) requestId: number, | ||
| @Body() body: { dateReceived: string; feedback: string }, | ||
| @UploadedFiles() photos?: Express.Multer.File[], | ||
| ): Promise<FoodRequest> { | ||
| const formattedDate = new Date(body.dateReceived); | ||
| if (isNaN(formattedDate.getTime())) { | ||
| throw new Error('Invalid date format for deliveryDate'); | ||
| } | ||
|
|
||
| const uploadedPhotoUrls = | ||
| photos && photos.length > 0 ? await this.awsS3Service.upload(photos) : []; | ||
| console.log( | ||
| 'Received photo files:', | ||
| photos?.map((p) => p.originalname), | ||
| '| Count:', | ||
| photos?.length, | ||
| ); | ||
|
|
||
| const updatedRequest = await this.requestsService.updateDeliveryDetails( | ||
| requestId, | ||
| formattedDate, | ||
| body.feedback, | ||
| uploadedPhotoUrls, | ||
| ); | ||
|
|
||
| if (!updatedRequest) { | ||
| throw new NotFoundException('Invalid request ID'); | ||
| } | ||
|
|
||
| if (!updatedRequest.orders || updatedRequest.orders.length == 0) { | ||
| throw new NotFoundException( | ||
| 'No associated orders found for this request', | ||
| ); | ||
| } | ||
|
|
||
| await Promise.all( | ||
| updatedRequest.orders.map((order) => | ||
| this.ordersService.updateStatus(order.orderId, OrderStatus.DELIVERED), | ||
| ), | ||
| ); | ||
|
|
||
| return updatedRequest; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,9 @@ const mockRequest: Partial<FoodRequest> = { | |
| requestedItems: ['Canned Goods', 'Vegetables'], | ||
| additionalInformation: 'No onions, please.', | ||
| requestedAt: null, | ||
| dateReceived: null, | ||
| feedback: null, | ||
| photos: null, | ||
| // dateReceived: null, // Removed - no longer on FoodRequest | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, let's just delete everything instead of commenting it out. |
||
| // feedback: null, // Removed - no longer on FoodRequest | ||
| // photos: null, // Removed - no longer on FoodRequest | ||
| orders: null, | ||
| }; | ||
|
|
||
|
|
@@ -250,9 +250,6 @@ describe('RequestsService', () => { | |
| mockRequest.requestedSize, | ||
| mockRequest.requestedItems, | ||
| mockRequest.additionalInformation, | ||
| mockRequest.dateReceived, | ||
| mockRequest.feedback, | ||
| mockRequest.photos, | ||
| ); | ||
|
|
||
| expect(result).toEqual(mockRequest); | ||
|
|
@@ -261,9 +258,6 @@ describe('RequestsService', () => { | |
| requestedSize: mockRequest.requestedSize, | ||
| requestedItems: mockRequest.requestedItems, | ||
| additionalInformation: mockRequest.additionalInformation, | ||
| dateReceived: mockRequest.dateReceived, | ||
| feedback: mockRequest.feedback, | ||
| photos: mockRequest.photos, | ||
| }); | ||
| expect(mockRequestsRepository.save).toHaveBeenCalledWith(mockRequest); | ||
| }); | ||
|
|
@@ -277,9 +271,6 @@ describe('RequestsService', () => { | |
| RequestSize.MEDIUM, | ||
| ['Canned Goods', 'Vegetables'], | ||
| 'Additional info', | ||
| null, | ||
| null, | ||
| null, | ||
| ), | ||
| ).rejects.toThrow(`Pantry ${invalidPantryId} not found`); | ||
|
|
||
|
|
@@ -299,9 +290,9 @@ describe('RequestsService', () => { | |
| requestedItems: ['Rice', 'Beans'], | ||
| additionalInformation: 'Gluten-free items only.', | ||
| requestedAt: null, | ||
| dateReceived: null, | ||
| feedback: null, | ||
| photos: null, | ||
| // dateReceived: null, // Removed | ||
| // feedback: null, // Removed | ||
| // photos: null, // Removed | ||
| orders: null, | ||
| }, | ||
| { | ||
|
|
@@ -311,9 +302,9 @@ describe('RequestsService', () => { | |
| requestedItems: ['Fruits', 'Snacks'], | ||
| additionalInformation: 'No nuts, please.', | ||
| requestedAt: null, | ||
| dateReceived: null, | ||
| feedback: null, | ||
| photos: null, | ||
| // dateReceived: null, // Removed | ||
| // feedback: null, // Removed | ||
| // photos: null, // Removed | ||
| orders: null, | ||
| }, | ||
| ]; | ||
|
|
@@ -332,7 +323,8 @@ describe('RequestsService', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('updateDeliveryDetails', () => { | ||
| // COMMENTED OUT: updateDeliveryDetails method was removed, functionality moved to orders | ||
| /* describe('updateDeliveryDetails', () => { | ||
| it('should update and return the food request with new delivery details', async () => { | ||
| const mockOrder: Partial<Order> = { | ||
| orderId: 1, | ||
|
|
@@ -489,5 +481,5 @@ describe('RequestsService', () => { | |
| relations: ['orders'], | ||
| }); | ||
| }); | ||
| }); | ||
| }); */ | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's actually delete all of these isntead of commenting them out.