mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 22:30:55 +00:00
21 lines
837 B
TypeScript
21 lines
837 B
TypeScript
/**
|
|
* Settings of `ownerId` that are not in `existingPairs` (`"<ownerId>:<key>"`)
|
|
* yet. This is what keeps the IAM baseline seed idempotent: `organization_settings`
|
|
* and `unit_settings` have no unique index on (owner, key), so a plain re-insert
|
|
* — or the package seeder's upsert-on-id, which never supplies an id — silently
|
|
* duplicates every row.
|
|
*
|
|
* `value: null` becomes `undefined` so the column default applies on insert.
|
|
*/
|
|
export function missingSettings<
|
|
TSetting extends { key: string; value?: string | null },
|
|
>(
|
|
defaults: TSetting[],
|
|
existingPairs: Set<string>,
|
|
ownerId: string,
|
|
): (Omit<TSetting, "value"> & { value?: string })[] {
|
|
return defaults
|
|
.filter((setting) => !existingPairs.has(`${ownerId}:${setting.key}`))
|
|
.map((setting) => ({ ...setting, value: setting.value ?? undefined }));
|
|
}
|