@@ -17,7 +17,8 @@ import {
1717import { ProcessAccessionDocFormTask } from "./ProcessAccessionDocFormTask" ;
1818
1919export type UpdateAllFormsTaskInput = {
20- form : string [ ] ;
20+ readonly form : string [ ] ;
21+ readonly force ?: boolean ;
2122} ;
2223
2324export type UpdateAllFormsTaskOutput = {
@@ -47,40 +48,53 @@ export class UpdateAllFormsTask extends Task<UpdateAllFormsTaskInput, UpdateAllF
4748
4849 const formSet = new Set ( input . form ) ;
4950
50- // Build a set of already-processed (cik:accession_number) keys per form
51- const processedSet = new Set < string > ( ) ;
52- for ( const form of formSet ) {
53- const processed = await processedFilingsRepo . query ( { form } ) ;
54- if ( processed ) {
55- for ( const pf of processed ) {
56- processedSet . add ( `${ pf . cik } :${ pf . accession_number } ` ) ;
51+ const formsToProcess : Filing [ ] = [ ] ;
52+
53+ if ( input . force ) {
54+ // Reprocess all filings for requested forms
55+ for ( const form of formSet ) {
56+ const filings = await filingRepo . query ( { form } ) ;
57+ if ( filings ) {
58+ for ( const f of filings ) {
59+ formsToProcess . push ( f ) ;
60+ }
61+ }
62+ }
63+ } else {
64+ // Build a set of already-processed (cik:accession_number) keys per form
65+ const processedSet = new Set < string > ( ) ;
66+ for ( const form of formSet ) {
67+ const processed = await processedFilingsRepo . query ( { form } ) ;
68+ if ( processed ) {
69+ for ( const pf of processed ) {
70+ processedSet . add ( `${ pf . cik } :${ pf . accession_number } ` ) ;
71+ }
5772 }
5873 }
59- }
6074
61- // Query filings per form and collect only unprocessed ones
62- const missingForms : Filing [ ] = [ ] ;
63- for ( const form of formSet ) {
64- const filings = await filingRepo . query ( { form } ) ;
65- if ( filings ) {
66- for ( const f of filings ) {
67- if ( ! processedSet . has ( ` ${ f . cik } : ${ f . accession_number } ` ) ) {
68- missingForms . push ( f ) ;
75+ // Query filings per form and collect only unprocessed ones
76+ for ( const form of formSet ) {
77+ const filings = await filingRepo . query ( { form } ) ;
78+ if ( filings ) {
79+ for ( const f of filings ) {
80+ if ( ! processedSet . has ( ` ${ f . cik } : ${ f . accession_number } ` ) ) {
81+ formsToProcess . push ( f ) ;
82+ }
6983 }
7084 }
7185 }
7286 }
7387
74- if ( missingForms . length ) {
88+ if ( formsToProcess . length ) {
7589 const wf = context . own ( new Workflow ( ) ) ;
7690 const loop = wf . map ( { concurrencyLimit : 10 } ) ;
7791 loop . pipe ( new ProcessAccessionDocFormTask ( ) ) ;
7892 loop . endMap ( ) ;
7993 await wf . run ( {
80- accessionNumber : missingForms . map ( ( f ) => f . accession_number ) ,
81- cik : missingForms . map ( ( f ) => f . cik ) ,
82- form : missingForms . map ( ( f ) => f . form ! ) ,
83- fileName : missingForms . map ( ( f ) => f . primary_doc . replaceAll ( / ^ ( x s l [ ^ \/ ] + \/ ) / g, "" ) ) ,
94+ accessionNumber : formsToProcess . map ( ( f ) => f . accession_number ) ,
95+ cik : formsToProcess . map ( ( f ) => f . cik ) ,
96+ form : formsToProcess . map ( ( f ) => f . form ! ) ,
97+ fileName : formsToProcess . map ( ( f ) => f . primary_doc . replaceAll ( / ^ ( x s l [ ^ \/ ] + \/ ) / g, "" ) ) ,
8498 } ) ;
8599 }
86100 return { success : true } ;
0 commit comments