import { ConflictException } from '@nestjs/common'; import type { RestrictionCheck } from '../compliance/restricted-zone'; /** 409 when the colony or an apiary changed between the unlocked read and the lock. */ export function apiaryChangedMeanwhile(): ConflictException { return new ConflictException( 'Der Stand wurde gerade geƤndert. Bitte neu laden.', ); } export const NOT_OVERRIDDEN: RestrictionCheck = { overridden: false, restrictionIds: [], }; /** * The audit trace of an override: only the reason and the restriction ids, * and only when an active restriction was really overridden. Spread into the * audit entry's afterData - never into data written to the colony. */ export function overrideTrace( check: RestrictionCheck, reason: string | null | undefined, ): { restrictionOverride?: { reason: string; restrictionIds: string[] } } { return check.overridden && reason ? { restrictionOverride: { reason, restrictionIds: check.restrictionIds } } : {}; } /** The apiary-history note: the override in front of an existing note. */ export function overrideNote( check: RestrictionCheck, reason: string | null | undefined, note: string | undefined, ): string | undefined { if (!check.overridden || !reason) { return note; } const prefix = `Ausnahme Sperrbezirk: ${reason}`; return note ? `${prefix}\n${note}` : prefix; }