Skip to content

[SSF-125] Move Food Request Fields#100

Open
Tarun-Nagesh wants to merge 3 commits intomainfrom
TN/SSF-125-move-food-request-fields
Open

[SSF-125] Move Food Request Fields#100
Tarun-Nagesh wants to merge 3 commits intomainfrom
TN/SSF-125-move-food-request-fields

Conversation

@Tarun-Nagesh
Copy link

ℹ️ Issue

Closes SSF-125

📝 Description

Moved delivery confirmation fields from Food Requests to Orders and implemented request status logic. This change reflects where delivery details are specific to individual orders instead of the entire request.

Backend Changes:

  1. Created TypeORM migration to move dateReceived, feedback, and photos fields from food_requests table to orders table
  2. Added status field to FoodRequest entity with enum values ACTIVE and CLOSED
  3. Moved confirm delivery endpoint from requests to orders: POST /api/orders/:orderId/confirm-delivery (previously POST /api/requests/:requestId/confirm-delivery)
  4. Implemented automatic request status updates - request closes when all its orders are delivered
  5. Fixed TypeScript compilation by defining local MulterFile interface in aws-s3.service.ts (could be changed later with tsconfig fix instead)

✔️ Verification

  1. Ran migration with yarn typeorm:migrate
  2. Tested confirm delivery endpoint via PowerShell
  3. All tests passing (added new tests for confirm delivery logic)

Copy link

@dburkhart07 dburkhart07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments. Good first pass though! 🥇

mockRequestsService.find.mockReset();
mockRequestsService.create.mockReset();
mockRequestsService.updateDeliveryDetails?.mockReset();
// mockRequestsService.updateDeliveryDetails?.mockReset(); // Removed - method no longer exists

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.

export class RequestsController {
constructor(
private requestsService: RequestsService,
private awsS3Service: AWSS3Service,

Choose a reason for hiding this comment

The 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.

dateReceived: null,
feedback: null,
photos: null,
// dateReceived: null, // Removed - no longer on FoodRequest

Choose a reason for hiding this comment

The 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.

LARGE = 'Large (10+ boxes)',
}

export enum FoodRequestStatus {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bring this enum into the frontend types as well. While we are at it, can we also rewrite the frontend FoodRequest type, and briefly smoke test the entire app to make sure nothing is broken by us changing the frontend type?


public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE food_requests_status_enum AS ENUM ('Active', 'Closed');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit: can we ask sam/yurika about the capitalization here? our enums are normally always lowercase, so it seems weird to change it here.

@UseInterceptors(
FilesInterceptor('photos', 10, { storage: multer.memoryStorage() }),
)
async confirmDelivery(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migth have a bit more to it, but can we create a DTO for these 3 fields and use it in the confirm delivery here? Not quite sure what the photos would look like in the DTO, but would be much cleaner.

})
deliveredAt: Date | null;

@Column({ name: 'date_received', type: 'timestamp', nullable: true })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to enforce strict type, so we need to give everything a ! for required fields, and ? for optional. So let's add 3 ?s here.

return updatedOrder;
}

private async updateRequestStatus(requestId: number): Promise<void> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure to validate the requestId first.

throw new NotFoundException(`Request ${requestId} not found`);
}

const orders = request.orders || [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we have no orders for a function like this, we should be throwing an error. This function should never be getting called on a request with no orders.

order.feedback = feedback;
order.photos = photos;
order.status = OrderStatus.DELIVERED;
order.deliveredAt = dateReceived;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field doesn't make sense to me. Good question for @sam-schu or @Yurika-Kan what is the difference between dateReceived and the deliveredAt date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants