cambios en la interfaz de organizaciones

This commit is contained in:
2026-02-23 12:40:30 -04:00
parent e149500735
commit 0efd5a11bd
12 changed files with 2427 additions and 265 deletions

View File

@@ -313,27 +313,41 @@ export class TrainingService {
// Handle photo updates/removals
const photoFields = ['photo1', 'photo2', 'photo3'] as const;
// 1. If we have NEW files, they replace any old files or occupy empty slots
if (photoPaths.length > 0) {
photoPaths.forEach((newPath, idx) => {
const fieldName = photoFields[idx];
const oldPath = currentRecord[fieldName];
if (oldPath && oldPath !== newPath) {
this.deleteFile(oldPath);
}
updateData[fieldName] = newPath;
});
}
// 2. If the user explicitly cleared a photo field (updateData.photoX === '')
// 1. First, handle explicit deletions (where field is '')
photoFields.forEach((field) => {
if (updateData[field] === '') {
const oldPath = currentRecord[field];
if (oldPath) this.deleteFile(oldPath);
updateData[field] = null; // Set to null in DB
updateData[field] = null;
}
});
// 2. We need to find which slots are currently "available" (null) after deletions
// and which ones have existing URLs that we want to keep.
// Let's determine the final state of the 3 slots.
const finalPhotos: (string | null)[] = [
updateData.photo1 !== undefined ? updateData.photo1 : currentRecord.photo1,
updateData.photo2 !== undefined ? updateData.photo2 : currentRecord.photo2,
updateData.photo3 !== undefined ? updateData.photo3 : currentRecord.photo3,
];
// 3. Fill the available (null) slots with NEW photo paths
if (photoPaths.length > 0) {
let photoPathIdx = 0;
for (let i = 0; i < 3 && photoPathIdx < photoPaths.length; i++) {
if (!finalPhotos[i]) {
finalPhotos[i] = photoPaths[photoPathIdx];
photoPathIdx++;
}
}
}
// Assign back to updateData
updateData.photo1 = finalPhotos[0];
updateData.photo2 = finalPhotos[1];
updateData.photo3 = finalPhotos[2];
if (updateTrainingDto.visitDate) {
updateData.visitDate = new Date(updateTrainingDto.visitDate);
}