@@ -5,15 +5,23 @@ import {
55  ParseIntPipe , 
66  Post , 
77  Body , 
8+   UploadedFiles , 
9+   UseInterceptors , 
810}  from  '@nestjs/common' ; 
911import  {  ApiBody  }  from  '@nestjs/swagger' ; 
1012import  {  RequestsService  }  from  './request.service' ; 
1113import  {  FoodRequest  }  from  './request.entity' ; 
14+ import  {  AWSS3Service  }  from  '../aws/aws-s3.service' ; 
15+ import  {  FilesInterceptor  }  from  '@nestjs/platform-express' ; 
16+ import  *  as  multer  from  'multer' ; 
1217
1318@Controller ( 'requests' ) 
14- //@UseInterceptors () 
19+ //  @UseInterceptors () 
1520export  class  FoodRequestsController  { 
16-   constructor ( private  requestsService : RequestsService )  { } 
21+   constructor ( 
22+     private  requestsService : RequestsService , 
23+     private  awsS3Service : AWSS3Service , 
24+   )  { } 
1725
1826  @Get ( '/:pantryId' ) 
1927  async  getAllPantryRequests ( 
@@ -84,4 +92,54 @@ export class FoodRequestsController {
8492      body . photos , 
8593    ) ; 
8694  } 
95+ 
96+   @Post ( '/:requestId/confirm-delivery' ) 
97+   @ApiBody ( { 
98+     description : 'Details for a confirmation form' , 
99+     schema : { 
100+       type : 'object' , 
101+       properties : { 
102+         dateReceived : { 
103+           type : 'string' , 
104+           format : 'date-time' , 
105+           nullable : true , 
106+           example : new  Date ( ) . toISOString ( ) , 
107+         } , 
108+         feedback : { 
109+           type : 'string' , 
110+           nullable : true , 
111+           example : 'Wonderful shipment!' , 
112+         } , 
113+         photos : { 
114+           type : 'array' , 
115+           items : {  type : 'string'  } , 
116+           nullable : true , 
117+           example : [ ] , 
118+         } , 
119+       } , 
120+     } , 
121+   } ) 
122+   @UseInterceptors ( 
123+     FilesInterceptor ( 'photos' ,  10 ,  {  storage : multer . memoryStorage ( )  } ) , 
124+   ) 
125+   async  confirmDelivery ( 
126+     @Param ( 'requestId' ,  ParseIntPipe )  requestId : number , 
127+     @Body ( )  body : {  dateReceived : string ;  feedback : string  } , 
128+     @UploadedFiles ( )  photos ?: Express . Multer . File [ ] , 
129+   ) : Promise < FoodRequest >  { 
130+     const  formattedDate  =  new  Date ( body . dateReceived ) ; 
131+     if  ( isNaN ( formattedDate . getTime ( ) ) )  { 
132+       throw  new  Error ( 'Invalid date format for deliveryDate' ) ; 
133+     } 
134+ 
135+     const  uploadedPhotoUrls  = 
136+       photos  &&  photos . length  >  0  ? await  this . awsS3Service . upload ( photos )  : [ ] ; 
137+ 
138+     return  this . requestsService . updateDeliveryDetails ( 
139+       requestId , 
140+       formattedDate , 
141+       body . feedback , 
142+       uploadedPhotoUrls , 
143+     ) ; 
144+   } 
87145} 
0 commit comments