Spaces:
Paused
Paused
File size: 1,064 Bytes
c7a38a3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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;
}
|