Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Oct 17, 2024
2 parents 8c896fb + 0815011 commit 5e79ae0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { EntityInputModel } from 'api/entities.v2/types/EntityInputDataType';
import { Logger } from 'api/log.v2/contracts/Logger';
import { TaskManager } from 'api/services/tasksmanager/TaskManager';
import { EntitiesDataSource } from 'api/entities.v2/contracts/EntitiesDataSource';
import { LanguageISO6391 } from 'shared/types/commonTypes';
import { ATConfigDataSource } from './contracts/ATConfigDataSource';
import { Validator } from './infrastructure/Validator';

Expand Down Expand Up @@ -66,25 +65,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],
Expand All @@ -103,5 +97,12 @@ export class RequestEntityTranslation {
);
}
}, Promise.resolve());

await Promise.all(
updatedEntities.map(async updatedEntity => {
this.logger.info(`[AT] - Pending translation saved on DB for entity - ${entity._id}`);
await this.entitiesDS.updateEntity(updatedEntity);
})
);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.189.0-rc5",
"version": "1.189.0-rc6",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down

0 comments on commit 5e79ae0

Please sign in to comment.