Conversation
dburkhart07
left a comment
There was a problem hiding this comment.
Some initial comments. Good first pass though! 🥇
apps/backend/src/migrations/1770571145350-MoveRequestFieldsToOrders.ts
Outdated
Show resolved
Hide resolved
| }) | ||
| deliveredAt: Date | null; | ||
|
|
||
| @Column({ name: 'date_received', type: 'timestamp', nullable: true }) |
There was a problem hiding this comment.
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.
dburkhart07
left a comment
There was a problem hiding this comment.
few more small things. looks great so far!!
dburkhart07
left a comment
There was a problem hiding this comment.
few more things, and just some questions that i wanted your opinions on. looking beautiful so far ⛱️
| }) | ||
| deliveredAt: Date | null; | ||
|
|
||
| @Column({ name: 'date_received', type: 'timestamp', nullable: true }) |
| feedback?: string | null; | ||
|
|
||
| @Column({ name: 'photos', type: 'text', array: true, nullable: true }) | ||
| photos?: string[]; |
There was a problem hiding this comment.
another thing tarun had put and dalton asked to be removed, i agree with dalton here as ? implies the value can be undefined so | null isn't necessary, it also wouldn't be consistent with how the rest of the code base handles nullable fields
There was a problem hiding this comment.
In Justin's strict mode PR, we're adding | null to entity fields corresponding to nullable database fields because we realized that TypeORM actually returns null, not undefined, for a null database entry. (The undefined option should only be used if you want to call a repo function with a subset of the entity fields)
| @@ -0,0 +1,4 @@ | |||
| export class ConfirmDeliveryDto { | |||
There was a problem hiding this comment.
Can we use class-validator to validate the fields in this DTO, as we have for other endpoint body DTOs?
| dateReceived: { | ||
| type: 'string', | ||
| format: 'date-time', | ||
| nullable: true, |
There was a problem hiding this comment.
Pending confirmation from Priya, but assuming the date received is required as it is in the DTO, this should not be nullable here
There was a problem hiding this comment.
We can assume this for now as it may need to change later based on client updates
| @@ -1,5 +1,6 @@ | |||
| import { Injectable } from '@nestjs/common'; | |||
| import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; | |||
| import 'multer'; | |||
There was a problem hiding this comment.
Is this necessary since there were no other changes to this file?
|
|
||
| async confirmDelivery( | ||
| orderId: number, | ||
| dto: ConfirmDeliveryDto, |
There was a problem hiding this comment.
Can we pass in the individual fields rather than the DTO to limit the DTO to the controller layer?
There was a problem hiding this comment.
This is how Tarun originally had it, Dalton said in his review that this is not how ssf does it. I agree with you that it would generally be the case that you would want to limit the DTO to the controller layer, but overall looking at the repository it seems like DTOs are almost always passed into the service (according to Dalton this is true, I briefly looked through most of the controllers and this tends to be true). I think we should just be consistent with how this is done on the project and leave it as is
There was a problem hiding this comment.
I'm fine with that for consistency, I think that started with service functions that would need to take in an impractical number of parameters (e.g., for pantry applications) and ended up spreading to almost all of our DTOs
| { dateReceived: new Date().toISOString(), feedback: 'test' }, | ||
| [], | ||
| ), | ||
| ).rejects.toThrow(`Order ${invalidOrderId} not found`); |
There was a problem hiding this comment.
Can we check this is a NotFoundException?
| { dateReceived: 'invalid-date', feedback: 'test feedback' }, | ||
| [], | ||
| ), | ||
| ).rejects.toThrow('Invalid date format for dateReceived'); |
There was a problem hiding this comment.
Can we check this is a BadRequestException?
| it('should throw BadRequestException when order is not shipped', async () => { | ||
| const orderRepo = testDataSource.getRepository(Order); | ||
|
|
||
| const pendingOrder = await orderRepo.findOne({ |
There was a problem hiding this comment.
Can we also check that we can't re-confirm a delivered order?
| const orderRepo = testDataSource.getRepository(Order); | ||
| const requestRepo = testDataSource.getRepository(FoodRequest); | ||
|
|
||
| const shippedOrder = await orderRepo.findOne({ |
There was a problem hiding this comment.
Can we get a specific order here? this implies that any shipped order will work for this test, which is not true since we're checking that the request is being closed
| expect(updatedRequest.status).toBe(FoodRequestStatus.ACTIVE); | ||
| }); | ||
|
|
||
| it('should set request status to CLOSED when all orders are delivered', async () => { |
There was a problem hiding this comment.
I'm not quite sure what the difference is in what we're checking in these two tests compared to the two previous tests?
There was a problem hiding this comment.
Yeah looks like 1 and 3 are pretty much the same, 2 is different because it is a case where there are more orders in the request
There was a problem hiding this comment.
Isn't 4 ("should set request status to ACTIVE when not all orders are delivered") also checking essentially the same thing as 2?
ℹ️ 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:
✔️ Verification