cambios en la interfaz de organizaciones
This commit is contained in:
10
apps/api/src/database/migrations/0019_cuddly_cobalt_man.sql
Normal file
10
apps/api/src/database/migrations/0019_cuddly_cobalt_man.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "commune_spokesperson_cedula" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "commune_spokesperson_cedula" DROP NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "commune_spokesperson_rif" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "commune_spokesperson_rif" DROP NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "commune_email" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "commune_email" DROP NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "communal_council_spokesperson_cedula" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "communal_council_spokesperson_cedula" DROP NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "communal_council_spokesperson_rif" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ALTER COLUMN "communal_council_spokesperson_rif" DROP NOT NULL;
|
||||
2041
apps/api/src/database/migrations/meta/0019_snapshot.json
Normal file
2041
apps/api/src/database/migrations/meta/0019_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -134,6 +134,13 @@
|
||||
"when": 1771855467870,
|
||||
"tag": "0018_milky_prism",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 19,
|
||||
"version": "7",
|
||||
"when": 1771858973096,
|
||||
"tag": "0019_cuddly_cobalt_man",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -262,4 +262,19 @@ export class CreateTrainingDto {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
parish: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
photo1?: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
photo2?: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
photo3?: string;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user