11import { GetCommand } from "@aws-sdk/lib-dynamodb" ;
22import { AwsServicesConnector } from "@lib/integration/awsServicesConnector.js" ;
3- import type {
4- FormSubmission ,
3+ import {
4+ type FormSubmission ,
55 FormSubmissionStatus ,
66} from "@lib/vault/types/formSubmission.js" ;
77import { logMessage } from "@lib/logging/logger.js" ;
@@ -17,9 +17,9 @@ export async function getFormSubmission(
1717 TableName : "Vault" ,
1818 Key : { FormID : formId , NAME_OR_CONF : `NAME#${ submissionName } ` } ,
1919 ProjectionExpression :
20- "CreatedAt,#status ,ConfirmationCode,FormSubmission,FormSubmissionHash" ,
20+ "CreatedAt,#statusCreatedAtKey ,ConfirmationCode,FormSubmission,FormSubmissionHash" ,
2121 ExpressionAttributeNames : {
22- "#status " : "Status" ,
22+ "#statusCreatedAtKey " : "Status#CreatedAt " ,
2323 } ,
2424 } ) ,
2525 ) ;
@@ -44,9 +44,32 @@ function formSubmissionFromDynamoDbResponse(
4444) : FormSubmission {
4545 return {
4646 createdAt : response . CreatedAt as number ,
47- status : response . Status as FormSubmissionStatus ,
47+ status : formSubmissionStatusFromStatusCreatedAt (
48+ response [ "Status#CreatedAt" ] as string ,
49+ ) ,
4850 confirmationCode : response . ConfirmationCode as string ,
4951 answers : response . FormSubmission as string ,
5052 checksum : response . FormSubmissionHash as string ,
5153 } ;
5254}
55+
56+ function formSubmissionStatusFromStatusCreatedAt (
57+ statusCreatedAtValue : string ,
58+ ) : FormSubmissionStatus {
59+ const status = statusCreatedAtValue . split ( "#" ) [ 0 ] ;
60+
61+ switch ( status ) {
62+ case "New" :
63+ return FormSubmissionStatus . New ;
64+ case "Downloaded" :
65+ return FormSubmissionStatus . Downloaded ;
66+ case "Confirmed" :
67+ return FormSubmissionStatus . Confirmed ;
68+ case "Problem" :
69+ return FormSubmissionStatus . Problem ;
70+ default :
71+ throw new Error (
72+ `Unsupported Status#CreatedAt value. Value = ${ statusCreatedAtValue } .` ,
73+ ) ;
74+ }
75+ }
0 commit comments