fix: resolve js null evaluations in entity relations and add on-the-fly appwrite schema bootstrapping for entity config
This commit is contained in:
parent
b1f00e9d19
commit
a39c059ee2
@ -71,14 +71,39 @@ export async function updateEntityConfig(data: any) {
|
|||||||
revalidatePath('/');
|
revalidatePath('/');
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
const result = await databases.createDocument(
|
try {
|
||||||
DATABASE_ID,
|
const result = await databases.createDocument(
|
||||||
COLLECTION_ID,
|
DATABASE_ID,
|
||||||
SINGLETON_ID,
|
COLLECTION_ID,
|
||||||
parsedData
|
SINGLETON_ID,
|
||||||
);
|
parsedData
|
||||||
revalidatePath('/');
|
);
|
||||||
return result;
|
revalidatePath('/');
|
||||||
|
return result;
|
||||||
|
} catch (createErr: any) {
|
||||||
|
// If the collection genuinely does not exist, auto-create it natively
|
||||||
|
if (createErr?.code === 404 && createErr?.type === 'collection_not_found') {
|
||||||
|
console.log('Colección entity_config no existe. Creando automáticamente...');
|
||||||
|
await databases.createCollection(DATABASE_ID, COLLECTION_ID, 'Configuración de Entidad');
|
||||||
|
await new Promise(r => setTimeout(r, 1500)); // Propagate
|
||||||
|
|
||||||
|
// Create minimal schema attributes lazily, Appwrite handles conflicts on re-runs
|
||||||
|
const textAttrs = ['razon_social', 'logotipo', 'ciudad', 'direccion', 'numero_contacto', 'numero_whatsapp', 'email', 'sitio_web', 'tv_url', 'radio_url', 'facebook_url', 'instagram_url', 'x_url', 'youtube_url', 'telegram_url'];
|
||||||
|
for (const a of textAttrs) {
|
||||||
|
try { await databases.createStringAttribute(DATABASE_ID, COLLECTION_ID, a, 500, false); } catch (e) {}
|
||||||
|
}
|
||||||
|
try { await databases.createBooleanAttribute(DATABASE_ID, COLLECTION_ID, 'mostrar_texto_logo', false, false); } catch(e){}
|
||||||
|
|
||||||
|
console.log('Atributos inyectados. Esperando 3 segundos...');
|
||||||
|
await new Promise(r => setTimeout(r, 3500)); // Wait for attributes to be Available
|
||||||
|
|
||||||
|
const result = await databases.createDocument(DATABASE_ID, COLLECTION_ID, SINGLETON_ID, parsedData);
|
||||||
|
revalidatePath('/');
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
throw createErr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating entity config:', error);
|
console.error('Error updating entity config:', error);
|
||||||
|
|||||||
@ -377,7 +377,7 @@ export const PublicationLayout: React.FC<PublicationLayoutProps> = ({
|
|||||||
options={relationData.tipo_publicacion_id || []}
|
options={relationData.tipo_publicacion_id || []}
|
||||||
labelKey="descripcion"
|
labelKey="descripcion"
|
||||||
value={
|
value={
|
||||||
typeof initialData?.tipo_publicacion_id === 'object'
|
initialData?.tipo_publicacion_id && typeof initialData.tipo_publicacion_id === 'object'
|
||||||
? initialData.tipo_publicacion_id.$id
|
? initialData.tipo_publicacion_id.$id
|
||||||
: initialData?.tipo_publicacion_id || ''
|
: initialData?.tipo_publicacion_id || ''
|
||||||
}
|
}
|
||||||
@ -462,7 +462,7 @@ export const PublicationLayout: React.FC<PublicationLayoutProps> = ({
|
|||||||
options={relationData.cliente_id || []}
|
options={relationData.cliente_id || []}
|
||||||
labelKey="nombre_entidad"
|
labelKey="nombre_entidad"
|
||||||
value={
|
value={
|
||||||
typeof initialData?.cliente_id === 'object'
|
initialData?.cliente_id && typeof initialData.cliente_id === 'object'
|
||||||
? initialData.cliente_id.$id
|
? initialData.cliente_id.$id
|
||||||
: initialData?.cliente_id || ''
|
: initialData?.cliente_id || ''
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user