mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
fix: melhora o tratamento de erros e otimiza a consulta de IDs de origem no Chatwoot
This commit is contained in:
parent
3459d61eff
commit
0b2d8a752f
@ -177,25 +177,26 @@ class ChatwootImport {
|
|||||||
return existingSourceIdsSet;
|
return existingSourceIdsSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); // Make sure the sourceId is always formatted as WAID:1234567890
|
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`);
|
||||||
let query: string;
|
|
||||||
if (conversationId) {
|
|
||||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2';
|
|
||||||
|
|
||||||
if (!conversationId) {
|
|
||||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
|
||||||
}
|
|
||||||
|
|
||||||
const pgClient = postgresClient.getChatwootConnection();
|
const pgClient = postgresClient.getChatwootConnection();
|
||||||
const result = await pgClient.query(query, [formattedSourceIds, conversationId]);
|
|
||||||
|
|
||||||
|
const params = conversationId
|
||||||
|
? [formattedSourceIds, conversationId]
|
||||||
|
: [formattedSourceIds];
|
||||||
|
|
||||||
|
const query = conversationId
|
||||||
|
? 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2'
|
||||||
|
: 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
||||||
|
|
||||||
|
const result = await pgClient.query(query, params);
|
||||||
for (const row of result.rows) {
|
for (const row of result.rows) {
|
||||||
existingSourceIdsSet.add(row.source_id);
|
existingSourceIdsSet.add(row.source_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return existingSourceIdsSet;
|
return existingSourceIdsSet;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
this.logger.error(`Error on getExistingSourceIds: ${error.toString()}`);
|
||||||
|
return new Set<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user