Skip to content

Commit

Permalink
filing workflow; cws docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoel committed Sep 25, 2024
1 parent fa50b40 commit e858d9f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
Binary file not shown.
12 changes: 8 additions & 4 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
has,
fetchTradingPartner,
updateSyncMetadata,
filingWorkflow,
} from './utils.js';
import type { LfSyncMetaData } from './utils.js';
import { transform } from './transformers/index.js';
Expand Down Expand Up @@ -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) {
Expand All @@ -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!;

Expand All @@ -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'],
Expand Down
57 changes: 57 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Link>;
export interface LfSyncMetaData {
Expand Down Expand Up @@ -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[];
}

0 comments on commit e858d9f

Please sign in to comment.