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:
@@ -12,6 +12,8 @@ import { withTransaction } from '@/lib/db/utils';
|
||||
import { buildListQuery } from '@/lib/db/query-builder';
|
||||
import { createAuditLog, type AuditMeta } from '@/lib/audit';
|
||||
import { NotFoundError, ConflictError } 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';
|
||||
@@ -181,6 +183,12 @@ export async function updateCompany(
|
||||
changedFields: Object.keys(diff),
|
||||
});
|
||||
|
||||
if (data.name !== undefined) {
|
||||
await syncEntityFolderName(portId, 'company', id, meta.userId).catch((err) => {
|
||||
logger.error({ err, companyId: id }, 'Failed to sync company folder name');
|
||||
});
|
||||
}
|
||||
|
||||
return updated!;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user