no update fechas

Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
Omar Sánchez Pizarro
2026-01-20 12:04:24 +01:00
parent 38d644da1f
commit 63481b500d
3 changed files with 73 additions and 30 deletions

View File

@@ -744,29 +744,47 @@ export async function saveArticle(articleData) {
);
if (existingUserInfoIndex >= 0) {
// Actualizar user_info existente
// Actualizar user_info existente pero mantener notified_at original
existingUserInfo[existingUserInfoIndex] = {
...existingUserInfo[existingUserInfoIndex],
worker_name: worker_name || existingUserInfo[existingUserInfoIndex].worker_name,
notified: true,
notified_at: new Date(),
// NO actualizar notified_at, mantener el valor existente
};
} else {
// Añadir nuevo user_info
existingUserInfo.push(userInfoEntry);
}
await articlesCollection.updateOne(
{ platform, id },
{
$set: {
...articleFields,
user_info: existingUserInfo,
expiresAt,
updatedAt: new Date(),
// Solo actualizar precio si es diferente, no actualizar fechas de notificación
const existingPrice = existing.price;
const newPrice = articleFields.price;
if (existingPrice === newPrice) {
// Si el precio es el mismo, solo actualizar user_info
await articlesCollection.updateOne(
{ platform, id },
{
$set: {
user_info: existingUserInfo,
}
}
}
);
);
} else {
// Precio diferente, actualizar artículo completo
// Mantener updatedAt para saber cuándo cambió el precio
// pero NO actualizar notified_at (ya se mantiene arriba)
await articlesCollection.updateOne(
{ platform, id },
{
$set: {
...articleFields,
user_info: existingUserInfo,
expiresAt,
updatedAt: new Date(),
}
}
);
}
} else {
// Artículo nuevo, crear con user_info
await articlesCollection.insertOne({