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:
@@ -23,6 +23,8 @@ import { emitToRoom } from '@/lib/socket/server';
|
||||
import { buildListQuery } from '@/lib/db/query-builder';
|
||||
import { diffEntity } from '@/lib/entity-diff';
|
||||
import { softDelete, restore, withTransaction } from '@/lib/db/utils';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { syncEntityFolderName } from '@/lib/services/document-folders.service';
|
||||
import type {
|
||||
CreateClientInput,
|
||||
UpdateClientInput,
|
||||
@@ -529,6 +531,12 @@ export async function updateClient(
|
||||
dispatchWebhookEvent(portId, 'client:updated', { clientId: id }),
|
||||
);
|
||||
|
||||
if (data.fullName !== undefined) {
|
||||
await syncEntityFolderName(portId, 'client', id, meta.userId).catch((err) => {
|
||||
logger.error({ err, clientId: id }, 'Failed to sync client folder name');
|
||||
});
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user