-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-108] Pantry food request management backend updates #82
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?
Conversation
dburkhart07
left a comment
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.
Few initial things, but looks pretty good so far
| }); | ||
|
|
||
| if (!requestExists) { | ||
| throw new Error(`Request ${requestId} not found`); |
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.
Can we make this a NotFoundException instead?
| return this.requestsService.find(pantryId); | ||
| } | ||
|
|
||
| @Get('/get-all-order-details/:requestId') |
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.
nit: i think we are trying to move away from putting the CRUD method in the name. Can we change it to /all-order-details/:requestId
|
|
||
| @OneToMany(() => Order, (order) => order.request, { nullable: true }) | ||
| order: Order; | ||
| @OneToMany(() => Order, (order) => order.request) |
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.
Why is this no longer nullable? When we make a new request, this should be able to exist as null until the orders have been assigned to the request, unless I am missing somethin.
| request.dateReceived = deliveryDate; | ||
| request.photos = photos; | ||
| request.order.status = OrderStatus.DELIVERED; | ||
| request.orders.forEach((order) => { |
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.
I know we already had this here, but are we not setting each of the status for the orders to be delivered on line 171 of the request.controller.ts file? I am pretty sure this can be deleted.
| request.order.orderId, | ||
| OrderStatus.DELIVERED, | ||
|
|
||
| await Promise.all( |
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.
Can we move this actually to be after we update the delivery details, and ensure there are no problems there? Once we confirm that, then we can mark all of the orders as delivered.
| export interface OrderItemDetails { | ||
| name: string; | ||
| quantity: number; | ||
| foodType: (typeof FoodTypes)[number]; |
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.
This might be a good time to bring in the FoodTypes enum into the frontend types and use that here. Can we also confirm with @sam-schu whether the food type is supposed to be the corresponding number, or the name? Not really sure what we are hoping to do with this info just yet, but to me I think the actual name makes more sense.
|
|
||
| describe('GET /get-all-order-details/:requestId', () => { | ||
| it('should call requestsService.getOrderDetails and return all associated orders and their details', async () => { | ||
| const mockOrderDetails = [ |
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.
can we type this?
| allocationId: number; | ||
|
|
||
| @Column({ name: 'order_id', type: 'int' }) | ||
| orderId: number; |
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.
thoughts on making this nullable: false the same way itemId is set as they're both FKs with many to one relationship? that way an allocation is set to for sure have an order that it is derived from.
|
|
||
| await Promise.all( | ||
| request.orders.map((order) => | ||
| this.ordersService.updateStatus(order.orderId, OrderStatus.DELIVERED), |
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.
this would update all orders associated with a specific request id to 'delivered' - but when would this be used if orders arrive at different times & need individual confirmation, instead of confirming all orders for a request at the same time
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.
i see in pantry demo vid that pantries confirm deliveries for individual/specific orders instead of for all orders of a request
| }); | ||
|
|
||
| if (!requestExists) { | ||
| throw new Error(`Request ${requestId} not found`); |
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.
not found exception would be more fitting here!
| request.order.status = OrderStatus.DELIVERED; | ||
| request.orders.forEach((order) => { | ||
| order.status = OrderStatus.DELIVERED; | ||
| }); |
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.
duplicate setting state to delivered - this.ordersService.updateStatus(order.orderId, OrderStatus.DELIVERED) in request.controller already calls on order service to update these statuses to delivered
| requestId: number, | ||
| ): Promise<OrderDetails[]> { | ||
| return this.axiosInstance.get( | ||
| `api/requests/get-all-order-details/${requestId}`, |
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.
nit but for sake of consistency, can we add / in front of the path? - either way works bc axios uses relative path, but good to set standard in case baseurl changes
ℹ️ Issue
Closes https://vidushimisra.atlassian.net/browse/SSF-108
📝 Description
In terms of code changes it was mainly defining the new backend route and writing tests for that. The backend route I added is:
@get('/get-all-order-details/:requestId'). I also had to do some refactoring to transition from one associated order to a list of them.
Also, right now the request management page is outdated. For one, it is still associating one order with one request and for another, request management and order management is now being split into to pages. I had to refactor this outdated page for the updated request type and I chose to simply use the first order in the orders list (orders[0]) and have everything else be the same. Thus, this page does not work as intended but it can still be loaded. This change is just a placeholder for now, the new design pages will take over. The associated route is: request-form/:pantryId
✔️ Verification
I used swagger to verify my backend route worked as expected and I wrote some jest tests to ensure this. I added controller and service tests for the @get('/get-all-order-details/:requestId') route.
🏕️ (Optional) Future Work / Notes
The request form frontend is outdated and my refactoring of it to account for the orders list is just a placeholder. This will be overwritten in the future.