@@ -2,17 +2,15 @@ import { APIGatewayProxyHandler } from "aws-lambda";
22import { Unit } from "aws-embedded-metrics" ;
33import pino from "pino" ;
44import { MetricEntry , MetricStatus , buildEMFObject } from "@internal/helpers" ;
5- import { postMI as postMIOperation } from "../services/mi-operations" ;
5+ import { getMI as getMIOperation } from "../services/mi-operations" ;
66import { ApiErrorDetail } from "../contracts/errors" ;
77import ValidationError from "../errors/validation-error" ;
88import { processError } from "../mappers/error-mapper" ;
9- import { assertNotEmpty , validateIso8601Timestamp } from "../utils/validation" ;
9+ import { assertNotEmpty } from "../utils/validation" ;
1010import { extractCommonIds } from "../utils/common-ids" ;
11- import { PostMIRequest , PostMIRequestSchema } from "../contracts/mi" ;
12- import { mapToMI } from "../mappers/mi-mapper" ;
1311import { Deps } from "../config/deps" ;
1412
15- export default function createGettMIHandler (
13+ export default function createGetMIHandler (
1614 deps : Deps ,
1715) : APIGatewayProxyHandler {
1816 return async ( event ) => {
@@ -32,34 +30,21 @@ export default function createGettMIHandler(
3230
3331 const { supplierId } = commonIds . value ;
3432 try {
35- const body = assertNotEmpty (
36- event . body ,
37- new ValidationError ( ApiErrorDetail . InvalidRequestMissingBody ) ,
33+ const miId = assertNotEmpty (
34+ event . pathParameters ?. id ,
35+ new ValidationError (
36+ ApiErrorDetail . InvalidRequestMissingMiIdPathParameter ,
37+ ) ,
3838 ) ;
3939
40- let postMIRequest : PostMIRequest ;
41-
42- try {
43- postMIRequest = PostMIRequestSchema . parse ( JSON . parse ( body ) ) ;
44- } catch ( error ) {
45- emitErrorMetric ( supplierId , deps . logger ) ;
46- const typedError =
47- error instanceof Error
48- ? new ValidationError ( ApiErrorDetail . InvalidRequestBody , {
49- cause : error ,
50- } )
51- : error ;
52- throw typedError ;
53- }
54- validateIso8601Timestamp ( postMIRequest . data . attributes . timestamp ) ;
55-
56- const result = await postMIOperation (
57- mapToMI ( postMIRequest , supplierId ) ,
40+ const result = await getMIOperation (
41+ miId ,
42+ supplierId ,
5843 deps . miRepo ,
5944 ) ;
6045
6146 deps . logger . info ( {
62- description : "Posted management information" ,
47+ description : "Retrieved management information" ,
6348 supplierId : commonIds . value . supplierId ,
6449 correlationId : commonIds . value . correlationId ,
6550 } ) ;
@@ -71,18 +56,18 @@ export default function createGettMIHandler(
7156 value : 1 ,
7257 unit : Unit . Count ,
7358 } ;
74- let emf = buildEMFObject ( "postMi " , dimensions , metric ) ;
59+ let emf = buildEMFObject ( "getMi " , dimensions , metric ) ;
7560 deps . logger . info ( emf ) ;
7661
7762 // metric displaying the type/number of lineItems posted per supplier
78- dimensions . lineItem = postMIRequest . data . attributes . lineItem ;
63+ dimensions . lineItem = result . data . attributes . lineItem ;
7964 metric . key = "LineItem per supplier" ;
80- metric . value = postMIRequest . data . attributes . quantity ;
81- emf = buildEMFObject ( "postMi " , dimensions , metric ) ;
65+ metric . value = result . data . attributes . quantity ;
66+ emf = buildEMFObject ( "getMi " , dimensions , metric ) ;
8267 deps . logger . info ( emf ) ;
8368
8469 return {
85- statusCode : 201 ,
70+ statusCode : 200 ,
8671 body : JSON . stringify ( result , null , 2 ) ,
8772 } ;
8873 } catch ( error ) {
@@ -99,6 +84,6 @@ function emitErrorMetric(supplierId: string, logger: pino.Logger) {
9984 value : 1 ,
10085 unit : Unit . Count ,
10186 } ;
102- const emf = buildEMFObject ( "postMi " , dimensions , metric ) ;
87+ const emf = buildEMFObject ( "getMi " , dimensions , metric ) ;
10388 logger . info ( emf ) ;
10489}
0 commit comments