nuevas correciones al formulario y esquema base de datos para osp
This commit is contained in:
@@ -107,17 +107,7 @@ export class TrainingService {
|
||||
// 2. Total Productores (Columna plana que mantuviste)
|
||||
this.drizzle
|
||||
.select({
|
||||
sum: sql<number>`
|
||||
SUM(
|
||||
(
|
||||
SELECT SUM(
|
||||
COALESCE((item->>'menCount')::int, 0) +
|
||||
COALESCE((item->>'womenCount')::int, 0)
|
||||
)
|
||||
FROM jsonb_array_elements(${trainingSurveys.productList}) as item
|
||||
)
|
||||
)
|
||||
`,
|
||||
sum: sql<number>`SUM(${trainingSurveys.womenCount} + ${trainingSurveys.menCount})`,
|
||||
})
|
||||
.from(trainingSurveys)
|
||||
.where(whereCondition),
|
||||
@@ -244,20 +234,25 @@ export class TrainingService {
|
||||
private async deleteFile(fileUrl: string) {
|
||||
if (!fileUrl) return;
|
||||
|
||||
// Extract object name from URL
|
||||
// URL format: http://endpoint:port/bucket/folder/filename
|
||||
// Or it could be just the path if we decided that.
|
||||
// Assuming fileUrl is the full public URL from getPublicUrl
|
||||
try {
|
||||
const url = new URL(fileUrl);
|
||||
const pathname = url.pathname; // /bucket/folder/filename
|
||||
const parts = pathname.split('/');
|
||||
// parts[0] is '', parts[1] is bucket, parts[2..] is objectName
|
||||
const objectName = parts.slice(2).join('/');
|
||||
// If it's a full URL, we need to extract the part after the bucket name
|
||||
if (fileUrl.startsWith('http')) {
|
||||
const url = new URL(fileUrl);
|
||||
const pathname = url.pathname; // /bucket/folder/filename
|
||||
const parts = pathname.split('/').filter(Boolean); // ['bucket', 'folder', 'filename']
|
||||
|
||||
await this.minioService.delete(objectName);
|
||||
// The first part is the bucket name, the rest is the object name
|
||||
if (parts.length >= 2) {
|
||||
const objectName = parts.slice(1).join('/');
|
||||
await this.minioService.delete(objectName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If it's not a URL or doesn't match the expected format, pass it as is
|
||||
await this.minioService.delete(fileUrl);
|
||||
} catch (error) {
|
||||
// If it's not a valid URL, maybe it's just the object name stored from before
|
||||
// Fallback if URL parsing fails
|
||||
await this.minioService.delete(fileUrl);
|
||||
}
|
||||
}
|
||||
@@ -292,6 +287,9 @@ export class TrainingService {
|
||||
state: Number(state) ?? null,
|
||||
municipality: Number(municipality) ?? null,
|
||||
parish: Number(parish) ?? null,
|
||||
hasTransport: rest.hasTransport === 'true' ? true : false,
|
||||
isOpenSpace: rest.isOpenSpace === 'true' ? true : false,
|
||||
isExporting: rest.isExporting === 'true' ? true : false,
|
||||
createdBy: userId,
|
||||
updatedBy: userId,
|
||||
})
|
||||
@@ -359,6 +357,12 @@ export class TrainingService {
|
||||
|
||||
// actualizamos el id del usuario que actualizo el registro
|
||||
updateData.updatedBy = userId;
|
||||
updateData.hasTransport =
|
||||
updateTrainingDto.hasTransport === 'true' ? true : false;
|
||||
updateData.isOpenSpace =
|
||||
updateTrainingDto.isOpenSpace === 'true' ? true : false;
|
||||
updateData.isExporting =
|
||||
updateTrainingDto.isExporting === 'true' ? true : false;
|
||||
|
||||
const [updatedRecord] = await this.drizzle
|
||||
.update(trainingSurveys)
|
||||
@@ -402,8 +406,7 @@ export class TrainingService {
|
||||
|
||||
// const records = await this.drizzle
|
||||
// .select({
|
||||
// firstname: trainingSurveys.firstname,
|
||||
// lastname: trainingSurveys.lastname,
|
||||
// coorFullName: trainingSurveys.coorFullName,
|
||||
// visitDate: trainingSurveys.visitDate,
|
||||
// stateName: states.name,
|
||||
// municipalityName: municipalities.name,
|
||||
@@ -451,8 +454,7 @@ export class TrainingService {
|
||||
// const dateStr = date.toLocaleDateString('es-VE');
|
||||
// const timeStr = date.toLocaleTimeString('es-VE');
|
||||
|
||||
// sheet.cell(`A${currentRow}`).value(record.firstname);
|
||||
// sheet.cell(`B${currentRow}`).value(record.lastname);
|
||||
// sheet.cell(`A${currentRow}`).value(record.coorFullName);
|
||||
// sheet.cell(`C${currentRow}`).value(dateStr);
|
||||
// sheet.cell(`D${currentRow}`).value(timeStr);
|
||||
// sheet.cell(`E${currentRow}`).value(record.stateName || '');
|
||||
|
||||
Reference in New Issue
Block a user