diff --git a/Laserfiche MCCi Common Web Service API - Documentation Version 0.5.pdf b/Laserfiche MCCi Common Web Service API - Documentation Version 0.5.pdf new file mode 100644 index 0000000..6bd092f Binary files /dev/null and b/Laserfiche MCCi Common Web Service API - Documentation Version 0.5.pdf differ diff --git a/src/sync.ts b/src/sync.ts index ce40e21..6250169 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -41,6 +41,7 @@ import { has, fetchTradingPartner, updateSyncMetadata, + filingWorkflow, } from './utils.js'; import type { LfSyncMetaData } from './utils.js'; import { transform } from './transformers/index.js'; @@ -150,7 +151,8 @@ export const sync: WorkerFunction = async function ( continue; } - // Let creationDate; + // @ts-expect-error fix later when we get products/locations set up right + let { path, filename } = filingWorkflow(syncMetadata.fields) // Upsert into LF if (syncMetadata.LaserficheEntryID) { @@ -164,7 +166,8 @@ export const sync: WorkerFunction = async function ( ); trace(`Moving the LF document back to _Incoming for filing`); - await moveEntry(syncMetadata.LaserficheEntryID, incomingFolder); + // Use our own filing workflow instead of incomingFolder + await moveEntry(syncMetadata.LaserficheEntryID, path as `/{string}`); // CreationDate = syncMetadata.fields.CreationTime!; @@ -175,8 +178,9 @@ export const sync: WorkerFunction = async function ( const { buffer, mimetype } = await getBuffer(conn, value); trace('Uploading document to Laserfiche'); const lfDocument = await createDocument({ - name: `${document._id}-${key}.${extname(syncMetadata.fields['Original Filename'] ?? '').slice(1)}`, - path: incomingFolder, + //name: `${document._id}-${key}.${extname(syncMetadata.fields['Original Filename'] ?? '').slice(1)}`, + name: filename, + path, mimetype, metadata: syncMetadata.fields || {}, template: syncMetadata.fields['Document Type'], diff --git a/src/utils.ts b/src/utils.ts index 2af3dab..dc48f19 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -28,6 +28,7 @@ import type Resource from '@oada/types/oada/resource.js'; import { BY_LF_PATH, tree } from './tree.js'; import type { DocumentEntry, DocumentId } from './cws/index.js'; import { getEntryId, retrieveDocumentContent } from './cws/index.js'; +import { Path } from './cws/paths.js'; export type VDocList = Record; export interface LfSyncMetaData { @@ -295,3 +296,59 @@ export function getFormattedDate(date: Date): string { return `${month}/${day}/${year} 12:00:00 AM`; } + +export function filingWorkflow(metadata: Metadata): {filename: string, path: Path} { + let { + Entity, + 'Document Type': documentType, + 'Share Mode': shareMode, + Products, + Locations, + 'Expiration Date': expiration, + 'Zendesk Ticket ID': ticketId, +} = metadata; + let location = Locations && Locations.length === 1 + ? Locations[0] + : Locations && Locations.length > 1 + ? 'Multi-Location' + : ''; + + let product = Products && Products.length === 1 + ? Products[0] + : Products && Products.length > 1 + ? 'Multi-Product' + : ''; + + let expire = expiration ? 'EXP_'+new Date(expiration).toISOString().split('T')[0] : undefined; + let ticket = ticketId ? `Ticket${ticketId}` : undefined; + + let path : Path = join( + ...([ + `/FSQA/trellis/trading-partners`, + Entity, + shareMode, + documentType, + ticket + ].filter(i => i) as unknown as string) + ) as unknown as Path; + + let filename = [ + Entity, + location, + product, + documentType, + expire + ].filter(i => i).join('_'); + + return { path, filename } +} + +interface Metadata { + Entity: string; + 'Document Type': string; + 'Share Mode': string; + 'Expiration Date'?: string; + 'Zendesk Ticket ID'?: string; + Products?: string[]; + Locations?: string[]; +} \ No newline at end of file