fix(webhook): add missing tipo_publicacion_id for Appwrite validation
This commit is contained in:
parent
ecf65d4128
commit
694b320d76
@ -129,6 +129,21 @@ export async function POST(req: Request) {
|
||||
fechaVencimiento = getLastDayOfMonth();
|
||||
}
|
||||
|
||||
// Buscar un tipo de publicación por defecto (Requerido por Appwrite Schema)
|
||||
let tipoPublicacionId = '';
|
||||
try {
|
||||
const types = await databases.listDocuments(
|
||||
APPWRITE_ALMEIRA_CONFIG.databaseId,
|
||||
APPWRITE_ALMEIRA_CONFIG.collections.publicationTypes,
|
||||
[]
|
||||
);
|
||||
if (types.documents.length > 0) {
|
||||
tipoPublicacionId = types.documents[0].$id;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('No se pudo obtener un tipo de publicación por defecto:', e);
|
||||
}
|
||||
|
||||
// Crear Post en Appwrite
|
||||
const newPost = await databases.createDocument(
|
||||
APPWRITE_ALMEIRA_CONFIG.databaseId,
|
||||
@ -144,6 +159,7 @@ export async function POST(req: Request) {
|
||||
contenido: parsed.contenido,
|
||||
estado: 'borrador', // Se requiere aprobación
|
||||
fecha_publicacion: new Date().toISOString(),
|
||||
...(tipoPublicacionId && { tipo_publicacion_id: tipoPublicacionId }),
|
||||
...(fechaVencimiento && { fecha_finalizacion: new Date(fechaVencimiento).toISOString() }),
|
||||
...(imageId && { imagen_destacada_id: imageId })
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user