prevision / apps /prevision-api /src /catalog /admin-catalog.ts
github-actions[bot]
Automated Deploy: 6d2e55112e3ada832d411bd3301a883ce9eba3a9
c7a38a3
Raw History Blame Contribute Delete
1.06 kB
import type { CatalogEntry } from './interfaces/catalog-entry.interface.js';
/**
* Checks an admin-only supplier catalog before it is imported: every entry must be
* `visibility: "admin"`, and no slug may collide with the public catalog (an upsert
* would otherwise turn a public tile into a hidden one, or the other way round).
*/
export function adminCatalogProblems(entries: CatalogEntry[], publicCatalog: CatalogEntry[]): string[] {
const publicSlugs = new Set(publicCatalog.map((entry) => entry.slug));
const seen = new Set<string>();
const problems: string[] = [];
for (const entry of entries) {
if (entry.visibility !== 'admin') problems.push(`${entry.slug}: visibility must be "admin"`);
if (publicSlugs.has(entry.slug)) problems.push(`${entry.slug}: slug is already in the public catalog`);
if (seen.has(entry.slug)) problems.push(`${entry.slug}: duplicate slug`);
if (!entry.brand || !entry.organization) problems.push(`${entry.slug}: brand and organization are required`);
seen.add(entry.slug);
}
return problems;
}