Skip to content

Commit 813c409

Browse files
wip
1 parent 520be45 commit 813c409

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { APIGatewayProxyHandler } from "aws-lambda";
2+
import { createLetterRepository } from "../infrastructure/letter-repo-factory";
3+
import { assertNotEmpty, lowerCaseKeys } from "../utils/validation";
4+
import { ApiErrorDetail } from '../contracts/errors';
5+
import { lambdaConfig } from "../config/lambda-config";
6+
import pino from 'pino';
7+
import { mapErrorToResponse } from "../mappers/error-mapper";
8+
import { ValidationError } from "../errors";
9+
10+
const letterRepo = createLetterRepository();
11+
12+
const log = pino();
13+
14+
// The endpoint should only return pending letters for now
15+
const status = "PENDING";
16+
17+
export const getLetters: APIGatewayProxyHandler = async (event) => {
18+
19+
let correlationId;
20+
21+
try {
22+
assertNotEmpty(event.headers, new Error("The request headers are empty"));
23+
const lowerCasedHeaders = lowerCaseKeys(event.headers);
24+
correlationId = assertNotEmpty(lowerCasedHeaders[lambdaConfig.APIM_CORRELATION_HEADER], new Error("The request headers don't contain the APIM correlation id"));
25+
const supplierId = assertNotEmpty(lowerCasedHeaders[lambdaConfig.SUPPLIER_ID_HEADER], new ValidationError(ApiErrorDetail.InvalidRequestMissingSupplierId));
26+
27+
// assert if letter exists and retrieve
28+
// call service
29+
30+
31+
// map response
32+
33+
return {
34+
statusCode: 200,
35+
body: JSON.stringify({}, null, 2),
36+
};
37+
}
38+
catch (error) {
39+
return mapErrorToResponse(error, correlationId);
40+
}
41+
};

lambdas/api-handler/src/services/letter-operations.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ export const patchLetterStatus = async (letterToUpdate: LetterDto, letterId: str
2929

3030
return mapToPatchLetterResponse(updatedLetter);
3131
}
32+
33+
export const getLetterData = async (supplierId: string, letterId: string, letterRepo: LetterRepository): Promise<LetterBase> => {
34+
35+
let letter;
36+
37+
try {
38+
letter = await letterRepo.getLetterById(supplierId, letterId);
39+
} catch (error) {
40+
if (error instanceof Error && /^Letter with id \w+ not found for supplier \w+$/.test(error.message)) {
41+
throw new NotFoundError(ApiErrorDetail.NotFoundLetterId);
42+
}
43+
throw error;
44+
}
45+
46+
47+
}

0 commit comments

Comments
 (0)