Merge pull request 'FIX: Correção dos Templates quebrados' (#8) from fix/templates into dev
All checks were successful
Deploy Dev — Backend / Deploy para VM Dev (push) Successful in 7s

Reviewed-on: #8
This commit is contained in:
Rafael Alves Lopes 2026-07-24 10:18:39 -03:00
commit d4893be23f
2 changed files with 11 additions and 3 deletions

View File

@ -155,7 +155,7 @@ export class WhatsappTemplateRepository {
`UPDATE whatsapp_templates SET
meta_status = $2,
meta_template_id = COALESCE($3, meta_template_id),
meta_approved_at = CASE WHEN $2 = 'APPROVED' THEN CURRENT_TIMESTAMP ELSE meta_approved_at END,
meta_approved_at = CASE WHEN $2::text = 'APPROVED' THEN CURRENT_TIMESTAMP ELSE meta_approved_at END,
updated_at = CURRENT_TIMESTAMP
WHERE meta_template_name = $1`,
[metaName, metaStatus, metaId || null],
@ -184,8 +184,8 @@ export class WhatsappTemplateRepository {
status, meta_approved_at, updated_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, NULL,
CASE WHEN $7 = 'APPROVED' THEN 'approved' ELSE 'pending' END,
CASE WHEN $7 = 'APPROVED' THEN CURRENT_TIMESTAMP ELSE NULL END,
CASE WHEN $7::text = 'APPROVED' THEN 'approved' ELSE 'pending' END,
CASE WHEN $7::text = 'APPROVED' THEN CURRENT_TIMESTAMP ELSE NULL END,
CURRENT_TIMESTAMP
)
ON CONFLICT (name) DO UPDATE SET

View File

@ -130,14 +130,19 @@ export class WhatsappTemplateService {
return { synced: 0, imported: 0, error: data?.error?.message || 'Erro ao sincronizar' };
}
this.logger.log(`[Meta Templates] Meta retornou ${data.data.length} template(s)`);
let synced = 0;
let imported = 0;
for (const t of data.data) {
const metaId = String(t.id);
this.logger.log(`[Meta Templates] Processando: "${t.name}" status="${t.status}"`);
const updated = await this.repo.updateMetaStatusByName(t.name, t.status, metaId);
if (updated > 0) {
synced++;
this.logger.log(`[Meta Templates] Status atualizado: "${t.name}" → ${t.status}`);
continue;
}
@ -159,12 +164,15 @@ export class WhatsappTemplateService {
if (wasInserted) {
imported++;
this.logger.log(`[Meta Templates] Importado: "${t.name}" (${t.status})`);
} else {
this.logger.log(`[Meta Templates] Ignorado (já existe ou sem alteração): "${t.name}"`);
}
} catch (importErr: any) {
this.logger.warn(`[Meta Templates] Falha ao importar "${t.name}": ${importErr.message}`);
}
}
this.logger.log(`[Meta Templates] Sync concluído: ${synced} atualizado(s), ${imported} importado(s)`);
return { synced, imported };
} catch (err: any) {
this.logger.error('[Meta Templates] Falha na sincronização:', err?.message);