feat(documents): syncEntityFolderName + entity-rename hooks
Per-entity subfolder names mirror the entity's current display string. Wired into updateClient / updateCompany / updateYacht; runs only when the name field changes. Best-effort (logged + swallowed) so a folder- sync error never fails an entity update. Preserves the (archived) suffix when present; skips entirely when the folder has been demoted to (deleted) — the rep owns the name at that point. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import type { Yacht } from '@/lib/db/schema/yachts';
|
||||
import { companies } from '@/lib/db/schema/companies';
|
||||
import { createAuditLog, type AuditMeta } from '@/lib/audit';
|
||||
import { NotFoundError, ValidationError } from '@/lib/errors';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { syncEntityFolderName } from '@/lib/services/document-folders.service';
|
||||
import { emitToRoom } from '@/lib/socket/server';
|
||||
import { setEntityTags } from '@/lib/services/entity-tags.helper';
|
||||
import { diffEntity } from '@/lib/entity-diff';
|
||||
@@ -161,6 +163,12 @@ export async function updateYacht(
|
||||
changedFields: Object.keys(diff),
|
||||
});
|
||||
|
||||
if (data.name !== undefined) {
|
||||
await syncEntityFolderName(portId, 'yacht', id, meta.userId).catch((err) => {
|
||||
logger.error({ err, yachtId: id }, 'Failed to sync yacht folder name');
|
||||
});
|
||||
}
|
||||
|
||||
return updated!;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user