2026-08-29 21:06:30 +03:30
|
|
|
import { Prisma } from '@prisma/client';
|
|
|
|
|
|
|
|
|
|
export function asCustomFields(value: unknown): Record<string, unknown> {
|
|
|
|
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
|
|
|
return value as Record<string, unknown>;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function toJsonCustomFields(
|
|
|
|
|
value?: Record<string, unknown> | null,
|
|
|
|
|
): Prisma.InputJsonValue {
|
|
|
|
|
return (value ?? {}) as Prisma.InputJsonValue;
|
|
|
|
|
}
|
2026-10-03 12:29:11 +03:30
|
|
|
|
|
|
|
|
export function asAddresses(value: unknown): string[] {
|
|
|
|
|
if (!Array.isArray(value)) return [];
|
|
|
|
|
const out: string[] = [];
|
|
|
|
|
for (const item of value) {
|
|
|
|
|
const text = String(item ?? '').trim();
|
|
|
|
|
if (text && !out.includes(text)) out.push(text);
|
|
|
|
|
if (out.length >= 20) break;
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function toJsonAddresses(value?: string[] | null): Prisma.InputJsonValue {
|
|
|
|
|
return asAddresses(value ?? []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Collect address-like cells from an excel row into a unique list. */
|
|
|
|
|
export function collectAddresses(...parts: Array<string | undefined | null>): string[] {
|
|
|
|
|
return asAddresses(parts.map((p) => (p ?? '').trim()).filter(Boolean));
|
|
|
|
|
}
|