FIX: Date format issue for NocoDB PostgreSQL integration
This commit is contained in:
parent
f4f514f1e1
commit
4b3f75d4cf
|
|
@ -15,6 +15,39 @@ export enum Table {
|
|||
Interest = "mbs9hjauug4eseo",
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert date from DD-MM-YYYY format to YYYY-MM-DD format for PostgreSQL
|
||||
*/
|
||||
const convertDateFormat = (dateString: string): string => {
|
||||
if (!dateString) return dateString;
|
||||
|
||||
// If it's already in ISO format or contains 'T', return as is
|
||||
if (dateString.includes('T') || dateString.match(/^\d{4}-\d{2}-\d{2}/)) {
|
||||
return dateString;
|
||||
}
|
||||
|
||||
// Handle DD-MM-YYYY format
|
||||
const ddmmyyyyMatch = dateString.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/);
|
||||
if (ddmmyyyyMatch) {
|
||||
const [, day, month, year] = ddmmyyyyMatch;
|
||||
const convertedDate = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
|
||||
console.log(`[convertDateFormat] Converted ${dateString} to ${convertedDate}`);
|
||||
return convertedDate;
|
||||
}
|
||||
|
||||
// Handle DD/MM/YYYY format
|
||||
const ddmmyyyySlashMatch = dateString.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
|
||||
if (ddmmyyyySlashMatch) {
|
||||
const [, day, month, year] = ddmmyyyySlashMatch;
|
||||
const convertedDate = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
|
||||
console.log(`[convertDateFormat] Converted ${dateString} to ${convertedDate}`);
|
||||
return convertedDate;
|
||||
}
|
||||
|
||||
console.warn(`[convertDateFormat] Could not parse date format: ${dateString}`);
|
||||
return dateString;
|
||||
};
|
||||
|
||||
export const getNocoDbConfiguration = () => {
|
||||
const config = useRuntimeConfig().nocodb;
|
||||
console.log('[nocodb] Configuration URL:', config.url);
|
||||
|
|
@ -150,6 +183,20 @@ export const updateInterest = async (id: string, data: Partial<Interest>, retryC
|
|||
}
|
||||
}
|
||||
|
||||
// Fix date formatting for PostgreSQL
|
||||
if (cleanData['Date Added']) {
|
||||
cleanData['Date Added'] = convertDateFormat(cleanData['Date Added']);
|
||||
}
|
||||
if (cleanData['Created At']) {
|
||||
cleanData['Created At'] = convertDateFormat(cleanData['Created At']);
|
||||
}
|
||||
if (cleanData['EOI Time Sent']) {
|
||||
cleanData['EOI Time Sent'] = convertDateFormat(cleanData['EOI Time Sent']);
|
||||
}
|
||||
if (cleanData['Time LOI Sent']) {
|
||||
cleanData['Time LOI Sent'] = convertDateFormat(cleanData['Time LOI Sent']);
|
||||
}
|
||||
|
||||
console.log('[nocodb.updateInterest] Clean data fields:', Object.keys(cleanData));
|
||||
|
||||
// PATCH requires ID in the body (not in URL)
|
||||
|
|
@ -248,6 +295,14 @@ export const createInterest = async (data: Partial<Interest>) => {
|
|||
delete cleanData["Berth Recommendations"];
|
||||
delete cleanData.Berth;
|
||||
|
||||
// Fix date formatting for PostgreSQL
|
||||
if (cleanData['Date Added']) {
|
||||
cleanData['Date Added'] = convertDateFormat(cleanData['Date Added']);
|
||||
}
|
||||
if (cleanData['Created At']) {
|
||||
cleanData['Created At'] = convertDateFormat(cleanData['Created At']);
|
||||
}
|
||||
|
||||
console.log('[nocodb.createInterest] Clean data fields:', Object.keys(cleanData));
|
||||
const url = createTableUrl(Table.Interest);
|
||||
console.log('[nocodb.createInterest] URL:', url);
|
||||
|
|
|
|||
Loading…
Reference in New Issue