44 LetterStatusType ,
55} from "../../../../internal/datastore/src/types" ;
66import { randomUUID } from "crypto" ;
7- import { createLetter } from "../helpers/create_letter_helpers" ;
7+ import { createLetter , createLetterDto } from "../helpers/create_letter_helpers" ;
88import { createLetterRepository } from "../infrastructure/letter-repo-factory" ;
9+ import { uploadFile } from "../helpers/s3_helpers" ;
910
1011async function main ( ) {
1112 await yargs ( hideBin ( process . argv ) )
@@ -37,6 +38,11 @@ async function main() {
3738 type : "string" ,
3839 demandOption : false ,
3940 } ,
41+ "ttl-hours" : {
42+ type : "number" ,
43+ demandOption : false ,
44+ default : 336 ,
45+ } ,
4046 status : {
4147 type : "string" ,
4248 demandOption : true ,
@@ -67,7 +73,8 @@ async function main() {
6773 : randomUUID ( ) ;
6874 const status = argv . status ;
6975 const environment = argv . environment ;
70- const letterRepository = createLetterRepository ( environment ) ;
76+ const ttlHours = argv . ttlHours ;
77+ const letterRepository = createLetterRepository ( environment , ttlHours ) ;
7178
7279 createLetter ( {
7380 letterId,
@@ -81,6 +88,99 @@ async function main() {
8188 } ) ;
8289 } ,
8390 )
91+ . command (
92+ "create-letter-batch" ,
93+ "Create a batch of letters" ,
94+ {
95+ "supplier-id" : {
96+ type : "string" ,
97+ demandOption : true ,
98+ } ,
99+ environment : {
100+ type : "string" ,
101+ demandOption : true ,
102+ } ,
103+ awsAccountId : {
104+ type : "string" ,
105+ demandOption : true ,
106+ } ,
107+ "group-id" : {
108+ type : "string" ,
109+ demandOption : false ,
110+ } ,
111+ "specification-id" : {
112+ type : "string" ,
113+ demandOption : false ,
114+ } ,
115+ "ttl-hours" : {
116+ type : "number" ,
117+ demandOption : false ,
118+ default : 336 ,
119+ } ,
120+ "count" : {
121+ type : "number" ,
122+ demandOption : true ,
123+ } ,
124+ status : {
125+ type : "string" ,
126+ demandOption : true ,
127+ choices : [
128+ "PENDING" ,
129+ "ACCEPTED" ,
130+ "REJECTED" ,
131+ "PRINTED" ,
132+ "ENCLOSED" ,
133+ "CANCELLED" ,
134+ "DISPATCHED" ,
135+ "FAILED" ,
136+ "RETURNED" ,
137+ "DESTROYED" ,
138+ "FORWARDED" ,
139+ "DELIVERED" ,
140+ ] ,
141+ } ,
142+ } ,
143+ async ( argv ) => {
144+
145+ // set batch ID
146+ const batchId = randomUUID ( ) ;
147+
148+ // parse args
149+ const supplierId = argv . supplierId ;
150+ const groupId = argv . groupId ? argv . groupId : randomUUID ( ) ;
151+ const specificationId = argv . specificationId
152+ ? argv . specificationId
153+ : randomUUID ( ) ;
154+ const status = argv . status ;
155+ const environment = argv . environment ;
156+ const ttlHours = argv . ttlHours ;
157+ const letterRepository = createLetterRepository ( environment , ttlHours ) ;
158+ const count = argv . count ;
159+
160+
161+ // Upload a test file for this batch
162+ const bucketName = `nhs-${ argv . awsAccountId } -eu-west-2-${ argv . environment } -supapi-test-letters` ;
163+ const targetFilename = `${ batchId } -${ status } .pdf` ;
164+ const url = `s3://${ bucketName } /${ batchId } /${ targetFilename } ` ;
165+ await uploadFile ( bucketName , batchId , "../../test_letter.pdf" , targetFilename ) ;
166+
167+ // Create letter DTOs
168+ let letterDtos = [ ] ;
169+ for ( let i = 0 ; i < count ; i ++ ) {
170+ letterDtos . push ( createLetterDto ( {
171+ letterId : randomUUID ( ) ,
172+ supplierId,
173+ groupId,
174+ specificationId,
175+ status : status as LetterStatusType ,
176+ url,
177+ } ) ) ;
178+ } ;
179+
180+ // Upload Letters
181+ await letterRepository . putLetterBatch ( letterDtos ) ;
182+ } ,
183+ )
84184 . demandCommand ( 1 )
85185 . parse ( ) ;
86186}
0 commit comments