forked from Yara724/api
Fix workflow steps
This commit is contained in:
@@ -1,5 +1,55 @@
|
||||
import { ResendItemType } from "./resendItemType.enum";
|
||||
|
||||
const RESEND_ITEM_VALUES = new Set<string>(Object.values(ResendItemType));
|
||||
|
||||
/**
|
||||
* Map multipart / client field names and DB typos to canonical {@link ResendItemType} values.
|
||||
*/
|
||||
export function normalizeResendRequestedItemKey(raw: string): string | null {
|
||||
const t = String(raw ?? "").trim();
|
||||
if (!t) return null;
|
||||
if (RESEND_ITEM_VALUES.has(t)) return t;
|
||||
const lower = t.toLowerCase();
|
||||
for (const v of RESEND_ITEM_VALUES) {
|
||||
if (v.toLowerCase() === lower) return v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Deduplicated list of valid requested item keys. */
|
||||
export function normalizeResendRequestedItemsList(
|
||||
items: string[] | undefined | null,
|
||||
): string[] {
|
||||
const out: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const raw of items || []) {
|
||||
const c = normalizeResendRequestedItemKey(String(raw));
|
||||
if (c && !seen.has(c)) {
|
||||
seen.add(c);
|
||||
out.push(c);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone `uploadedDocuments` from a Mongoose subdoc (plain object or Map) into a plain object
|
||||
* so merges and {@link isResendPartyItemSatisfied} see existing keys.
|
||||
*/
|
||||
export function cloneResendUploadedDocuments(
|
||||
raw: unknown,
|
||||
): Record<string, unknown> {
|
||||
if (raw == null || typeof raw !== "object") return {};
|
||||
if (raw instanceof Map) {
|
||||
const o: Record<string, unknown> = {};
|
||||
for (const [k, v] of raw.entries()) {
|
||||
o[String(k)] = v;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return { ...(raw as Record<string, unknown>) };
|
||||
}
|
||||
|
||||
/** How the mobile/web client should collect each resend item (no workflow-step manager). */
|
||||
export type ResendItemInputKind = "document_camera" | "voice" | "video" | "text";
|
||||
|
||||
@@ -11,7 +61,8 @@ export function getResendItemInputKind(item: string): ResendItemInputKind {
|
||||
}
|
||||
|
||||
export function buildResendItemsWithUi(requestedItems: string[]) {
|
||||
return requestedItems.map((item) => ({
|
||||
const normalized = normalizeResendRequestedItemsList(requestedItems);
|
||||
return normalized.map((item) => ({
|
||||
item,
|
||||
inputKind: getResendItemInputKind(item),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user