@@ -16,50 +16,47 @@ export const patchLetters: APIGatewayProxyHandler = async (event) => {
1616 } ;
1717 }
1818
19- const pathParameters = event . pathParameters || { } ;
20- const letterId = pathParameters [ "id" ] ;
19+ const letterId = event . pathParameters ?. id ;
2120
22- if ( event . path . includes ( '/letters/' ) && letterId ) {
21+ if ( ! letterId ) {
22+ return {
23+ statusCode : 404 ,
24+ body : "Not Found: The requested resource does not exist"
25+ } ;
26+ }
2327
24- if ( ! event . body )
25- {
26- return {
27- statusCode : 400 ,
28- body : "Bad Request: Missing request body"
29- }
28+ if ( ! event . body )
29+ {
30+ return {
31+ statusCode : 400 ,
32+ body : "Bad Request: Missing request body"
3033 }
34+ }
3135
32- const patchLetterRequest : LetterApiDocument = JSON . parse ( event . body ) ;
36+ const patchLetterRequest : LetterApiDocument = JSON . parse ( event . body ) ;
3337
34- try {
38+ try {
3539
36- // TODO CCM-11188: Is it worth retrieving the letter first to check if the status is different?
40+ // TODO CCM-11188: Is it worth retrieving the letter first to check if the status is different?
3741
38- const result = await patchLetterStatus ( patchLetterRequest . data , letterId , supplierId , letterRepo ) ;
42+ const result = await patchLetterStatus ( patchLetterRequest . data , letterId , supplierId , letterRepo ) ;
3943
44+ return {
45+ statusCode : 200 ,
46+ body : JSON . stringify ( result , null , 2 )
47+ } ;
48+ } catch ( error ) {
49+ if ( error instanceof ValidationError ) {
4050 return {
41- statusCode : 200 ,
42- body : JSON . stringify ( result , null , 2 )
51+ statusCode : 400 ,
52+ body : error . message
53+ } ;
54+ } else if ( error instanceof NotFoundError ) {
55+ return {
56+ statusCode : 404 ,
57+ body : error . message
4358 } ;
44- } catch ( error ) {
45- if ( error instanceof ValidationError ) {
46- return {
47- statusCode : 400 ,
48- body : error . message
49- } ;
50- } else if ( error instanceof NotFoundError ) {
51- return {
52- statusCode : 404 ,
53- body : error . message
54- } ;
55- }
56- throw error ;
5759 }
60+ throw error ;
5861 }
59-
60- // TODO CCM-11188: Is this reachable with the API GW?
61- return {
62- statusCode : 404 ,
63- body : 'Not Found: The requested resource does not exist' ,
64- } ;
6562} ;
0 commit comments