diff --git a/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts b/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts index f5c15fb11b..215ec9c1be 100644 --- a/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts +++ b/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts @@ -66,25 +66,20 @@ export class RequestEntityTranslation { } const entity = Entity.fromInputModel(entityInputModel); + let updatedEntities = (await this.entitiesDS.getByIds([entity.sharedId]).all()).filter( + e => e.language !== languageFrom + ); await atTemplateConfig?.properties.reduce(async (prev, property) => { await prev; const propertyValue = entity.getPropertyValue(property); if (propertyValue) { - const entities = this.entitiesDS.getByIds([entity.sharedId]); const pendingText = `${RequestEntityTranslation.AITranslationPendingText} ${propertyValue}`; - await entities.forEach(async fetchedEntity => { - if (languagesTo.includes(fetchedEntity.language as LanguageISO6391)) { - await this.entitiesDS.updateEntity( - fetchedEntity.setPropertyValue(property, pendingText) - ); - this.logger.info( - `[AT] - Pending translation saved on DB - ${property.name}: ${pendingText}` - ); - } - }); + updatedEntities = updatedEntities.map(fetchedEntity => + fetchedEntity.setPropertyValue(property, pendingText) + ); await this.taskManager.startTask({ key: [getTenant().name, entity.sharedId, property.id], @@ -103,5 +98,11 @@ export class RequestEntityTranslation { ); } }, Promise.resolve()); + + await Promise.all( + updatedEntities.map(async updatedEntity => { + await this.entitiesDS.updateEntity(updatedEntity); + }) + ); } }