-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcreate_letter_helpers.ts
More file actions
84 lines (77 loc) · 1.94 KB
/
create_letter_helpers.ts
File metadata and controls
84 lines (77 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
LetterRepository,
Letter,
LetterStatusType,
} from "@internal/datastore";
import { uploadFile } from "./s3_helpers";
export async function createLetter(params: {
letterId: string;
bucketName: string;
supplierId: string;
targetFilename: string;
specificationId: string;
groupId: string;
status: LetterStatusType;
letterRepository: LetterRepository;
testLetter: string;
}) {
const {
bucketName,
groupId,
letterId,
letterRepository,
specificationId,
status,
supplierId,
targetFilename,
testLetter,
} = params;
if (testLetter !== "none") {
await uploadFile(
bucketName,
supplierId,
`${testLetter}.pdf`,
targetFilename,
);
}
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
id: letterId,
supplierId,
specificationId,
groupId,
url: `s3://${bucketName}/${supplierId}/${targetFilename}`,
status,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
source: "/data-plane/letter-rendering/letter-test-data",
subject: `supplier-api/letter-test-data/${letterId}`,
billingRef: specificationId
};
const letterRecord = await letterRepository.putLetter(letter);
console.log(letterRecord);
}
export function createLetterDto(params: {
letterId: string;
supplierId: string;
specificationId: string;
groupId: string;
status: LetterStatusType;
url: string;
}) {
const { groupId, letterId, specificationId, status, supplierId, url } =
params;
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
id: letterId,
supplierId,
specificationId,
groupId,
url,
status,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
source: "/data-plane/letter-rendering/letter-test-data",
subject: `supplier-api/letter-test-data/${letterId}`,
billingRef: specificationId
};
return letter;
}