mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
Merge pull request #1494 from KokeroO/develop
fix: melhora a formatação e tratamento de erros na função getExistingSourceIds
This commit is contained in:
commit
17fd407d8d
@ -177,24 +177,25 @@ class ChatwootImport {
|
||||
return existingSourceIdsSet;
|
||||
}
|
||||
|
||||
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); // Make sure the sourceId is always formatted as WAID:1234567890
|
||||
let query: string;
|
||||
if (conversationId) {
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2';
|
||||
} else {
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
||||
}
|
||||
|
||||
// Ensure all sourceIds are consistently prefixed with 'WAID:' as required by downstream systems and database queries.
|
||||
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`);
|
||||
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) {
|
||||
existingSourceIdsSet.add(row.source_id);
|
||||
}
|
||||
|
||||
return existingSourceIdsSet;
|
||||
} catch (error) {
|
||||
return null;
|
||||
this.logger.error(`Error on getExistingSourceIds: ${error.toString()}`);
|
||||
return new Set<string>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,7 +337,6 @@ class ChatwootImport {
|
||||
|
||||
this.deleteHistoryMessages(instance);
|
||||
this.deleteRepositoryMessagesCache(instance);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user